Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement backend on registration page #512

Merged
merged 1 commit into from
Jan 15, 2025
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
4 changes: 4 additions & 0 deletions cypress/e2e/admin/registration/registration.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ describe('Página de Minhas Inscrições', () => {
cy.get('h1').contains('Minhas Inscrições');
cy.get('input[placeholder="Busque por palavras-chave"]').should('exist');
cy.get('button').contains('Acompanhar').should('exist');
cy.get(':nth-child(3) > .resource-card-header > .resource-title').contains("Inscrição para o Concurso de Cordelistas - Festival de Literatura Nordestina").should("be.visible");
cy.get(':nth-child(3) > .resource-card-body > .resource-details > :nth-child(1)').contains("Fase de recurso").should("be.visible");
cy.get(':nth-child(3) > .resource-card-body > .resource-details > :nth-child(2)').contains("Fase de recurso do Concurso de Cordelistas").should("be.visible");
cy.get(':nth-child(3) > .resource-card-body > .resource-details > :nth-child(3)').contains("23/07/2024 até 26/07/2024").should("be.visible");
});
});
12 changes: 11 additions & 1 deletion src/Controller/Web/Admin/RegistrationAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@

namespace App\Controller\Web\Admin;

use App\Service\Interface\InscriptionOpportunityServiceInterface;
use Symfony\Component\HttpFoundation\Response;

class RegistrationAdminController extends AbstractAdminController
{
public function __construct(
private readonly InscriptionOpportunityServiceInterface $service,
) {
}

public function list(): Response
{
return $this->render('registration/list.html.twig');
$inscriptions = $this->service->findUserInscriptionsWithDetails();

return $this->render('registration/list.html.twig', [
'inscriptions' => $inscriptions,
]);
}
}
20 changes: 20 additions & 0 deletions src/Repository/InscriptionOpportunityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use App\Entity\InscriptionOpportunity;
use App\Entity\InscriptionPhase;
use App\Entity\Phase;
use App\Repository\Interface\InscriptionOpportunityRepositoryInterface;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Uid\Uuid;

class InscriptionOpportunityRepository extends AbstractRepository implements InscriptionOpportunityRepositoryInterface
{
Expand Down Expand Up @@ -78,4 +80,22 @@ public function findOneInscriptionOpportunity(string $inscriptionId, string $opp
->getQuery()
->getOneOrNullResult();
}

public function findUserInscriptionsWithDetails(Uuid $agentId): iterable
{
$qb = $this->createQueryBuilder('i');

$subQuery = $this->getEntityManager()->createQueryBuilder()
->select('MAX(p2.startDate)')
->from(Phase::class, 'p2')
->where('p2.opportunity = o.id');

return $qb->select('i', 'o', 'p')
->join('i.opportunity', 'o')
->join(Phase::class, 'p', 'WITH', 'p.opportunity = o.id AND p.startDate = ('.$subQuery->getDQL().')')
->where('i.agent = :agentId')
->setParameter('agentId', $agentId)
->getQuery()
->getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Entity\InscriptionOpportunity;
use App\Entity\InscriptionPhase;
use Symfony\Component\Uid\Uuid;

interface InscriptionOpportunityRepositoryInterface
{
Expand All @@ -14,4 +15,6 @@ public function create(InscriptionOpportunity $inscriptionOpportunity, ?Inscript
public function findOneInscriptionOpportunity(string $inscriptionId, string $opportunityId, array $agents);

public function findInscriptionsByOpportunity(string $opportunityId, array $agents, int $limit);

public function findUserInscriptionsWithDetails(Uuid $agentId): iterable;
}
25 changes: 25 additions & 0 deletions src/Service/InscriptionOpportunityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\DTO\InscriptionOpportunityDto;
use App\Entity\InscriptionOpportunity;
use App\Entity\InscriptionPhase;
use App\Entity\Phase;
use App\Enum\InscriptionPhaseStatusEnum;
use App\Exception\InscriptionOpportunity\AlreadyInscriptionOpportunityException;
use App\Exception\InscriptionOpportunity\InscriptionOpportunityResourceNotFoundException;
Expand Down Expand Up @@ -90,6 +91,30 @@ public function list(Uuid $opportunity, int $limit = 50): array
);
}

public function findUserInscriptionsWithDetails(): array
TalysonSoares marked this conversation as resolved.
Show resolved Hide resolved
{
$userParams = $this->getUserParams()['agent'][0];
$agent = $userParams->getId();

$inscriptionsWithDetails = $this->repository->findUserInscriptionsWithDetails($agent);

$phaseData = [];

foreach ($inscriptionsWithDetails as $inscription) {
if ($inscription instanceof Phase) {
$phaseData[] = [
'opportunity' => $inscription->getOpportunity()->getName(),
'phase' => $inscription->getName(),
'phaseDescription' => $inscription->getDescription(),
'startDate' => $inscription->getStartDate(),
'endDate' => $inscription->getEndDate(),
];
}
}

return $phaseData;
}

public function remove(Uuid $opportunity, Uuid $id): void
{
$inscriptionOpportunity = $this->repository->findOneBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function get(Uuid $opportunity, Uuid $id);

public function list(Uuid $opportunity, int $limit = 50): array;

public function findUserInscriptionsWithDetails(): array;

public function remove(Uuid $opportunity, Uuid $id): void;

public function update(Uuid $opportunity, Uuid $identifier, array $inscriptionOpportunity): InscriptionOpportunity;
Expand Down
13 changes: 6 additions & 7 deletions templates/_admin/registration/_partials/tabs/sent.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
<hr>
</div>

{% for inscription in inscriptions %}
<div class="resource-card mt-4">
<div class="resource-card-header">
<div class="resource-icon"></div>
<h4 class="resource-title">{{ 'view.registration.title-card' | trans }}</h4>
<h4 class="resource-title">{{ inscription.opportunity }}</h4>
</div>
<div class="resource-card-body">
<div class="resource-details">
<p><strong>{{ 'phase' | trans }}</strong> {{ 'view.registration.merit' | trans }}</p>
<p><strong>{{ 'type' | trans }}</strong> {{ 'view.registration.data' | trans }}</p>
<p><strong>{{ 'analysis' | trans }}</strong> {{ 'view.registration.hour' | trans }}</p>
<p><strong>{{ 'phase' | trans }}</strong> {{ inscription.phase }}</p>
<p><strong>{{ 'type' | trans }}</strong> {{ inscription.phaseDescription }}</p>
<p><strong>{{ 'analysis' | trans }}</strong> {{ inscription.startDate | date('d/m/Y') }} {{ 'to'|trans }} {{ inscription.endDate | date('d/m/Y') }}</p>
</div>
</div>
<div class="text-end mt-3">
Expand All @@ -38,6 +39,4 @@
</button>
</div>
</div>



{% endfor %}
47 changes: 47 additions & 0 deletions tests/Functional/Services/InscriptionOpportunityServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Service\Interface\InscriptionOpportunityServiceInterface;
use App\Tests\AbstractWebTestCase;
use App\Tests\Fixtures\InscriptionOpportunityTestFixtures;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Uid\Uuid;

Expand Down Expand Up @@ -56,4 +57,50 @@ public function testCreateInscriptionInOpportunityAndPhase(): void

self::assertNotNull($inscriptionPhase);
}

public function testFindUserInscriptions(): void
{
$result = $this->service->findUserInscriptionsWithDetails();

$expectedResult = [
[
'opportunity' => 'Chamada para Oficinas de Artesanato - Feira de Cultura Popular',
'phase' => 'Fase de documentos',
'phaseDescription' => 'Fase de documentos para as oficinas de Artesanato na Feira de Cultura Popular',
'startDate' => new DateTime('2024-08-15 00:00:00.0'),
'endDate' => new DateTime('2024-08-20 00:00:00.0'),
],
[
'opportunity' => 'Credenciamento de Quadrilhas Juninas - São João do Nordeste',
'phase' => 'Fase de submissão',
'phaseDescription' => 'Fase de submissão para o credenciamento de Quadrilhas Juninas - São João do Nordeste',
'startDate' => new DateTime('2024-07-15 00:00:00.0'),
'endDate' => new DateTime('2024-07-18 00:00:00.0'),
],
[
'opportunity' => 'Inscrição para o Festival de Danças Folclóricas - Encontro Nordestino',
'phase' => 'Fase de documentação',
'phaseDescription' => 'Fase de documentação de inscrição para o Festival de Danças Folclóricas - Encontro Nordestino',
'startDate' => new DateTime('2024-08-22 00:00:00.0'),
'endDate' => new DateTime('2024-08-24 00:00:00.0 '),
],
[
'opportunity' => 'Edital de Patrocínio para Grupos de Maracatu - Carnaval Cultural',
'phase' => 'Fase de submissão',
'phaseDescription' => null,
'startDate' => new DateTime('2024-08-28 00:00:00.0'),
'endDate' => new DateTime('2024-09-01 00:00:00.0'),
],
];

foreach ($expectedResult as $index => $expectedItem) {
$actualItem = $result[$index];

self::assertEquals($expectedItem['opportunity'], $actualItem['opportunity'], 'O nome da oportunidade não corresponde.');
self::assertEquals($expectedItem['phase'], $actualItem['phase'], 'O nome da fase não corresponde.');
self::assertEquals($expectedItem['phaseDescription'], $actualItem['phaseDescription'], 'A descrição da fase não corresponde.');
self::assertEquals($expectedItem['startDate'], $actualItem['startDate'], 'A data de início não corresponde.');
self::assertEquals($expectedItem['endDate'], $actualItem['endDate'], 'A data de término não corresponde.');
}
}
}
Loading