Skip to content

Commit

Permalink
changes based on comments #3307
Browse files Browse the repository at this point in the history
  • Loading branch information
numew committed Dec 5, 2024
1 parent f0150d1 commit b90d14a
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 299 deletions.
57 changes: 20 additions & 37 deletions src/Controller/Api/SignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Controller\Api;

use App\Dto\Api\Response\SignalementResponse;
use App\Factory\Api\SignalementResponseFactory;
use App\Repository\SignalementRepository;
use App\Service\Signalement\SignalementDesordresProcessor;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -13,7 +13,6 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

#[When('dev')]
#[When('test')]
Expand All @@ -35,6 +34,13 @@ class SignalementController extends AbstractController
required: false,
schema: new OA\Schema(type: 'limit', example: '10')
)]
#[OA\Parameter(
name: 'page',
description: 'Numéro de la page de signalement à retourner (défaut : 1)',
in: 'query',
required: false,
schema: new OA\Schema(type: 'page', example: '2')
)]
#[OA\Response(
response: Response::HTTP_OK,
description: 'Une liste de signalements',
Expand All @@ -45,17 +51,23 @@ class SignalementController extends AbstractController
)]
public function getSignalementList(
SignalementRepository $signalementRepository,
SignalementDesordresProcessor $signalementDesordresProcessor,
UrlGeneratorInterface $urlGenerator,
SignalementResponseFactory $signalementResponseFactory,
#[MapQueryParameter] int $limit = 20,
#[MapQueryParameter] int $page = 1,
): JsonResponse {
if ($limit < 1) {
$limit = 1;
}
if ($limit > 100) {
$limit = 100;
}
$signalements = $signalementRepository->findForAPI(user: $this->getUser(), limit: $limit);
if ($page < 1) {
$page = 1;
}
$signalements = $signalementRepository->findForAPI(user: $this->getUser(), limit: $limit, page: $page);
$resources = [];
foreach ($signalements as $signalement) {
$resources[] = new SignalementResponse($signalement, $signalementDesordresProcessor, $urlGenerator); // sinon comment acceder à ses services pour generer les responses ?
$resources[] = $signalementResponseFactory->createFromSignalement($signalement);
}

return new JsonResponse($resources, Response::HTTP_OK);
Expand All @@ -76,43 +88,14 @@ public function getSignalementList(
)]
public function getSignalementByUuid(
SignalementRepository $signalementRepository,
SignalementDesordresProcessor $signalementDesordresProcessor,
UrlGeneratorInterface $urlGenerator,
SignalementResponseFactory $signalementResponseFactory,
string $uuid,
): JsonResponse {
$signalements = $signalementRepository->findForAPI(user : $this->getUser(), uuid : $uuid);
if (!count($signalements)) {
return new JsonResponse(['message' => 'Signalement introuvable'], Response::HTTP_NOT_FOUND);
}
$resource = new SignalementResponse($signalements[0], $signalementDesordresProcessor, $urlGenerator);

return new JsonResponse($resource, Response::HTTP_OK);
}

#[Route('/signalements/reference/{reference}', name: 'api_signalement_reference', methods: ['GET'])]
#[OA\Get(
path: '/api/signalements/reference/{reference}',
description: 'Retourne un signalement récupéré par sa reference',
summary: 'Signalement par référence',
security: [['bearerAuth' => []]],
tags: ['Signalements']
)]
#[OA\Response(
response: Response::HTTP_OK,
description: 'Un signalement',
content: new OA\JsonContent(ref: '#/components/schemas/SignalementResponse')
)]
public function getSignalementByReference(
SignalementRepository $signalementRepository,
SignalementDesordresProcessor $signalementDesordresProcessor,
UrlGeneratorInterface $urlGenerator,
string $reference,
): JsonResponse {
$signalements = $signalementRepository->findForAPI(user : $this->getUser(), reference : $reference);
if (!count($signalements)) {
return new JsonResponse(['message' => 'Signalement introuvable'], Response::HTTP_NOT_FOUND);
}
$resource = new SignalementResponse($signalements[0], $signalementDesordresProcessor, $urlGenerator);
$resource = $signalementResponseFactory->createFromSignalement($signalements[0]);

return new JsonResponse($resource, Response::HTTP_OK);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace App\Dto\Api\Response;
namespace App\Dto\Api\Model;

use App\Entity\Criticite;
use App\Entity\DesordrePrecision;

class DesordreResponse
class Desordre
{
public string $categorie;
public ?string $zone;
Expand All @@ -18,12 +18,10 @@ public function __construct(
) {
$this->categorie = $categorie;
$this->zone = $zone;
foreach ($data as $label => $unused) {
foreach ($data as $label => $detail) {
$details = $label;
if ($unused instanceof DesordrePrecision && $unused->getLabel()) {
$details .= ' : '.$unused->getLabel();
} elseif ($unused instanceof Criticite && $unused->getLabel()) {
$details .= ' : '.$unused->getLabel();
if ($detail->getLabel() && ($detail instanceof DesordrePrecision || $detail instanceof Criticite)) {
$details .= ' : '.$detail->getLabel();
}
$this->details[] = $details;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Dto/Api/Model/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Dto\Api\Model;

class File
{
public string $titre;
public string $documentType;
public string $url;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Dto\Api\Response;
namespace App\Dto\Api\Model;

class GeolocalisationResponse
class Geolocalisation
{
public function __construct(public ?float $latitude, public ?float $longitude)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
<?php

namespace App\Dto\Api\Response;
namespace App\Dto\Api\Model;

use App\Entity\Intervention;
use App\Entity\Intervention as InterventionEntity;

class InterventionResponse
class Intervention
{
public string $dateIntervention;
public ?string $type;
public ?string $statut;
public ?PartnerResponse $partner;
public ?Partner $partner;
public ?string $details;
public array $conclusions = [];
public ?bool $occupantPresent;
public ?bool $proprietairePresent;

public function __construct(
Intervention $intervention,
InterventionEntity $intervention,
) {
$this->dateIntervention = $intervention->getScheduledAt()->format(\DATE_ATOM);
$this->type = $intervention->getType()?->label();
$this->statut = $intervention->getStatus();
$this->partner = $intervention->getPartner() ? new PartnerResponse($intervention->getPartner()) : null;
$this->partner = $intervention->getPartner() ? new Partner($intervention->getPartner()) : null;
$this->details = $intervention->getDetails(); // traitement de suppression du html
$this->conclusions = $intervention->getConcludeProcedure() ?? [];
$this->occupantPresent = $intervention->isOccupantPresent();
$this->proprietairePresent = $intervention->isProprietairePresent();
// besoin d'exposer plus d'élements ?
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

namespace App\Dto\Api\Response;
namespace App\Dto\Api\Model;

use App\Entity\Partner;
use App\Entity\Partner as PartnerEntity;

class PartnerResponse
class Partner
{
public string $nom;
public ?string $type;
public array $competences = [];

public function __construct(
Partner $partner,
PartnerEntity $partner,
) {
$this->nom = $partner->getNom();
$this->type = $partner->getType()?->label();
$this->competences = $partner->getCompetence() ?? [];
// besoin d'exposer plus d'élements ?
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace App\Dto\Api\Response;
namespace App\Dto\Api\Model;

use App\Entity\Suivi;
use App\Entity\Suivi as SuiviEntity;

class SuiviResponse
class Suivi
{
public int $id;
public string $dateCreation;
Expand All @@ -13,13 +13,13 @@ class SuiviResponse
public int $type;

public function __construct(
Suivi $suivi,
SuiviEntity $suivi,
) {
$this->id = $suivi->getId();
$this->dateCreation = $suivi->getCreatedAt()->format(\DATE_ATOM);
$this->description = $suivi->getDescription(); // traitement de suppression du html ? comment gérer les bouton/doc qui sont présent en dur dans le contenu ?
$this->public = $suivi->getIsPublic();
$this->type = $suivi->getType(); // envoyer un libellé ?
// exposer "createdBy" sous quelle forme ?
// TODO : exposer "createdBy" attendre merge multi ter. et essayer de faire propre
}
}
26 changes: 0 additions & 26 deletions src/Dto/Api/Response/AffectationResponse.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/Dto/Api/Response/FileResponse.php

This file was deleted.

Loading

0 comments on commit b90d14a

Please sign in to comment.