Skip to content

Commit e3bb96c

Browse files
committed
EV-267: POC on DTO and api platform
1 parent 3c904a6 commit e3bb96c

File tree

8 files changed

+138
-8
lines changed

8 files changed

+138
-8
lines changed

.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ APP_ENV=dev
2222
APP_SECRET=01324d73757787ffeba5f2f76cec1a28
2323
###< symfony/framework-bundle ###
2424

25+
###> app ###
26+
APP_PATH_PREFIX=/api/v2
27+
###< app ###
28+
29+
###> INDEX ###
30+
INDEX_URL=http://elasticsearch:9200
31+
INDEX_EVENTS_ALIAS=events
32+
INDEX_ORGANIZATION_ALIAS=organization
33+
###< INDEX ###
34+
2535
###> doctrine/doctrine-bundle ###
2636
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
2737
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml

compose.override.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/packages/api_platform.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ api_platform:
1111
jsonopenapi: ['application/vnd.openapi+json']
1212
html: ['text/html']
1313

14+
mapping:
15+
paths:
16+
- '%kernel.project_dir%/src/Api/Dto'
17+
18+
doctrine:
19+
enabled: false
20+
21+
elasticsearch:
22+
hosts: ['%env(INDEXING_URL)%']
23+
1424
defaults:
1525
stateless: true
1626
cache_headers:

config/services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ services:
1111
autowire: true # Automatically injects dependencies in your services.
1212
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
1313

14+
# bind:
15+
# # Bound services
16+
# Elasticsearch\Client: '@api_platform.elasticsearch.client'
17+
1418
# makes classes in src/ available to be used as services
1519
# this creates a service per class whose id is the fully-qualified class name
1620
App\:

docker-compose.override.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: "3"
2+
3+
services:
4+
phpfpm:
5+
depends_on:
6+
- elasticsearch
7+
- rabbit
8+
9+
rabbit:
10+
image: rabbitmq:3.12.4-management-alpine
11+
networks:
12+
- app
13+
- frontend
14+
ports:
15+
- "15672"
16+
environment:
17+
- RABBITMQ_DEFAULT_USER=user
18+
- RABBITMQ_DEFAULT_PASS=password
19+
- RABBITMQ_ERLANG_COOKIE='d53f319cd7376f8f840aaf9889f315ab
20+
21+
elasticsearch:
22+
image: elasticsearch:8.10.2
23+
networks:
24+
- app
25+
- frontend
26+
ports:
27+
- "9200"
28+
deploy:
29+
resources:
30+
limits:
31+
memory: 4096M
32+
reservations:
33+
memory: 4096M
34+
volumes:
35+
- ./.docker/data/elasticsearch:/usr/share/elasticsearch/data
36+
environment:
37+
- discovery.type=single-node
38+
- xpack.security.enabled=false
39+

src/Api/Dto/Event.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App\Api\Dto;
4+
5+
use ApiPlatform\Metadata\ApiProperty;
6+
use ApiPlatform\Metadata\ApiResource;
7+
use ApiPlatform\Metadata\Get;
8+
use App\Api\State\EventRepresentationProvider;
9+
10+
#[ApiResource(operations: [
11+
new Get(
12+
openapiContext: [
13+
'summary' => 'Get single event base on identifier',
14+
'parameters' => [
15+
[
16+
'name' => 'id',
17+
'in' => 'path',
18+
'required' => true,
19+
'schema' => [
20+
'type' => 'integer',
21+
],
22+
],
23+
],
24+
],
25+
output: EventRepresentationProvider::class,
26+
provider: EventRepresentationProvider::class,
27+
),
28+
])]
29+
class Event
30+
{
31+
#[ApiProperty(
32+
identifier: true,
33+
)]
34+
private int $id;
35+
36+
public function getId(): int
37+
{
38+
return $this->id;
39+
}
40+
41+
public function setId(int $id): static
42+
{
43+
$this->id = $id;
44+
45+
return $this;
46+
}
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Cover item data provider.
6+
*
7+
* @see https://api-platform.com/docs/core/data-providers/
8+
*/
9+
10+
namespace App\Api\State;
11+
12+
use ApiPlatform\Metadata\Operation;
13+
use ApiPlatform\State\ProviderInterface;
14+
use App\Api\Dto\Event;
15+
16+
/**
17+
* Class CoverItemDataProvider.
18+
*/
19+
final class EventRepresentationProvider implements ProviderInterface
20+
{
21+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
22+
{
23+
$event = new Event();
24+
$event->setId(1);
25+
26+
return $event;
27+
}
28+
}

src/ApiResource/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)