-
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.
wip api get #3307
- Loading branch information
Showing
9 changed files
with
481 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Controller\Api; | ||
|
||
use App\Dto\Api\Response\SignalementResponse; | ||
use App\Repository\SignalementRepository; | ||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\DependencyInjection\Attribute\When; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[When('dev')] | ||
#[When('test')] | ||
#[Route('/api')] | ||
class SignalementController extends AbstractController | ||
{ | ||
#[Route('/signalements', name: 'api_signalements', methods: ['GET'])] | ||
#[OA\Get( | ||
path: '/api/signalements', | ||
description: '', | ||
summary: 'Retourne les {{ limit }} derniers signalements', | ||
security: [['bearerAuth' => []]], | ||
tags: ['Signalements'], | ||
)] | ||
#[OA\Parameter( | ||
name: 'limit', | ||
description: 'Nombre de signalements à retourner (défaut : 20, max : 500)', | ||
in: 'query', | ||
required: false, | ||
schema: new OA\Schema(type: 'limit', example: '10') | ||
)] | ||
#[OA\Response( | ||
response: Response::HTTP_OK, | ||
description: 'Une liste de signalements', | ||
content: new OA\JsonContent( | ||
type: 'array', | ||
items: new OA\Items(ref: new Model(type: SignalementResponse::class)) | ||
) | ||
)] | ||
public function getSignalementList( | ||
SignalementRepository $signalementRepository, | ||
#[MapQueryParameter] int $limit = 20, | ||
): JsonResponse { | ||
// TODO : Gérer la limite max | ||
// TODO : Limiter les signalements retournés en fonction de l'user connecté | ||
$signalements = $signalementRepository->findBy([], ['createdAt' => 'DESC'], $limit); | ||
$resources = []; | ||
foreach ($signalements as $signalement) { | ||
$resources[] = new SignalementResponse($signalement); | ||
} | ||
|
||
return new JsonResponse($resources, Response::HTTP_OK); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace App\Dto\Api\Response; | ||
|
||
use App\Entity\Affectation; | ||
|
||
class AffectationResponse | ||
{ | ||
public string $dateCreation; | ||
public ?string $dateReponse; | ||
public int $statut; | ||
public PartnerResponse $partnerResponse; | ||
public ?string $motifCloture; | ||
public ?string $motifRefus; | ||
|
||
public function __construct( | ||
Affectation $affectation, | ||
) { | ||
$this->dateCreation = $affectation->getCreatedAt()->format(\DATE_ATOM); | ||
$this->dateReponse = $affectation->getAnsweredAt()?->format(\DATE_ATOM); | ||
$this->statut = $affectation->getStatut(); // envoyer un libellé ? | ||
$this->partnerResponse = new PartnerResponse($affectation->getPartner()); | ||
$this->motifCloture = $affectation->getMotifCloture()?->label(); | ||
$this->motifRefus = $affectation->getMotifRefus()?->label(); | ||
} | ||
} |
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\Dto\Api\Response; | ||
|
||
use App\Entity\File; | ||
|
||
class FileResponse | ||
{ | ||
public string $uuid; | ||
public string $titre; | ||
public string $documentType; | ||
|
||
public function __construct( | ||
File $file, | ||
) { | ||
$this->uuid = $file->getUuid(); // il faudrait retourner l'url publique complete du fichier à partir de son uuid (route show_file mais il faut des dependances) | ||
$this->titre = $file->getTitle(); | ||
$this->documentType = $file->getDocumentType()->value; | ||
// besoin d'exposer plus d'élements ? | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace App\Dto\Api\Response; | ||
|
||
class GeolocalisationResponse | ||
{ | ||
public function __construct(public ?float $latitude, public ?float $longitude) | ||
{ | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace App\Dto\Api\Response; | ||
|
||
use App\Entity\Intervention; | ||
|
||
class InterventionResponse | ||
{ | ||
public string $dateIntervention; | ||
public ?string $type; | ||
public ?string $statut; | ||
public ?PartnerResponse $partner; | ||
public ?string $details; | ||
public array $conclusions = []; | ||
public ?bool $occupantPresent; | ||
public ?bool $proprietairePresent; | ||
|
||
public function __construct( | ||
Intervention $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->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 ? | ||
} | ||
} |
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\Dto\Api\Response; | ||
|
||
use App\Entity\Partner; | ||
|
||
class PartnerResponse | ||
{ | ||
public string $nom; | ||
public ?string $type; | ||
public array $competences = []; | ||
|
||
public function __construct( | ||
Partner $partner, | ||
) { | ||
$this->nom = $partner->getNom(); | ||
$this->type = $partner->getType()?->label(); | ||
$this->competences = $partner->getCompetence() ?? []; | ||
// besoin d'exposer plus d'élements ? | ||
} | ||
} |
Oops, something went wrong.