Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/tag_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tag Develop Commits

on:
pull_request:
branches: [ develop ]
types: [ closed ]
push:
branches: [ develop ]

jobs:
tag-dev:
if: github.event.pull_request.merged == true || github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
permissions:
contents: write # necessário para criar tags
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # necessário para acessar tags existentes (se precisar comparar)

- name: Read base version
run: |
BASE_VERSION=$(cat version.txt)
COMMIT_SHORT=$(git rev-parse --short HEAD)
DEV_TAG="${BASE_VERSION}-dev.${COMMIT_SHORT}"
echo "Criando tag: $DEV_TAG"
git tag "$DEV_TAG"
git push origin "$DEV_TAG"
9 changes: 0 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ Todas as mudanças relevantes serão documentadas nesse arquivo.

O formato é baseado no [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0), e esse projeto adere ao [Semantic Versionning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2025-11-18
### Modificado
- Reorganizado mensageria e documentado
- Cobertura para os testes

### Adicionado
- Logs para o containers
- Auditoria para envio dos emails

## [1.1.0] - 2024-10-28
### Modificado
- Requisição para endpoint
Expand Down
7 changes: 2 additions & 5 deletions app/Console/Commands/ImportRegistrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Events\ImportRegistrationEvent;
use Illuminate\Console\Command;
use App\Services\RabbitMQService;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -56,11 +57,7 @@ protected function processMessage(AMQPMessage $msg)
return;
}

foreach ($registrations as $registration) {
Mail::to($registration['agent_email'])->send(new ImporteRegistrationMail($registration));
Log::info('Email enviado para ' . $registration['agent_email']);

}
event(new ImportRegistrationEvent($registrations));
// Confirmar a mensagem após processamento
$msg->ack();
} catch (\Exception $e) {
Expand Down
35 changes: 35 additions & 0 deletions app/Events/ImportRegistrationEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ImportRegistrationEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $registrations;

/**
* Create a new event instance.
*/
public function __construct($registrations)
{
$this->registrations = $registrations;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
73 changes: 73 additions & 0 deletions app/Listeners/ImportRegistrationListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Listeners;

use App\Models\EmailDispatch;
use App\Mail\ImporteRegistrationMail;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use App\Events\ImportRegistrationEvent;

class ImportRegistrationListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(ImportRegistrationEvent $event): void
{
foreach ($event->registrations as $registration) {
if (!$this->isValidRegistration($registration)) {
Log::error('Chaves obrigatórias ausentes na inscrição: ' . json_encode($registration));
continue;
}

Log::info('Enviando e-mail para: ' . $registration['agent_email']);

// Cria o Mailable
$mailable = new ImporteRegistrationMail($registration);

// Audita em EmailDispatch com o conteúdo renderizado
EmailDispatch::create([
'to' => $registration['agent_name'],
'subject' => $mailable->envelope()->subject,
'content' => $mailable->render(),
'mailable_type' => ImporteRegistrationMail::class,
'meta' => [
'registration' => $registration['registration'],
'opp_id' => $registration['opp_id'],
'opp_name' => $registration['opp_name'],
'number' => $registration['number'],
'agent_name' => $registration['agent_name'],
'agent_email' => $registration['agent_email'],
],
'dispatched_at' => now(),
]);

Mail::to($registration['agent_email'])->send($mailable);
Log::info('Email enviado e auditado para: ' . $registration['agent_email']);
}
}

/**
* Valida se a inscrição possui as chaves obrigatórias
*/
protected function isValidRegistration(array $registration): bool
{
return isset(
$registration['registration'],
$registration['opp_id'],
$registration['opp_name'],
$registration['number'],
$registration['agent_name'],
$registration['agent_email']
);
}
}
5 changes: 5 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Providers;

use App\Events\OpinionManagementEvent;
use App\Events\ImportRegistrationEvent;
use App\Listeners\AuditMessageListener;
use App\Listeners\OpinionManagementListener;
use App\Listeners\ImportRegistrationListener;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
Expand All @@ -13,6 +15,9 @@ class EventServiceProvider extends ServiceProvider
OpinionManagementEvent::class => [
OpinionManagementListener::class,
],
ImportRegistrationEvent::class => [
ImportRegistrationListener::class,
],
];
/**
* Register services.
Expand Down
Loading
Loading