Skip to content

Commit

Permalink
fixed codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed May 27, 2024
1 parent fce20f0 commit dfcf314
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,22 +333,22 @@ 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');
});

$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');
});
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/AddCorsHeaderForAppDomainsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 313 in src/Participant/ParticipantRepository.php

View workflow job for this annotation

GitHub Actions / test / Static Analysis

Cannot access property $event on kissj\User\User|null.
return $participant;
}

return null;
}

public function findParticipantById(int $participantId, Event $event): ?Participant
{
$participant = $this->findOneBy(['id' => $participantId]);
Expand Down
19 changes: 10 additions & 9 deletions src/ParticipantVendor/ParticipantVendorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand All @@ -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,
Expand All @@ -62,5 +64,4 @@ public function RetrieveParticipantByTieCode(
],
);
}

}
48 changes: 12 additions & 36 deletions src/ParticipantVendor/VendoredParticipantType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}
3 changes: 2 additions & 1 deletion src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion src/User/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public function findSkautisUser(int $skautisId, Event $event): ?User
'event' => $event,
]);
}

}

0 comments on commit dfcf314

Please sign in to comment.