Skip to content

Commit

Permalink
wip api get #3307
Browse files Browse the repository at this point in the history
wip api get #3307
  • Loading branch information
numew committed Nov 28, 2024
1 parent db4821d commit 4a80e75
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/Controller/Api/SignalementController.php
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);
}
}
26 changes: 26 additions & 0 deletions src/Dto/Api/Response/AffectationResponse.php
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();
}
}
21 changes: 21 additions & 0 deletions src/Dto/Api/Response/FileResponse.php
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 ?
}
}
10 changes: 10 additions & 0 deletions src/Dto/Api/Response/GeolocalisationResponse.php
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)
{
}
}
31 changes: 31 additions & 0 deletions src/Dto/Api/Response/InterventionResponse.php
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 ?
}
}
21 changes: 21 additions & 0 deletions src/Dto/Api/Response/PartnerResponse.php
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 ?
}
}
Loading

0 comments on commit 4a80e75

Please sign in to comment.