-
Notifications
You must be signed in to change notification settings - Fork 13
Version: dev #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Version: dev #168
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,286 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| declare(strict_types=1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace PhpList\RestBundle\Messaging\Controller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Doctrine\ORM\EntityManagerInterface; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use OpenApi\Attributes as OA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\Core\Domain\Messaging\Message\SyncCampaignProcessorMessage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\Core\Domain\Messaging\Model\Message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\Core\Domain\Messaging\Model\Message\MessageStatus; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\Core\Domain\Messaging\Service\Manager\MessageManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\Core\Security\Authentication; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\RestBundle\Common\Controller\BaseController; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\RestBundle\Common\Validator\RequestValidator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\RestBundle\Messaging\Request\Message\MessageMetadataRequest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\RestBundle\Messaging\Request\ResendMessageToListsRequest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\RestBundle\Messaging\Serializer\MessageNormalizer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use PhpList\RestBundle\Messaging\Service\CampaignService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Symfony\Component\HttpFoundation\JsonResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Symfony\Component\HttpFoundation\Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Symfony\Component\HttpFoundation\Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Symfony\Component\Messenger\MessageBusInterface; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Symfony\Component\Routing\Attribute\Route; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * This controller provides REST API to manage campaign actions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @author Tatevik Grigoryan <tatevik@phplist.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[Route('/campaigns', name: 'campaign_')] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class CampaignActionController extends BaseController | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function __construct( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Authentication $authentication, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RequestValidator $validator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly CampaignService $campaignService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly MessageBusInterface $messageBus, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly EntityManagerInterface $entityManager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly MessageManager $messageManager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly MessageNormalizer $messageNormalizer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parent::__construct($authentication, $validator); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[Route('/{messageId}/copy', name: 'copy_campaign', requirements: ['messageId' => '\d+'], methods: ['POST'])] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[OA\Post( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: '/api/v2/campaigns/{messageId}/copy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Copies campaign/message by id into a draft message.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: 'Copies campaign/message by id.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['campaigns'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'php-auth-pw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Session key obtained from login', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'header', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'messageId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'message ID', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'path', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responses: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 201, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Success', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/Message') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 403, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function copyMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Request $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[MapEntity(mapping: ['messageId' => 'id'])] ?Message $message = null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): JsonResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $authUser = $this->requireAuthentication($request); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($message === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw $this->createNotFoundException('Campaign not found.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $message = $this->messageManager->copyAsDraftMessage($message, $authUser); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->entityManager->flush(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->json($this->campaignService->getMessage($message), Response::HTTP_CREATED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[Route('/{messageId}/status', name: 'update_status', requirements: ['messageId' => '\d+'], methods: ['PATCH'])] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[OA\Patch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: '/api/v2/campaigns/{messageId}/status', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Updates campaign/message status by id.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: 'Update campaign status by id.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody: new OA\RequestBody( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Update message status.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/MessageMetadataRequest') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['campaigns'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'php-auth-pw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Session key obtained from login', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'header', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'string' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'messageId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'message ID', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'path', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responses: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Success', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/Message') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 403, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 404, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 422, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function updateMessageStatus( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Request $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[MapEntity(mapping: ['messageId' => 'id'])] ?Message $message = null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): JsonResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->requireAuthentication($request); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($message === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw $this->createNotFoundException('Message not found.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** @var MessageMetadataRequest $messageMetadataRequest */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $messageMetadataRequest = $this->validator->validate($request, MessageMetadataRequest::class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $message = $this->messageManager->updateStatus( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MessageStatus::from($messageMetadataRequest->status), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->entityManager->flush(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->json($this->messageNormalizer->normalize($message), Response::HTTP_OK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[Route('/{messageId}/send', name: 'send_campaign', requirements: ['messageId' => '\d+'], methods: ['POST'])] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[OA\Post( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: '/api/v2/campaigns/{messageId}/send', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Processes/sends campaign/message by id.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: 'Processes/sends campaign/message by id.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['campaigns'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'php-auth-pw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Session key obtained from login', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'header', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'messageId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'message ID', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'path', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responses: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Success', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/Message') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 403, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 404, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+195
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing 404 response in OpenAPI documentation The 📝 Add 404 response to OpenAPI responses: [
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/Message')
),
new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
- )
+ ),
+ new OA\Response(
+ response: 404,
+ description: 'Campaign not found',
+ content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
+ )
]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function sendMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Request $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[MapEntity(mapping: ['messageId' => 'id'])] ?Message $message = null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): JsonResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->requireAuthentication($request); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($message === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw $this->createNotFoundException('Campaign not found.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->messageBus->dispatch(new SyncCampaignProcessorMessage($message->getId())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->json($this->campaignService->getMessage($message), Response::HTTP_OK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[Route('/{messageId}/resend', name: 'resend_campaign', requirements: ['messageId' => '\d+'], methods: ['POST'])] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[OA\Post( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: '/api/v2/campaigns/{messageId}/resend', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Processes/sends campaign/message by id to specified mailing lists.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: 'Processes/sends campaign/message by id to lists.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody: new OA\RequestBody( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'List ids to send this campaign to.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/ResendMessageToListsRequest') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['campaigns'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'php-auth-pw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Session key obtained from login', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'header', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Parameter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'messageId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'message ID', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in: 'path', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: new OA\Schema(type: 'string') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| responses: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Success', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/Message') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new OA\Response( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: 403, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Failure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+255
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing 404 response in OpenAPI documentation. The endpoint throws not-found (line 272) when the campaign doesn't exist, but this isn't documented in the responses. Should mirror 📝 Proposed fix new OA\Response(
response: 403,
description: 'Failure',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
- )
+ ),
+ new OA\Response(
+ response: 404,
+ description: 'Campaign not found',
+ content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
+ )
]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function resendMessageToLists( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Request $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[MapEntity(mapping: ['messageId' => 'id'])] ?Message $message = null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): JsonResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->requireAuthentication($request); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($message === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw $this->createNotFoundException('Campaign not found.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** @var ResendMessageToListsRequest $resendToListsRequest */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $resendToListsRequest = $this->validator->validate($request, ResendMessageToListsRequest::class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->messageBus->dispatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new SyncCampaignProcessorMessage($message->getId(), $resendToListsRequest->listIds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->json($this->campaignService->getMessage($message), Response::HTTP_OK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: phpList/rest-api
Length of output: 972
🏁 Script executed:
Repository: phpList/rest-api
Length of output: 1178
🏁 Script executed:
Repository: phpList/rest-api
Length of output: 42
🏁 Script executed:
Repository: phpList/rest-api
Length of output: 2778
🏁 Script executed:
Repository: phpList/rest-api
Length of output: 566
🏁 Script executed:
Repository: phpList/rest-api
Length of output: 348
Add
Assert\Choicevalidation to thestatusfield inMessageMetadataRequestThe
statusfield currently only has#[Assert\NotBlank]validation. Without anAssert\Choiceconstraint (like used inMessageFormatRequest), invalid enum backing values slip through validation and causeMessageStatus::from()to throw an unhandledValueError, returning a 500 instead of a proper 400/422 response.Add constraint:
#[Assert\Choice(['draft', 'sent', ...])]with valid enum backing values.🤖 Prompt for AI Agents