From dfcf3140b0b71bd174c1e5669a356a0d0194f5cd Mon Sep 17 00:00:00 2001 From: Lung Date: Tue, 28 May 2024 00:45:27 +0200 Subject: [PATCH] fixed codestyle --- src/Application/Route.php | 6 +-- .../AddCorsHeaderForAppDomainsMiddleware.php | 2 +- src/Participant/ParticipantRepository.php | 9 +++- .../ParticipantVendorController.php | 19 ++++---- .../VendoredParticipantType.php | 48 +++++-------------- src/Settings/Settings.php | 3 +- src/User/UserRepository.php | 1 - 7 files changed, 35 insertions(+), 53 deletions(-) diff --git a/src/Application/Route.php b/src/Application/Route.php index 3fda9444..7f42fcc3 100755 --- a/src/Application/Route.php +++ b/src/Application/Route.php @@ -333,14 +333,14 @@ public function addRoutesInto(App $app): App ->add(AddCorsHeaderForAppDomainsMiddleware::class) ->setName('entry-troop-from-web-app'); }); - $app->group("/vendor", function (RouteCollectorProxy $app) { + $app->group('/vendor', function (RouteCollectorProxy $app) { $app->map(['POST', 'OPTIONS'], '/bearercheck', function (Response $response) { return $response->withStatus(200); }) ->add(ApiAuthorizedOnlyMiddleware::class) ->add(AddCorsHeaderForAppDomainsMiddleware::class) ->setName('entry-participant-from-web-app'); - $app->map(['GET', 'OPTIONS'],'/participant/{TieCode}', ParticipantVendorController::class . '::RetrieveParticipantByTieCode') + $app->map(['GET', 'OPTIONS'],'/participant/{tieCode}', ParticipantVendorController::class . '::retrieveParticipantByTieCode') ->add(ApiAuthorizedOnlyMiddleware::class) ->add(AddCorsHeaderForAppDomainsMiddleware::class) ->setName('entry-troop-from-web-app'); @@ -348,7 +348,7 @@ public function addRoutesInto(App $app): App $app->group('/event/{eventSlug}', function (RouteCollectorProxy $app) { $app->group('/admin', function (RouteCollectorProxy $app) { - $app->group('/{participantId}', function (RouteCollectorProxy $app) { + $app->group('/{participantId}', function (RouteCollectorProxy $app) { $app->post('/adminNote', AdminController::class . '::changeAdminNote') ->setName('admin-change-note'); }); diff --git a/src/Middleware/AddCorsHeaderForAppDomainsMiddleware.php b/src/Middleware/AddCorsHeaderForAppDomainsMiddleware.php index 6b717240..15372734 100644 --- a/src/Middleware/AddCorsHeaderForAppDomainsMiddleware.php +++ b/src/Middleware/AddCorsHeaderForAppDomainsMiddleware.php @@ -18,7 +18,7 @@ public function process(Request $request, ResponseHandler $handler): Response $response = $handler->handle($request); } - return $response->withHeader('Access-Control-Allow-Origin', 'https://kissj.skauting.cz') + return $response->withHeader('Access-Control-Allow-Origin', 'https://kissj.skauting.cz') // TODO fix for production - make dynamic or list ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') ->withHeader('Access-Control-Allow-Headers', 'authorization') ->withHeader('Access-Control-Allow-Credentials', 'true'); // also handle cookies diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index 9def18bb..d27426b0 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -306,12 +306,17 @@ public function findOneByEntryCode(string $entryCode): ?Participant public function findOneByTieCodeAndEvent(string $tieCode, Event $authorizedEvent): ?Participant { $participant = $this->findOneBy(['tie_code' => $tieCode]); - if ($participant === null) {return null;} - if ($participant->user->event == $authorizedEvent) { + if ($participant === null) { + return null; + } + + if ($participant->user->event->id === $authorizedEvent->id) { return $participant; } + return null; } + public function findParticipantById(int $participantId, Event $event): ?Participant { $participant = $this->findOneBy(['id' => $participantId]); diff --git a/src/ParticipantVendor/ParticipantVendorController.php b/src/ParticipantVendor/ParticipantVendorController.php index 9ff9e080..ad46b258 100755 --- a/src/ParticipantVendor/ParticipantVendorController.php +++ b/src/ParticipantVendor/ParticipantVendorController.php @@ -18,25 +18,25 @@ public function __construct( ) { } - public function RetrieveParticipantByTieCode( + public function retrieveParticipantByTieCode( Request $request, Response $response, Event $authorizedEvent, - string $TieCode, - + string $tieCode, ): Response { - $participant = $this->participantRepository->findOneByTieCodeAndEvent($TieCode, $authorizedEvent); + $participant = $this->participantRepository->findOneByTieCodeAndEvent($tieCode, $authorizedEvent); - if ($participant == null) { + if ($participant === null) { return $response->withStatus(404); } + $allowHealthData = (bool)$request->getHeader('Allow-Health')[0]; $vendoredParticipant = new VendoredParticipantType( - $participant->role -> value ?? "norole", + $participant->role -> value ?? 'norole', $participant->firstName, $participant->lastName, - $participant->birthDate == null ? null : $participant->birthDate->format('Y-m-d'), + $participant->birthDate?->format('Y-m-d'), $participant->nickname, ); @@ -53,7 +53,9 @@ public function RetrieveParticipantByTieCode( $body = json_encode($vendoredParticipant); - if ($body === false) { return $response->withStatus(500); } + if ($body === false) { + return $response->withStatus(500); + } return $this->getResponseWithJson( $response, @@ -62,5 +64,4 @@ public function RetrieveParticipantByTieCode( ], ); } - } diff --git a/src/ParticipantVendor/VendoredParticipantType.php b/src/ParticipantVendor/VendoredParticipantType.php index df4a16d4..97665672 100644 --- a/src/ParticipantVendor/VendoredParticipantType.php +++ b/src/ParticipantVendor/VendoredParticipantType.php @@ -4,42 +4,18 @@ class VendoredParticipantType { - public ?string $role; - public ?string $name; - public ?string $surname; - public ?string $birthdate; - public ?string $leaderName; - public ?string $leaderSurname; - public ?string $leaderContact; - public ?string $nickname; - public ?string $psychicalHealth; // nullable string - public ?string $physicalHealth; // nullable string - public ?string $medicaments; // nullable string - public function __construct( - ?string $role, - ?string $name, - ?string $surname, - ?string $birthdate, - ?string $nickname = null, - ?string $leaderName = null, - ?string $leaderSurname = null, - ?string $leaderContact = null, - ?string $psychicalHealth = null, - ?string $physicalHealth = null, - ?string $medicaments = null + public ?string $role, + public ?string $name, + public ?string $surname, + public ?string $birthdate, + public ?string $nickname = null, + public ?string $leaderName = null, + public ?string $leaderSurname = null, + public ?string $leaderContact = null, + public ?string $psychicalHealth = null, + public ?string $physicalHealth = null, + public ?string $medicaments = null ) { - $this->role = $role; - $this->nickname = $nickname; - $this->name = $name; - $this->surname = $surname; - $this->birthdate = $birthdate; - $this->leaderName = $leaderName; - $this->leaderSurname = $leaderSurname; - $this->leaderContact = $leaderContact; - $this->psychicalHealth = $psychicalHealth; - $this->physicalHealth = $physicalHealth; - $this->medicaments = $medicaments; } - -} \ No newline at end of file +} diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index a815ef60..2d1d77da 100755 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -12,7 +12,6 @@ use kissj\BankPayment\IBankPaymentService; use kissj\BankPayment\TatraBankPaymentService; use kissj\Entry\EntryController; -use kissj\Entry\ParticipantVendorController; use kissj\Event\ContentArbiterGuest; use kissj\Event\ContentArbiterIst; use kissj\Event\ContentArbiterPatrolLeader; @@ -67,6 +66,7 @@ use kissj\Participant\Troop\TroopLeaderRepository; use kissj\Participant\Troop\TroopParticipantRepository; use kissj\Participant\Troop\TroopService; +use kissj\ParticipantVendor\ParticipantVendorController; use kissj\Payment\PaymentRepository; use kissj\Payment\PaymentService; use kissj\Payment\QrCodeService; @@ -186,6 +186,7 @@ public function getContainerDefinition(string $envPath, string $envFilename): ar ParticipantController::class => autowire(), ParticipantRepository::class => autowire(), ParticipantService::class => autowire(), + ParticipantVendorController::class => autowire(), PatrolController::class => autowire(), PatrolLeaderRepository::class => autowire(), PatrolLeadersOnlyMiddleware::class => autowire(), diff --git a/src/User/UserRepository.php b/src/User/UserRepository.php index 9f84138c..735cfae1 100755 --- a/src/User/UserRepository.php +++ b/src/User/UserRepository.php @@ -48,5 +48,4 @@ public function findSkautisUser(int $skautisId, Event $event): ?User 'event' => $event, ]); } - }