This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #481 from Agroarca/i480
desenvolvimento notificações admin
- Loading branch information
Showing
32 changed files
with
1,060 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/Enums/Administracao/Notificacoes/TipoNotificacaoEnum.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Enums\Administracao\Notificacoes; | ||
|
||
use App\Enums\EnumToArray; | ||
|
||
enum TipoNotificacaoEnum: int | ||
{ | ||
use EnumToArray; | ||
|
||
case Placeholder = 0; | ||
case ProdutoEnviadoAprovacao = 1; | ||
|
||
public static function arrayNomes(): array | ||
{ | ||
return [ | ||
self::Placeholder->value => 'Placeholder', | ||
self::ProdutoEnviadoAprovacao->value => 'Produto Enviado para Aprovação', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Events\Equipamento\Cadastro; | ||
|
||
use App\Models\Equipamentos\Cadastro\Equipamento; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class EquipamentoSaved | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public function __construct( | ||
public Equipamento $equipamento | ||
) { | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/Http/Controllers/Admin/Administracao/Usuarios/UsuarioController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\Administracao\Usuarios; | ||
|
||
use App\Enums\Usuario\TipoPessoa; | ||
use App\Enums\Usuario\TipoUsuario; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Usuario; | ||
use App\Services\Notificacoes\NotificacaoAdminService; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
|
||
class UsuarioController extends Controller | ||
{ | ||
public function __construct( | ||
private NotificacaoAdminService $notAdmService | ||
) { | ||
} | ||
|
||
public function inicio(): mixed | ||
{ | ||
$usuarios = Usuario::paginate(); | ||
$usuarios->setCollection($usuarios->getCollection()->makeVisible(['cpf', 'cnpj'])); | ||
|
||
$tipoPessoaEnum = TipoPessoa::arrayNomes(); | ||
return Inertia::render('Admin/Administracao/Usuarios/Inicio', compact('usuarios', 'tipoPessoaEnum')); | ||
} | ||
|
||
public function visualizar(Usuario $usuario): mixed | ||
{ | ||
$usuario->makeVisible(['cpf', 'cnpj', 'celular']); | ||
$usuario->load('grupos'); | ||
|
||
$tipoPessoaEnum = TipoPessoa::arrayNomes(); | ||
$tipoUsuarioEnum = TipoUsuario::toArray(); | ||
|
||
$preferenciasNotificacao = []; | ||
if ($usuario->tipo_usuario == TipoUsuario::Admin) { | ||
$preferenciasNotificacao = $this->notAdmService->getPreferenciasNotificacaoUsuario($usuario); | ||
} | ||
|
||
return Inertia::render('Admin/Administracao/Usuarios/Visualizar', [ | ||
'usuario' => $usuario, | ||
'tipoPessoaEnum' => $tipoPessoaEnum, | ||
'tipoUsuarioEnum' => $tipoUsuarioEnum, | ||
'preferenciasNotificacao' => (array) $preferenciasNotificacao, | ||
]); | ||
} | ||
|
||
public function salvarPreferencias(Request $request, Usuario $usuario) | ||
{ | ||
$this->notAdmService->salvarPreferenciasNotificacaoUsuario($usuario, $request->all()); | ||
return redirect()->route('admin.administracao.usuarios.visualizar', $usuario->id); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/Listeners/Equipamentos/Cadastro/EquipamentoSavedListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Equipamentos\Cadastro; | ||
|
||
use App\Enums\Equipamentos\Cadastro\StatusEquipamento; | ||
use App\Events\Equipamento\Cadastro\EquipamentoSaved; | ||
use App\Models\Equipamentos\Cadastro\Equipamento; | ||
use App\Notifications\Equipamentos\Cadastro\EquipamentoAprovadoNotification; | ||
use App\Notifications\Equipamentos\Cadastro\EquipamentoReprovadoNotification; | ||
use App\Services\Notificacoes\NotificacaoAdminService; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
class EquipamentoSavedListener | ||
{ | ||
/** | ||
* Handle the event. | ||
*/ | ||
public function handle(EquipamentoSaved $event): void | ||
{ | ||
$this->handleStatus($event->equipamento); | ||
} | ||
|
||
private function handleStatus(Equipamento $equipamento): void | ||
{ | ||
if (!$equipamento->isDirty('status')) { | ||
return; | ||
} | ||
|
||
if ($equipamento->status == StatusEquipamento::Aprovado) { | ||
Notification::send($equipamento->usuario, new EquipamentoAprovadoNotification($equipamento)); | ||
} | ||
|
||
if ($equipamento->status == StatusEquipamento::Reprovado) { | ||
Notification::send($equipamento->usuario, new EquipamentoReprovadoNotification($equipamento)); | ||
} | ||
|
||
if ($equipamento->status == StatusEquipamento::Criado) { | ||
app(NotificacaoAdminService::class)->notificarEquipamentoEnviadoAprovacao(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Mail\Equipamentos\Cadastro; | ||
|
||
use App\Models\Equipamentos\Cadastro\Equipamento; | ||
use App\Models\Usuario; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Address; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class EquipamentoAprovado extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
private Usuario $usuario, | ||
private Equipamento $equipamento | ||
) { | ||
} | ||
|
||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
from: new Address( | ||
address: config('mail.from.address'), | ||
name: config('mail.from.name') | ||
), | ||
to: [ | ||
new Address( | ||
address: $this->usuario->email, | ||
name: $this->usuario->nome | ||
) | ||
], | ||
subject: 'Equipamento aprovado' | ||
); | ||
} | ||
|
||
public function content(): Content | ||
{ | ||
return new Content( | ||
view: 'equipamentos.cadastro.equipamento-aprovado', | ||
text: 'equipamentos.cadastro.equipamento-aprovado-text', | ||
with: [ | ||
'nome' => $this->usuario->nome, | ||
'nomeEquipamento' => $this->equipamento->titulo, | ||
'url' => url()->route('site.equipamento', $this->equipamento->id), | ||
] | ||
); | ||
} | ||
|
||
public function attachments(): array | ||
{ | ||
return []; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/Mail/Equipamentos/Cadastro/EquipamentoEnviadoAprovacao.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Mail\Equipamentos\Cadastro; | ||
|
||
use App\Models\Usuario; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Address; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class EquipamentoEnviadoAprovacao extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
private Usuario $usuario | ||
) { | ||
} | ||
|
||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
from: new Address( | ||
address: config('mail.from.address'), | ||
name: config('mail.from.name') | ||
), | ||
to: [ | ||
new Address( | ||
address: $this->usuario->email, | ||
name: $this->usuario->nome | ||
) | ||
], | ||
subject: 'Equipamento enviado para aprovação' | ||
); | ||
} | ||
|
||
public function content(): Content | ||
{ | ||
return new Content( | ||
view: 'equipamentos.cadastro.equipamento-enviado-aprovacao', | ||
text: 'equipamentos.cadastro.equipamento-enviado-aprovacao-text', | ||
with: [ | ||
'nome' => $this->usuario->nome, | ||
'url' => url()->route('admin.equipamentos'), | ||
] | ||
); | ||
} | ||
|
||
public function attachments(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Mail\Equipamentos\Cadastro; | ||
|
||
use App\Models\Equipamentos\Cadastro\Equipamento; | ||
use App\Models\Usuario; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Address; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class EquipamentoReprovado extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
private Usuario $usuario, | ||
public Equipamento $equipamento | ||
) { | ||
} | ||
|
||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
from: new Address( | ||
address: config('mail.from.address'), | ||
name: config('mail.from.name') | ||
), | ||
to: [ | ||
new Address( | ||
address: $this->usuario->email, | ||
name: $this->usuario->nome | ||
) | ||
], | ||
subject: 'Equipamento em revisão' | ||
); | ||
} | ||
|
||
public function content(): Content | ||
{ | ||
return new Content( | ||
view: 'equipamentos.cadastro.equipamento-reprovado', | ||
text: 'equipamentos.cadastro.equipamento-reprovado-text', | ||
with: [ | ||
'nome' => $this->usuario->nome, | ||
'nomeEquipamento' => $this->equipamento->titulo, | ||
'url' => url()->route('site.equipamento.editar', $this->equipamento->id), | ||
] | ||
); | ||
} | ||
|
||
public function attachments(): array | ||
{ | ||
return []; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/Models/Administracao/Notificacoes/NotificacaoAdmin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Models\Administracao\Notificacoes; | ||
|
||
use App\Enums\Administracao\Notificacoes\TipoNotificacaoEnum; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class NotificacaoAdmin extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'admininistracao_notificacao_admins'; | ||
|
||
protected $fillable = [ | ||
'usuario_id', | ||
'tipo', | ||
]; | ||
|
||
protected $casts = [ | ||
'tipo' => TipoNotificacaoEnum::class, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.