From 79759f1e2f871467b98c33221424da909946518f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 20 Mar 2025 17:53:35 +0200 Subject: [PATCH] fixes, testing --- .../location-form.component.html | 2 +- .../location-form/location-form.component.ts | 12 +++++++ .../shipping-company-form.component.html | 2 +- .../trip-detail/trip-detail.component.html | 6 ++-- .../trip/trip-detail/trip-detail.component.ts | 3 +- .../user-trip-detail.component.html | 2 +- .../vessel-form/vessel-form.component.html | 4 +-- .../zone/zone-form/zone-form.component.html | 2 +- httpdocs/src/ApiResource/UserTripEventApi.php | 6 ++-- httpdocs/src/Entity/User.php | 1 + .../src/Mapper/LocationApiToEntityMapper.php | 8 ++--- httpdocs/src/Mapper/TripApiToEntityMapper.php | 35 ++++++++++++++++--- .../Mapper/TripLocationApiToEntityMapper.php | 8 ++--- httpdocs/src/Mapper/UserApiToEntityMapper.php | 4 +-- 14 files changed, 67 insertions(+), 28 deletions(-) diff --git a/angular/src/app/_views/location/location-form/location-form.component.html b/angular/src/app/_views/location/location-form/location-form.component.html index 20dcbad..10302dd 100644 --- a/angular/src/app/_views/location/location-form/location-form.component.html +++ b/angular/src/app/_views/location/location-form/location-form.component.html @@ -21,7 +21,7 @@ [getDataFunction]="getZones" [displayedDataField]="'name'" [listColDefinitions]="zoneColDefinitions" - [dataSet]="data?.zoneIri" + [dataSet]="data?.zone" > diff --git a/angular/src/app/_views/location/location-form/location-form.component.ts b/angular/src/app/_views/location/location-form/location-form.component.ts index a087932..ec997e8 100644 --- a/angular/src/app/_views/location/location-form/location-form.component.ts +++ b/angular/src/app/_views/location/location-form/location-form.component.ts @@ -9,6 +9,7 @@ import { TranslateService } from "@ngx-translate/core"; import { Router } from "@angular/router"; import { ROUTE_BASE_DATA } from "@app/app-routing.module"; import {AppHelperService} from "@app/_helpers/app-helper.service"; +import {Validators} from "@angular/forms"; @Component({ selector: 'app-location-form', @@ -42,6 +43,17 @@ export class LocationFormComponent extends AbstractDataFormComponent { return this.zoneService.zonesGetCollection(index, pageSize, term); } diff --git a/angular/src/app/_views/shipping-company/shipping-company-form/shipping-company-form.component.html b/angular/src/app/_views/shipping-company/shipping-company-form/shipping-company-form.component.html index 2d48a4a..6868ad8 100644 --- a/angular/src/app/_views/shipping-company/shipping-company-form/shipping-company-form.component.html +++ b/angular/src/app/_views/shipping-company/shipping-company-form/shipping-company-form.component.html @@ -28,7 +28,7 @@ @if (isEditMode()) { - } diff --git a/angular/src/app/_views/trip/trip-detail/trip-detail.component.html b/angular/src/app/_views/trip/trip-detail/trip-detail.component.html index 7808b32..ab3e0dd 100644 --- a/angular/src/app/_views/trip/trip-detail/trip-detail.component.html +++ b/angular/src/app/_views/trip/trip-detail/trip-detail.component.html @@ -22,7 +22,7 @@
-
diff --git a/angular/src/app/_views/trip/trip-detail/trip-detail.component.ts b/angular/src/app/_views/trip/trip-detail/trip-detail.component.ts index 7c747e2..d74f1de 100644 --- a/angular/src/app/_views/trip/trip-detail/trip-detail.component.ts +++ b/angular/src/app/_views/trip/trip-detail/trip-detail.component.ts @@ -305,6 +305,7 @@ export class TripDetailComponent implements OnInit, AfterViewInit { } saveAllTripLocations() { + // First update the location objects in our tripLocations array this.tripLocations.forEach((tripLocation, index) => { const locationFormValue = this.locationForms[index].get('location')?.value; @@ -322,7 +323,7 @@ export class TripDetailComponent implements OnInit, AfterViewInit { }); // Filter out trip locations that have no location set - const validTripLocations = this.tripLocations.filter(tl => tl.location); + const validTripLocations = this.tripLocations.filter(tl => tl.locationIri); if (validTripLocations.length === 0) { return; diff --git a/angular/src/app/_views/user-trip/user-trip-detail/user-trip-detail.component.html b/angular/src/app/_views/user-trip/user-trip-detail/user-trip-detail.component.html index 4fa22d5..36334e3 100644 --- a/angular/src/app/_views/user-trip/user-trip-detail/user-trip-detail.component.html +++ b/angular/src/app/_views/user-trip/user-trip-detail/user-trip-detail.component.html @@ -96,7 +96,7 @@
-
diff --git a/angular/src/app/_views/vessel/vessel-form/vessel-form.component.html b/angular/src/app/_views/vessel/vessel-form/vessel-form.component.html index d48b4a3..153438a 100644 --- a/angular/src/app/_views/vessel/vessel-form/vessel-form.component.html +++ b/angular/src/app/_views/vessel/vessel-form/vessel-form.component.html @@ -31,7 +31,7 @@ [getDataFunction]="getShippingCompanies" [displayedDataField]="'name'" [listColDefinitions]="shippingCompanyColDefinitions" - [dataSet]="data?.companyIri"> + [dataSet]="data?.company"> @@ -42,7 +42,7 @@ @if (isEditMode()) { - } diff --git a/angular/src/app/_views/zone/zone-form/zone-form.component.html b/angular/src/app/_views/zone/zone-form/zone-form.component.html index 97aef3d..88a53f8 100644 --- a/angular/src/app/_views/zone/zone-form/zone-form.component.html +++ b/angular/src/app/_views/zone/zone-form/zone-form.component.html @@ -15,7 +15,7 @@ @if (isEditMode()) { - } diff --git a/httpdocs/src/ApiResource/UserTripEventApi.php b/httpdocs/src/ApiResource/UserTripEventApi.php index 81fbacb..0af4ffa 100644 --- a/httpdocs/src/ApiResource/UserTripEventApi.php +++ b/httpdocs/src/ApiResource/UserTripEventApi.php @@ -33,13 +33,13 @@ use Symfony\Component\Validator\Constraints\NotBlank; security: 'is_granted("ROLE_USER")' ), new Post( - security: 'is_granted("ROLE_ADMIN")' + security: 'is_granted("ROLE_USER")' ), new Patch( - security: 'is_granted("ROLE_ADMIN")' + security: 'is_granted("ROLE_USER")' ), new Delete( - security: 'is_granted("ROLE_ADMIN")' + security: 'is_granted("ROLE_USER")' ) ], order: ['date' => 'ASC'], diff --git a/httpdocs/src/Entity/User.php b/httpdocs/src/Entity/User.php index e7dd4a5..3b9835a 100644 --- a/httpdocs/src/Entity/User.php +++ b/httpdocs/src/Entity/User.php @@ -12,6 +12,7 @@ use Symfony\Component\Security\Core\User\UserInterface; class User implements UserInterface, PasswordAuthenticatedUserInterface { public const ROLE_ADMIN = "ROLE_ADMIN"; + public const ROLE_USER = "ROLE_USER"; #[ORM\Id] #[ORM\GeneratedValue] diff --git a/httpdocs/src/Mapper/LocationApiToEntityMapper.php b/httpdocs/src/Mapper/LocationApiToEntityMapper.php index 657c4fc..cf14021 100644 --- a/httpdocs/src/Mapper/LocationApiToEntityMapper.php +++ b/httpdocs/src/Mapper/LocationApiToEntityMapper.php @@ -32,11 +32,11 @@ class LocationApiToEntityMapper implements MapperInterface return $entity; } - if (!$dto->zone) { + if (!$dto->zoneIri) { throw new \Exception('Zone is required for new locations'); } - $zone = $this->zoneRepository->find($dto->zone->id); + $zone = $this->zoneRepository->find($dto->zoneIri->id); if (!$zone) { throw new \Exception('Zone not found'); } @@ -57,8 +57,8 @@ class LocationApiToEntityMapper implements MapperInterface $entity->setIsPlace($dto->isPlace); $entity->setIsPort($dto->isPort); - if ($dto->zone) { - $zone = $this->zoneRepository->find($dto->zone->id); + if ($dto->zoneIri) { + $zone = $this->zoneRepository->find($dto->zoneIri->id); if (!$zone) { throw new \Exception('Zone not found'); } diff --git a/httpdocs/src/Mapper/TripApiToEntityMapper.php b/httpdocs/src/Mapper/TripApiToEntityMapper.php index de1572e..5ddd3f0 100644 --- a/httpdocs/src/Mapper/TripApiToEntityMapper.php +++ b/httpdocs/src/Mapper/TripApiToEntityMapper.php @@ -35,24 +35,24 @@ class TripApiToEntityMapper implements MapperInterface } // For new trips, we need the vessel and locations - if (!$dto->vessel?->id) { + if (!$dto->vesselIri->id) { throw new \Exception('Vessel is required for new trips'); } - if (!$dto->startLocation?->id || !$dto->endLocation?->id) { + if (!$dto->startLocationIri->id || !$dto->endLocationIri->id) { throw new \Exception('Start and end locations are required for new trips'); } - $vessel = $this->vesselRepository->find($dto->vessel->id); + $vessel = $this->vesselRepository->find($dto->vesselIri->id); if (!$vessel) { throw new \Exception('Vessel not found'); } - $startLocation = $this->locationRepository->find($dto->startLocation->id); + $startLocation = $this->locationRepository->find($dto->startLocationIri->id); if (!$startLocation) { throw new \Exception('Start location not found'); } - $endLocation = $this->locationRepository->find($dto->endLocation->id); + $endLocation = $this->locationRepository->find($dto->endLocationIri->id); if (!$endLocation) { throw new \Exception('End location not found'); } @@ -79,6 +79,31 @@ class TripApiToEntityMapper implements MapperInterface $entity->setEndDate($dto->endDate); $entity->setNote($dto->note); + if ($dto->vesselIri->id) { + $vessel = $this->vesselRepository->find($dto->vesselIri->id); + if (!$vessel) { + throw new \Exception('Vessel not found'); + } + $entity->setVessel($vessel); + } + + if ($dto->startLocationIri->id) { + $startLocation = $this->locationRepository->find($dto->startLocationIri->id); + if (!$startLocation) { + throw new \Exception('Start location not found'); + } + $entity->setStartLocation($startLocation); + } + + if ($dto->endLocationIri->id) { + $endLocation = $this->locationRepository->find($dto->endLocationIri->id); + if (!$endLocation) { + throw new \Exception('End location not found'); + } + $entity->setEndLocation($endLocation); + } + + return $entity; } } \ No newline at end of file diff --git a/httpdocs/src/Mapper/TripLocationApiToEntityMapper.php b/httpdocs/src/Mapper/TripLocationApiToEntityMapper.php index fec969b..c448767 100644 --- a/httpdocs/src/Mapper/TripLocationApiToEntityMapper.php +++ b/httpdocs/src/Mapper/TripLocationApiToEntityMapper.php @@ -35,16 +35,16 @@ class TripLocationApiToEntityMapper implements MapperInterface } // For new trip locations, we need trip and location - if (!$dto->trip?->id || !$dto->location?->id) { + if (!$dto->tripIri->id || !$dto->locationIri->id) { throw new \Exception('Trip and Location are required for new trip locations'); } - $trip = $this->tripRepository->find($dto->trip->id); + $trip = $this->tripRepository->find($dto->tripIri->id); if (!$trip) { throw new \Exception('Trip not found'); } - $location = $this->locationRepository->find($dto->location->id); + $location = $this->locationRepository->find($dto->locationIri->id); if (!$location) { throw new \Exception('Location not found'); } @@ -60,7 +60,7 @@ class TripLocationApiToEntityMapper implements MapperInterface assert($entity instanceof TripLocation); if ($dto->location) { - $location = $this->locationRepository->find($dto->location->id); + $location = $this->locationRepository->find($dto->locationIri->id); if (!$location) { throw new \Exception('Location not found'); } diff --git a/httpdocs/src/Mapper/UserApiToEntityMapper.php b/httpdocs/src/Mapper/UserApiToEntityMapper.php index e4f802c..6e9c675 100644 --- a/httpdocs/src/Mapper/UserApiToEntityMapper.php +++ b/httpdocs/src/Mapper/UserApiToEntityMapper.php @@ -49,11 +49,11 @@ class UserApiToEntityMapper implements MapperInterface $roles = $entity->getRoles(); if ($dto->isAdmin && !in_array(User::ROLE_ADMIN, $roles, true)) { - $entity->setRoles([User::ROLE_ADMIN]); + $entity->setRoles([User::ROLE_ADMIN, User::ROLE_USER]); } if (!$dto->isAdmin && in_array(User::ROLE_ADMIN, $roles, true)) { - $entity->setRoles([]); + $entity->setRoles([User::ROLE_USER]); } if ($dto->password) {