|
5 | 5 | namespace PhpList\RestBundle\Controller;
|
6 | 6 |
|
7 | 7 | use OpenApi\Attributes as OA;
|
| 8 | +use PhpList\Core\Domain\Model\Messaging\Template; |
8 | 9 | use PhpList\Core\Domain\Repository\Messaging\TemplateRepository;
|
9 | 10 | use PhpList\Core\Security\Authentication;
|
10 | 11 | use PhpList\RestBundle\Controller\Traits\AuthenticationTrait;
|
11 | 12 | use PhpList\RestBundle\Serializer\TemplateNormalizer;
|
| 13 | +use Symfony\Bridge\Doctrine\Attribute\MapEntity; |
12 | 14 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
13 | 15 | use Symfony\Component\HttpFoundation\JsonResponse;
|
14 | 16 | use Symfony\Component\HttpFoundation\Request;
|
@@ -82,4 +84,50 @@ public function getTemplates(Request $request): JsonResponse
|
82 | 84 |
|
83 | 85 | return new JsonResponse($normalized, Response::HTTP_OK);
|
84 | 86 | }
|
| 87 | + |
| 88 | + #[Route('/{templateId}', name: 'get_template', methods: ['GET'])] |
| 89 | + #[OA\Get( |
| 90 | + path: '/templates/{templateId}', |
| 91 | + description: 'Returns template by id.', |
| 92 | + summary: 'Gets a templateI by id.', |
| 93 | + tags: ['templates'], |
| 94 | + parameters: [ |
| 95 | + new OA\Parameter( |
| 96 | + name: 'session', |
| 97 | + description: 'Session ID obtained from authentication', |
| 98 | + in: 'header', |
| 99 | + required: true, |
| 100 | + schema: new OA\Schema( |
| 101 | + type: 'string' |
| 102 | + ) |
| 103 | + ), |
| 104 | + new OA\Parameter( |
| 105 | + name: 'templateId', |
| 106 | + description: 'template ID', |
| 107 | + in: 'path', |
| 108 | + required: true, |
| 109 | + schema: new OA\Schema(type: 'string') |
| 110 | + ) |
| 111 | + ], |
| 112 | + responses: [ |
| 113 | + new OA\Response( |
| 114 | + response: 200, |
| 115 | + description: 'Success', |
| 116 | + content: new OA\JsonContent(ref: '#/components/schemas/Template') |
| 117 | + ), |
| 118 | + new OA\Response( |
| 119 | + response: 403, |
| 120 | + description: 'Failure', |
| 121 | + content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') |
| 122 | + ) |
| 123 | + ] |
| 124 | + )] |
| 125 | + public function getTemplate( |
| 126 | + Request $request, |
| 127 | + #[MapEntity(mapping: ['templateId' => 'id'])] Template $template |
| 128 | + ): JsonResponse { |
| 129 | + $this->requireAuthentication($request); |
| 130 | + |
| 131 | + return new JsonResponse($this->normalizer->normalize($template), Response::HTTP_OK); |
| 132 | + } |
85 | 133 | }
|
0 commit comments