From ad11f7c0dd5b3f139e6ac9e88ce638a21ebc9927 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 30 Jul 2025 16:56:33 +0200 Subject: [PATCH] pilotage reference & token session timeout --- angular/openapi.yaml | 2 - angular/src/app/_helpers/error.interceptor.ts | 2 +- .../trip/trip-form/trip-form.component.html | 4 ++ angular/src/app/core/api/v1/model/trip.ts | 2 +- .../src/app/core/api/v1/model/tripJsonld.ts | 2 +- .../packages/lexik_jwt_authentication.yaml | 2 +- httpdocs/migrations/Version20250730143720.php | 31 +++++++++++++++ httpdocs/src/ApiResource/TripApi.php | 2 +- .../src/Command/Patch/Patch001Command.php | 39 +++++++++++++++++++ httpdocs/src/Entity/Trip.php | 21 +++++----- httpdocs/src/Mapper/TripApiToEntityMapper.php | 14 +++++++ httpdocs/src/Mapper/TripEntityToApiMapper.php | 2 +- 12 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 httpdocs/migrations/Version20250730143720.php create mode 100644 httpdocs/src/Command/Patch/Patch001Command.php diff --git a/angular/openapi.yaml b/angular/openapi.yaml index 66f2115..ce7dc3b 100644 --- a/angular/openapi.yaml +++ b/angular/openapi.yaml @@ -4571,7 +4571,6 @@ components: format: iri-reference example: 'https://example.com/' pilotageReference: - readOnly: true type: - string - 'null' @@ -4664,7 +4663,6 @@ components: format: iri-reference example: 'https://example.com/' pilotageReference: - readOnly: true type: - string - 'null' diff --git a/angular/src/app/_helpers/error.interceptor.ts b/angular/src/app/_helpers/error.interceptor.ts index d914796..eb44170 100644 --- a/angular/src/app/_helpers/error.interceptor.ts +++ b/angular/src/app/_helpers/error.interceptor.ts @@ -28,7 +28,7 @@ export class ErrorInterceptor implements HttpInterceptor { this.accountService.logout(); } console.log(err); - this.alertService.error(err.message + ' - ' + err.error); + this.alertService.error(err.error.detail); const error = err.error?.message || err.statusText; return throwError(() => error); diff --git a/angular/src/app/_views/trip/trip-form/trip-form.component.html b/angular/src/app/_views/trip/trip-form/trip-form.component.html index 092074b..8ac7fbb 100644 --- a/angular/src/app/_views/trip/trip-form/trip-form.component.html +++ b/angular/src/app/_views/trip/trip-form/trip-form.component.html @@ -11,6 +11,10 @@
+
+ + +
addSql('ALTER TABLE trip ADD pilotage_reference VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE trip DROP pilotage_reference'); + } +} diff --git a/httpdocs/src/ApiResource/TripApi.php b/httpdocs/src/ApiResource/TripApi.php index 132f977..2218f13 100644 --- a/httpdocs/src/ApiResource/TripApi.php +++ b/httpdocs/src/ApiResource/TripApi.php @@ -78,7 +78,7 @@ class TripApi #[ApiProperty(writable: true)] public ?VesselApi $vesselIri = null; - #[ApiProperty(writable: false)] + #[ApiProperty(writable: true)] public ?string $pilotageReference = null; /** diff --git a/httpdocs/src/Command/Patch/Patch001Command.php b/httpdocs/src/Command/Patch/Patch001Command.php new file mode 100644 index 0000000..17e13b8 --- /dev/null +++ b/httpdocs/src/Command/Patch/Patch001Command.php @@ -0,0 +1,39 @@ +entityManager->getRepository(Trip::class)->findAll(); + + foreach ($trips as $trip) { + $trip->setPilotageReference("P-" . $trip->getId() . "-" . $trip->getStartDate()->format('Y')); + } + + $this->entityManager->flush(); + return Command::SUCCESS; + } +} \ No newline at end of file diff --git a/httpdocs/src/Entity/Trip.php b/httpdocs/src/Entity/Trip.php index ac73847..ae8a143 100644 --- a/httpdocs/src/Entity/Trip.php +++ b/httpdocs/src/Entity/Trip.php @@ -18,6 +18,9 @@ class Trip #[ORM\Column] private ?int $id = null; + #[ORM\Column(length: 255, unique: true)] + private ?string $pilotageReference = null; + #[ORM\ManyToOne(targetEntity: Vessel::class, inversedBy: 'trips')] #[ORM\JoinColumn(nullable: false)] private Vessel $vessel; @@ -74,25 +77,25 @@ class Trip return $this->id; } - public function getVessel(): Vessel + public function getPilotageReference(): ?string { - return $this->vessel; + return $this->pilotageReference; } - public function setVessel(Vessel $vessel): self + public function setPilotageReference(string $pilotageReference): void { - $this->vessel = $vessel; - return $this; + $this->pilotageReference = $pilotageReference; } - public function getCustomerReference(): ?string + public function getVessel(): Vessel { - return $this->customerReference; + return $this->vessel; } - public function setCustomerReference(?string $customerReference): void + public function setVessel(Vessel $vessel): self { - $this->customerReference = $customerReference; + $this->vessel = $vessel; + return $this; } public function getStartLocation(): Location diff --git a/httpdocs/src/Mapper/TripApiToEntityMapper.php b/httpdocs/src/Mapper/TripApiToEntityMapper.php index 66c3f2d..263a379 100644 --- a/httpdocs/src/Mapper/TripApiToEntityMapper.php +++ b/httpdocs/src/Mapper/TripApiToEntityMapper.php @@ -7,6 +7,7 @@ use App\Entity\Trip; use App\Repository\TripRepository; use App\Repository\VesselRepository; use App\Repository\LocationRepository; +use Symfony\Component\Validator\Exception\ValidatorException; use Symfonycasts\MicroMapper\AsMapper; use Symfonycasts\MicroMapper\MapperInterface; use Symfonycasts\MicroMapper\MicroMapperInterface; @@ -77,6 +78,19 @@ class TripApiToEntityMapper implements MapperInterface $entity->setEndDate($dto->endDate); $entity->setNote($dto->note); + if ($dto->pilotageReference !== $entity->getPilotageReference()) { + $existingTrip = $this->repository->findOneBy(['pilotageReference' => $dto->pilotageReference]); + + if ($existingTrip !== null) { + throw new ValidatorException(sprintf( + 'A trip with the pilotage reference "%s" already exists.', + $dto->pilotageReference + )); + } + + $entity->setPilotageReference($dto->pilotageReference); + } + if ($dto->vesselIri->id) { $vessel = $this->vesselRepository->find($dto->vesselIri->id); if (!$vessel) { diff --git a/httpdocs/src/Mapper/TripEntityToApiMapper.php b/httpdocs/src/Mapper/TripEntityToApiMapper.php index d30605b..deafcb9 100644 --- a/httpdocs/src/Mapper/TripEntityToApiMapper.php +++ b/httpdocs/src/Mapper/TripEntityToApiMapper.php @@ -37,7 +37,7 @@ class TripEntityToApiMapper implements MapperInterface assert($dto instanceof TripApi); $dto->dbId = $entity->getId(); - $dto->pilotageReference = "P-" . $entity->getId() . "-" . $entity->getStartDate()->format('Y'); + $dto->pilotageReference = $entity->getPilotageReference(); $dto->startDate = $entity->getStartDate(); $dto->endDate = $entity->getEndDate(); $dto->note = $entity->getNote();