Skip to content

Commit

Permalink
added api for entry app
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Sep 22, 2023
1 parent dcee144 commit c3841c4
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"monolog/monolog": "^1.25",
"php-di/slim-bridge": "^3",
"phpmailer/phpmailer": "^6.0",
"ramsey/uuid": "^4.7",
"robmorgan/phinx": "^0.12.5",
"selective/basepath": "^2.1",
"sentry/sdk": "^3.1",
Expand Down
238 changes: 237 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ protected function redirect(
/**
* @param array<string,string> $json
*/
protected function getResponseWithJson(Response $response, array $json): Response
protected function getResponseWithJson(Response $response, array $json, int $statusCode = 200): Response
{
$encodedJson = \GuzzleHttp\json_encode($json);
$response->getBody()->write($encodedJson);

return $response
->withHeader('Content-Type', 'application/json')
->withStatus(200);
->withStatus($statusCode);
}

protected function getRouter(Request $request): RouteParserInterface
Expand Down
4 changes: 3 additions & 1 deletion src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace kissj\Application;

use kissj\Entry\EntryController;
use kissj\Event\EventController;
use kissj\Export\ExportController;
use kissj\Middleware\AdminsOnlyMiddleware;
Expand Down Expand Up @@ -263,8 +264,9 @@ public function addRoutesInto(App $app): App
});
});

// TODO make full v3 async api for JS frontend
$app->group($app->getBasePath() . '/v3', function (RouteCollectorProxy $app) {
$app->post('/entry/{entryCode}', EntryController::class . '::entry')
->setName('entry');
$app->group('/event/{eventSlug}', function (RouteCollectorProxy $app) {
$app->group('/admin', function (RouteCollectorProxy $app) {
$app->group('/{participantId}', function (RouteCollectorProxy $app) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddApiSecretEntryCode extends AbstractMigration
{
public function up(): void
{
$tableParticipant = $this->table('participant');
$tableParticipant->addColumn('entry_date', 'datetime', ['null' => true]);
$tableParticipant->addColumn('entry_code', 'string', ['null' => false, 'default' => 'ABCDEFGH']);
$tableParticipant->save();

$tableParticipant->changeColumn('entry_code', 'string', ['null' => false]);
$tableParticipant->save();


$tableEvent = $this->table('event');
$tableEvent->addColumn('api_secret', 'string', ['null' => false, 'default' => '']);
$tableEvent->save();
}

public function down(): void
{
$participantTable = $this->table('participant');
$participantTable->removeColumn('entry_date');
$participantTable->removeColumn('entry_code');
$participantTable->save();

$eventTable = $this->table('event');
$eventTable->removeColumn('api_secret');
$eventTable->save();
}
}
Loading

0 comments on commit c3841c4

Please sign in to comment.