|
18 | 18 | use Symfony\Component\HttpFoundation\JsonResponse; |
19 | 19 | use Symfony\Component\HttpFoundation\Request; |
20 | 20 | use Symfony\Component\HttpFoundation\Response; |
21 | | -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
22 | 21 | use Symfony\Component\Routing\Attribute\Route; |
23 | 22 |
|
24 | 23 | /** |
@@ -106,7 +105,7 @@ public function getMessages(Request $request): JsonResponse |
106 | 105 |
|
107 | 106 | $filter = (new MessageFilter())->setOwner($authUer); |
108 | 107 |
|
109 | | - return new JsonResponse( |
| 108 | + return $this->json( |
110 | 109 | $this->paginatedProvider->getPaginatedList($request, $this->normalizer, Message::class, $filter), |
111 | 110 | Response::HTTP_OK |
112 | 111 | ); |
@@ -156,10 +155,10 @@ public function getMessage( |
156 | 155 | $this->requireAuthentication($request); |
157 | 156 |
|
158 | 157 | if (!$message) { |
159 | | - throw new NotFoundHttpException('Campaign not found.'); |
| 158 | + throw $this->createNotFoundException('Campaign not found.'); |
160 | 159 | } |
161 | 160 |
|
162 | | - return new JsonResponse($this->normalizer->normalize($message), Response::HTTP_OK); |
| 161 | + return $this->json($this->normalizer->normalize($message), Response::HTTP_OK); |
163 | 162 | } |
164 | 163 |
|
165 | 164 | #[Route('', name: 'create_message', methods: ['POST'])] |
@@ -221,7 +220,7 @@ public function createMessage(Request $request, MessageNormalizer $normalizer): |
221 | 220 | $createMessageRequest = $this->validator->validate($request, CreateMessageRequest::class); |
222 | 221 | $data = $this->messageManager->createMessage($createMessageRequest, $authUser); |
223 | 222 |
|
224 | | - return new JsonResponse($normalizer->normalize($data), Response::HTTP_CREATED); |
| 223 | + return $this->json($normalizer->normalize($data), Response::HTTP_CREATED); |
225 | 224 | } |
226 | 225 |
|
227 | 226 | #[Route('/{messageId}', name: 'update_campaign', methods: ['PUT'])] |
@@ -288,13 +287,13 @@ public function updateMessage( |
288 | 287 | $authUser = $this->requireAuthentication($request); |
289 | 288 |
|
290 | 289 | if (!$message) { |
291 | | - throw new NotFoundHttpException('Campaign not found.'); |
| 290 | + throw $this->createNotFoundException('Campaign not found.'); |
292 | 291 | } |
293 | 292 | /** @var UpdateMessageRequest $updateMessageRequest */ |
294 | 293 | $updateMessageRequest = $this->validator->validate($request, UpdateMessageRequest::class); |
295 | 294 | $data = $this->messageManager->updateMessage($updateMessageRequest, $message, $authUser); |
296 | 295 |
|
297 | | - return new JsonResponse($this->normalizer->normalize($data), Response::HTTP_OK); |
| 296 | + return $this->json($this->normalizer->normalize($data), Response::HTTP_OK); |
298 | 297 | } |
299 | 298 |
|
300 | 299 | #[Route('/{messageId}', name: 'delete_campaign', methods: ['DELETE'])] |
@@ -346,11 +345,11 @@ public function deleteMessage( |
346 | 345 | $this->requireAuthentication($request); |
347 | 346 |
|
348 | 347 | if (!$message) { |
349 | | - throw new NotFoundHttpException('Campaign not found.'); |
| 348 | + throw $this->createNotFoundException('Campaign not found.'); |
350 | 349 | } |
351 | 350 |
|
352 | 351 | $this->messageManager->delete($message); |
353 | 352 |
|
354 | | - return new JsonResponse(null, Response::HTTP_NO_CONTENT); |
| 353 | + return $this->json(null, Response::HTTP_NO_CONTENT); |
355 | 354 | } |
356 | 355 | } |
0 commit comments