-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds endpoints for listing, retrieving, and deleting ActivityArea. (#658
- Loading branch information
1 parent
e3e98d9
commit a87ed15
Showing
20 changed files
with
376 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
get: | ||
path: /{id} | ||
controller: App\Controller\Api\ActivityAreaApiController::get | ||
methods: ['GET'] | ||
|
||
list: | ||
path: / | ||
controller: App\Controller\Api\ActivityAreaApiController::list | ||
methods: ['GET'] | ||
|
||
remove: | ||
path: /{id} | ||
controller: App\Controller\Api\ActivityAreaApiController::remove | ||
methods: ['DELETE'] |
14 changes: 14 additions & 0 deletions
14
public/docs/components/paths/activity-area/Collection.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
get: | ||
tags: | ||
- Áreas de Atividade | ||
summary: Recupera uma lista de áreas de atividade | ||
responses: | ||
'200': | ||
description: Lista de áreas de atividade | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
allOf: | ||
- $ref: '../../responses/activity-area/ActivityAreaGetCollectionResponse.yaml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
get: | ||
parameters: | ||
- $ref: '../../parameters/path/id.yaml' | ||
tags: | ||
- Áreas de Atividade | ||
summary: Recupera uma única área de atividade | ||
responses: | ||
'200': | ||
description: Área de atividade encontrada | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../responses/activity-area/ActivityAreaGetItemResponse.yaml' | ||
'404': | ||
description: Área de atividade não encontrada | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../responses/activity-area/ActivityAreaNotFound.yaml' | ||
|
||
delete: | ||
parameters: | ||
- $ref: '../../parameters/path/id.yaml' | ||
tags: | ||
- Áreas de Atividade | ||
summary: Remove uma única área de atividade | ||
responses: | ||
'204': | ||
description: Não possui conteúdo de resposta | ||
content: | ||
application/json: {} | ||
'404': | ||
description: Área de atividade não encontrada | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../responses/activity-area/ActivityAreaNotFound.yaml' |
3 changes: 3 additions & 0 deletions
3
public/docs/components/responses/activity-area/ActivityAreaGetCollectionResponse.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type: object | ||
allOf: | ||
- $ref: './CommonDefinitions.yaml#/ActivityAreaBase' |
3 changes: 3 additions & 0 deletions
3
public/docs/components/responses/activity-area/ActivityAreaGetItemResponse.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type: object | ||
allOf: | ||
- $ref: './CommonDefinitions.yaml#/ActivityAreaBase' |
11 changes: 11 additions & 0 deletions
11
public/docs/components/responses/activity-area/ActivityAreaNotFound.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type: object | ||
properties: | ||
error_message: | ||
type: string | ||
default: "not_found" | ||
error_details: | ||
type: object | ||
properties: | ||
description: | ||
type: string | ||
default: "The requested ActivityArea was not found." |
13 changes: 13 additions & 0 deletions
13
public/docs/components/responses/activity-area/CommonDefinitions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ActivityAreaBase: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
format: uuid | ||
description: "Identificador único da área de atividade." | ||
example: "123e4567-e89b-12d3-a456-426614174000" | ||
name: | ||
type: string | ||
maxLength: 20 | ||
description: "Nome da área de atividade." | ||
example: "Teatro" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
format: uuid | ||
description: "Identificador único da área de atividade." | ||
example: "123e4567-e89b-12d3-a456-426614174000" | ||
name: | ||
type: string | ||
maxLength: 20 | ||
description: "Nome da área de atividade." | ||
example: "Teatro" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Api; | ||
|
||
use App\Helper\EntityIdNormalizerHelper; | ||
use App\Service\Interface\ActivityAreaServiceInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
class ActivityAreaApiController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
private readonly ActivityAreaServiceInterface $service, | ||
) { | ||
} | ||
|
||
public function get(?Uuid $id): JsonResponse | ||
{ | ||
$activityArea = $this->service->get($id); | ||
|
||
return $this->json($activityArea, context: ['groups' => ['activity-area.get', 'activity-area.get.item']]); | ||
} | ||
|
||
public function list(): JsonResponse | ||
{ | ||
return $this->json($this->service->list(), context: [ | ||
'groups' => 'activity-area.get', | ||
AbstractNormalizer::CALLBACKS => [ | ||
'parent' => [EntityIdNormalizerHelper::class, 'normalizeEntityId'], | ||
], | ||
]); | ||
} | ||
|
||
public function remove(?Uuid $id): JsonResponse | ||
{ | ||
$this->service->remove($id); | ||
|
||
return $this->json(data: [], status: Response::HTTP_NO_CONTENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Exception/ActivityArea/ActivityAreaResourceNotFoundException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exception\ActivityArea; | ||
|
||
use App\Exception\ResourceNotFoundException; | ||
|
||
class ActivityAreaResourceNotFoundException extends ResourceNotFoundException | ||
{ | ||
protected const string RESOURCE = 'ActivityArea'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Service; | ||
|
||
use App\Entity\ActivityArea; | ||
use App\Exception\ActivityArea\ActivityAreaResourceNotFoundException; | ||
use App\Repository\Interface\ActivityAreaRepositoryInterface; | ||
use App\Service\Interface\ActivityAreaServiceInterface; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
readonly class ActivityAreaService extends AbstractEntityService implements ActivityAreaServiceInterface | ||
{ | ||
public function __construct( | ||
private ActivityAreaRepositoryInterface $repository, | ||
private Security $security, | ||
) { | ||
parent::__construct($this->security); | ||
} | ||
|
||
public function get(Uuid $id): ActivityArea | ||
{ | ||
$activityArea = $this->findOneBy(['id' => $id]); | ||
|
||
if (null === $activityArea) { | ||
throw new ActivityAreaResourceNotFoundException(); | ||
} | ||
|
||
return $activityArea; | ||
} | ||
|
||
public function list(int $limit = 50, array $params = []): array | ||
{ | ||
return $this->repository->findBy( | ||
$params, | ||
['name' => 'ASC'], | ||
$limit | ||
); | ||
} | ||
|
||
public function remove(Uuid $id): void | ||
{ | ||
$activityArea = $this->findOneBy(['id' => $id]); | ||
|
||
if (null === $activityArea) { | ||
throw new ActivityAreaResourceNotFoundException(); | ||
} | ||
|
||
$this->repository->remove($activityArea); | ||
} | ||
|
||
private function findOneBy(array $array): ?ActivityArea | ||
{ | ||
return $this->repository->findOneBy($array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Service\Interface; | ||
|
||
use App\Entity\ActivityArea; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
interface ActivityAreaServiceInterface | ||
{ | ||
public function get(Uuid $id): ActivityArea; | ||
|
||
public function list(int $limit = 50): array; | ||
|
||
public function remove(Uuid $id): void; | ||
} |
Oops, something went wrong.