Skip to content

Commit 0d367ef

Browse files
committed
ISSUE-345: template by id
1 parent 3e08262 commit 0d367ef

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/Controller/TemplateController.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace PhpList\RestBundle\Controller;
66

77
use OpenApi\Attributes as OA;
8+
use PhpList\Core\Domain\Model\Messaging\Template;
89
use PhpList\Core\Domain\Repository\Messaging\TemplateRepository;
910
use PhpList\Core\Security\Authentication;
1011
use PhpList\RestBundle\Controller\Traits\AuthenticationTrait;
1112
use PhpList\RestBundle\Serializer\TemplateNormalizer;
13+
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
1214
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1315
use Symfony\Component\HttpFoundation\JsonResponse;
1416
use Symfony\Component\HttpFoundation\Request;
@@ -82,4 +84,50 @@ public function getTemplates(Request $request): JsonResponse
8284

8385
return new JsonResponse($normalized, Response::HTTP_OK);
8486
}
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+
}
85133
}

0 commit comments

Comments
 (0)