Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 4ca793f

Browse files
author
vagrant
committed
adds serializer, adds versioning
1 parent c4e2fa1 commit 4ca793f

18 files changed

+350
-19
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"symfony/flex": "^1.0",
1515
"symfony/framework-bundle": "^4.1",
1616
"symfony/lts": "^4@dev",
17+
"symfony/serializer": "^4.1",
1718
"symfony/twig-bundle": "^4.1",
19+
"symfony/validator": "^4.1",
1820
"symfony/webpack-encore-pack": "^1.0",
1921
"symfony/yaml": "^4.1"
2022
},

composer.lock

Lines changed: 236 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/packages/league_tactician.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ tactician:
44
commandbus:
55
default:
66
middleware:
7+
- app.middleware.response_message
78
# Security middleware - https://github.com/thephpleague/tactician-bundle#security-middleware-tacticianmiddlewaresecurity
89
# - tactician.middleware.security
910
# Validator middleware - https://github.com/thephpleague/tactician-bundle/tree/v1.0#validator-middleware-tacticianmiddlewarevalidator
10-
# - tactician.middleware.validator
11+
- tactician.middleware.validator
1112
# Locking middleware - http://tactician.thephpleague.com/plugins/locking-middleware/
1213
# - tactician.middleware.locking
1314
# Doctrine transactional middleware, requires additional package - https://github.com/thephpleague/tactician-doctrine
1415
# - tactician.middleware.doctrine
15-
- app.middleware.response_message
1616
- tactician.middleware.command_handler

config/packages/translation.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
framework:
2+
default_locale: '%locale%'
3+
translator:
4+
paths:
5+
- '%kernel.project_dir%/translations'
6+
fallbacks:
7+
- '%locale%'

config/routes.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
index:
2+
path: '/'
3+
methods: [GET]
4+
defaults:
5+
_controller: 'App\Controller\App\ShowApp'
6+
7+
api_routes:
8+
prefix: /api/{version}/
9+
resource: 'routes/api.yaml'
10+
requirements:
11+
version: '%api_version%'
12+
defaults:
13+
version: '%api_version%'

config/routes/api.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
api_project:
2+
prefix: '/project/'
3+
resource: 'project.yaml'

config/routes/project.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create_project:
2+
path: '/create'
3+
methods: [POST]
4+
defaults:
5+
_controller: 'App\Controller\Api\Project\CreateProject'

config/services.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Put parameters here that don't need to change on each machine where the app is deployed
55
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
66
parameters:
7+
locale: 'en'
8+
api_version: '1.0.0'
79

810
services:
911
# default configuration for services in *this* file
@@ -29,6 +31,11 @@ services:
2931
# add more service definitions when explicit configuration is needed
3032
# please note that last definitions always *replace* previous ones
3133

34+
get_set_method_normalizer:
35+
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
36+
public: false
37+
tags: [serializer.normalizer]
38+
3239
League\Tactician\CommandBus:
3340
alias: tactician.commandbus
3441

src/Controller/Api/Project/CreateProject.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,51 @@
55
namespace App\Controller\Api\Project;
66

77
use App\Handler\Project\CreateProject\CreateProjectCommand;
8-
use App\Handler\Project\CreateProject\ProjectResponse;
98
use League\Tactician\CommandBus;
109
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11-
use Symfony\Component\HttpFoundation\JsonResponse;
12-
use Symfony\Component\Routing\Annotation\Route;
10+
use Symfony\Component\HttpFoundation\Request;
11+
use Symfony\Component\HttpFoundation\Response;
12+
use Symfony\Component\Serializer\SerializerInterface;
1313

1414
class CreateProject extends AbstractController
1515
{
1616
/**
1717
* @var CommandBus
1818
*/
1919
private $commandBus;
20+
/**
21+
* @var SerializerInterface
22+
*/
23+
private $serializer;
2024

2125
/**
2226
* CreateProject constructor.
2327
*
2428
* @param CommandBus $commandBus
29+
* @param SerializerInterface $serializer
2530
*/
26-
public function __construct(CommandBus $commandBus)
31+
public function __construct(CommandBus $commandBus, SerializerInterface $serializer)
2732
{
2833
$this->commandBus = $commandBus;
34+
$this->serializer = $serializer;
2935
}
3036

3137
/**
3238
* Creates project - project is used as a placeholder for inner app logic
3339
*
34-
* @Route(path="/api/project/create", methods={"POST"}, name="project_create")
40+
* @param Request $request
3541
*
42+
* @return Response
43+
*
44+
* @throws \LogicException
3645
*/
37-
public function __invoke()
46+
public function __invoke(Request $request): Response
3847
{
39-
/** @var ProjectResponse $result */
48+
$data = $request->getContent();
49+
$createProjectCommand = $this->serializer->deserialize($data, CreateProjectCommand::class, 'json');
50+
4051
return $this->commandBus->handle(
41-
new CreateProjectCommand('test2')
52+
$createProjectCommand
4253
);
4354
}
4455
}

0 commit comments

Comments
 (0)