diff --git a/Makefile b/Makefile index dd92b88..f715876 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,10 @@ demo-import: .application-demo-import demo-remove: .application-demo-remove +github-import: .application-github-import + +github-remove: .application-github-remove + default-publish: @$(call .publish,dist/docker-run.default.sh,sveneisenschmidt/yay,$(DOCKER_ENV),$(DOCKER_BRANCH)) diff --git a/dist/examples/demo/example-01.sh b/dist/examples/demo/example-01.sh new file mode 100644 index 0000000..58e1e2a --- /dev/null +++ b/dist/examples/demo/example-01.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +# Enable demo integration +make demo-import + +# Start application +make start + +# Create new player +curl -X "POST" http://localhost:50080/api/players/ \ + -d "{\"name\": \"Jane Doe\",\"username\":\"jane.doe\",\"email\": \"jane.doe@example.org\",\"image_url\":\"https://api.adorable.io/avatars/128/354\"}" + +# Perform demo action 5x +curl -X "POST" http://localhost:50080/api/progress/ \ + -d "{\"username\":\"jane.doe\",\"actions\":[\"demo-action\",\"demo-action\",\"demo-action\",\"demo-action\",\"demo-action\"]}" + +# Get player activity +curl -X "GET" http://localhost:50080/api/players/jane.doe/personal-activities/ \ No newline at end of file diff --git a/dist/examples/github/example-01.sh b/dist/examples/github/example-01.sh new file mode 100644 index 0000000..9f6cdda --- /dev/null +++ b/dist/examples/github/example-01.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Enable demo integration +make github-import + +# Start application +make start \ No newline at end of file diff --git a/integration/default.yml b/integration/default.yml index 539ed22..a7e380c 100644 --- a/integration/default.yml +++ b/integration/default.yml @@ -28,3 +28,4 @@ integration: actions: ~ achievements: ~ validators: ~ + webhooks: ~ diff --git a/integration/github.yml b/integration/github.yml new file mode 100644 index 0000000..7229a26 --- /dev/null +++ b/integration/github.yml @@ -0,0 +1,6 @@ +integration: + levels: + actions: ~ + achievements: ~ + validators: ~ + webhooks: ~ diff --git a/makedefs/application.mk b/makedefs/application.mk index 145f274..c5c8f0b 100644 --- a/makedefs/application.mk +++ b/makedefs/application.mk @@ -45,11 +45,34 @@ .application-demo-remove-fixtures: @$(call .docker-run,cli,'\ - php bin/console yay:integration:disable default && \ + php bin/console yay:integration:disable default && \ php bin/console yay:integration:disable demo && \ php bin/console cache:clear --no-warmup && \ php bin/console cache:warmup') +.application-github-import: \ + .application-clean-database \ + .application-github-import-fixtures + +.application-github-remove: \ + .application-github-remove-fixtures \ + .application-clean-database + +.application-github-import-fixtures: + @$(call .docker-run,cli,'\ + php bin/console yay:integration:enable default integration/default && \ + php bin/console yay:integration:enable github integration/github && \ + php bin/console yay:recalculate && \ + php bin/console cache:clear --no-warmup && \ + php bin/console cache:warmup') + +.application-github-remove-fixtures: + @$(call .docker-run,cli,'\ + php bin/console yay:integration:disable default && \ + php bin/console yay:integration:disable github && \ + php bin/console cache:clear --no-warmup && \ + php bin/console cache:warmup') + .application-test: @$(call .docker-run,cli,'\ php bin/console doctrine:schema:drop --env=test --force --em=default && \ diff --git a/src/App/Api/Controller/PlayerController.php b/src/App/Api/Controller/PlayerController.php index e8978cd..63e920b 100644 --- a/src/App/Api/Controller/PlayerController.php +++ b/src/App/Api/Controller/PlayerController.php @@ -13,6 +13,7 @@ use App\Api\Validator\EntityValidator; use Component\Engine\Engine; use Component\Entity\PlayerInterface; +use Component\Entity\Activity; /** * @Route("/players") @@ -382,11 +383,17 @@ public function indexPersonalActivitiesAction( throw $this->createNotFoundException(); } - /** @var PlayerInterface $player */ - $player = $players->first(); + $activities = $players + ->first() + ->getActivities() + ->toArray(); + + \usort($activities, function (Activity $a, Activity $b) { + return $a->getCreatedAt() > $b->getCreatedAt() ? -1 : 1; + }); return $serializer->createResponse( - $player->getActivities(), + $activities, ['player.personal_activities.show'] ); } diff --git a/src/App/Api/EventListener/KernelExceptionListener.php b/src/App/Api/EventListener/KernelExceptionListener.php new file mode 100644 index 0000000..843826b --- /dev/null +++ b/src/App/Api/EventListener/KernelExceptionListener.php @@ -0,0 +1,32 @@ +serializer = $serializer; + } + + public function onKernelException(GetResponseForExceptionEvent $event) + { + $exception = $event->getException(); + $response = $this->serializer->createResponse([ + 'exception' => get_class($exception), + 'message' => $exception->getMessage() + ]); + + if ($exception instanceof HttpExceptionInterface) { + $response->setStatusCode($exception->getStatusCode()); + } else { + $response->setStatusCode(500); + } + + $event->setResponse($response); + } +} \ No newline at end of file diff --git a/src/App/Api/Resources/config/services.yml b/src/App/Api/Resources/config/services.yml index a4ee1f9..c8d1076 100644 --- a/src/App/Api/Resources/config/services.yml +++ b/src/App/Api/Resources/config/services.yml @@ -12,6 +12,15 @@ services: App\Api\Response\ResponseSerializer: ~ App\Api\Validator\EntityValidator: ~ + App\Api\EventListener\KernelExceptionListener: + tags: + - { name: kernel.event_listener, event: kernel.exception, method: onKernelException } + + App\Api\Serializer\EventListener\LinkListener: + public: true + tags: + - { name: jms_serializer.event_listener, event: serializer.post_serialize, method: onPostSerialize, direction: serialization } + Component\HttpFoundation\Request\ParamConverter\QueryStringConverter: tags: - { name: request.param_converter, priority: -2, converter: QueryString } @@ -23,10 +32,5 @@ services: - { name: request.param_converter, priority: -2, converter: JsonField } Component\HttpFoundation\Request\ParamConverter\DeserializeFieldConverter: tags: - - { name: request.param_converter, priority: -2, converter: DeserializeField } - - App\Api\Serializer\EventListener\LinkListener: - public: true - tags: - - { name: jms_serializer.event_listener, event: serializer.post_serialize, method: onPostSerialize, direction: serialization } + - { name: request.param_converter, priority: -2, converter: DeserializeField } diff --git a/src/App/Engine/Controller/EngineControllerTrait.php b/src/App/Engine/Controller/EngineControllerTrait.php index ae2d87a..609fe69 100644 --- a/src/App/Engine/Controller/EngineControllerTrait.php +++ b/src/App/Engine/Controller/EngineControllerTrait.php @@ -29,7 +29,7 @@ public function advance( foreach ($actions as $action) { $actionDefinitions = $engine->findActionDefinitionBy(['name' => $action]); if ($actionDefinitions->isEmpty()) { - continue; + throw $this->createNotFoundException(sprintf('Action "%s" not found', $action)); } $personalActionCollection->add(