|
9 | 9 | use PhpList\Core\Security\Authentication;
|
10 | 10 | use PhpList\RestBundle\Controller\Traits\AuthenticationTrait;
|
11 | 11 | use PhpList\RestBundle\Entity\Request\CreateMessageRequest;
|
| 12 | +use PhpList\RestBundle\Entity\Request\UpdateMessageRequest; |
12 | 13 | use PhpList\RestBundle\Serializer\MessageNormalizer;
|
13 | 14 | use PhpList\RestBundle\Service\Manager\MessageManager;
|
14 | 15 | use PhpList\RestBundle\Service\Provider\MessageProvider;
|
|
19 | 20 | use Symfony\Component\HttpFoundation\Request;
|
20 | 21 | use Symfony\Component\HttpFoundation\Response;
|
21 | 22 | use Symfony\Component\Routing\Attribute\Route;
|
| 23 | +use Symfony\Component\Serializer\SerializerInterface; |
22 | 24 |
|
23 | 25 | /**
|
24 | 26 | * This controller provides REST API to manage campaigns.
|
@@ -151,78 +153,11 @@ public function getMessage(
|
151 | 153 | content: new OA\JsonContent(
|
152 | 154 | properties: [
|
153 | 155 | new OA\Property(property: 'template_id', type: 'integer', example: 1),
|
154 |
| - new OA\Property( |
155 |
| - property: 'message_content', |
156 |
| - properties: [ |
157 |
| - new OA\Property(property: 'subject', type: 'string', example: 'Campaign Subject'), |
158 |
| - new OA\Property(property: 'text', type: 'string', example: 'Full text content'), |
159 |
| - new OA\Property(property: 'text_message', type: 'string', example: 'Short text message'), |
160 |
| - new OA\Property(property: 'footer', type: 'string', example: 'Unsubscribe link here'), |
161 |
| - ], |
162 |
| - type: 'object' |
163 |
| - ), |
164 |
| - new OA\Property( |
165 |
| - property: 'message_format', |
166 |
| - properties: [ |
167 |
| - new OA\Property(property: 'html_formated', type: 'boolean', example: true), |
168 |
| - new OA\Property( |
169 |
| - property: 'send_format', |
170 |
| - type: 'string', |
171 |
| - enum: ['html', 'text', 'invite'], |
172 |
| - example: 'html' |
173 |
| - ), |
174 |
| - new OA\Property( |
175 |
| - property: 'format_options', |
176 |
| - type: 'array', |
177 |
| - items: new OA\Items(type: 'string', enum: ['text', 'html', 'pdf']), |
178 |
| - example: ['html'] |
179 |
| - ), |
180 |
| - ], |
181 |
| - type: 'object' |
182 |
| - ), |
183 |
| - new OA\Property( |
184 |
| - property: 'message_metadata', |
185 |
| - properties: [ |
186 |
| - new OA\Property(property: 'status', type: 'string', example: 'draft'), |
187 |
| - ], |
188 |
| - type: 'object' |
189 |
| - ), |
190 |
| - new OA\Property( |
191 |
| - property: 'message_schedule', |
192 |
| - properties: [ |
193 |
| - new OA\Property( |
194 |
| - property: 'embargo', |
195 |
| - type: 'string', |
196 |
| - format: 'date-time', |
197 |
| - example: '2025-04-17 09:00:00' |
198 |
| - ), |
199 |
| - new OA\Property(property: 'repeat_interval', type: 'string', example: '24 hours'), |
200 |
| - new OA\Property( |
201 |
| - property: 'repeat_until', |
202 |
| - type: 'string', |
203 |
| - format: 'date-time', |
204 |
| - example: '2025-04-30T00:00:00+04:00' |
205 |
| - ), |
206 |
| - new OA\Property(property: 'requeue_interval', type: 'string', example: '12 hours'), |
207 |
| - new OA\Property( |
208 |
| - property: 'requeue_until', |
209 |
| - type: 'string', |
210 |
| - format: 'date-time', |
211 |
| - example: '2025-04-20T00:00:00+04:00' |
212 |
| - ), |
213 |
| - ], |
214 |
| - type: 'object' |
215 |
| - ), |
216 |
| - new OA\Property( |
217 |
| - property: 'message_options', |
218 |
| - properties: [ |
219 |
| - new OA\ Property(property: 'from_field', type: 'string', example: '[email protected]'), |
220 |
| - new OA\ Property(property: 'to_field', type: 'string', example: '[email protected]'), |
221 |
| - new OA\ Property(property: 'reply_to', type: 'string', example: '[email protected]'), |
222 |
| - new OA\Property(property: 'user_selection', type: 'string', example: 'all-active-users'), |
223 |
| - ], |
224 |
| - type: 'object' |
225 |
| - ), |
| 156 | + new OA\Property(property: 'message_content', ref: '#/components/schemas/MessageContentRequest'), |
| 157 | + new OA\Property(property: 'message_format', ref: '#/components/schemas/MessageFormatRequest'), |
| 158 | + new OA\Property(property: 'message_metadata', ref: '#/components/schemas/MessageMetadataRequest'), |
| 159 | + new OA\Property(property: 'message_schedule', ref: '#/components/schemas/MessageScheduleRequest'), |
| 160 | + new OA\Property(property: 'message_options', ref: '#/components/schemas/MessageOptionsRequest'), |
226 | 161 | ],
|
227 | 162 | type: 'object'
|
228 | 163 | )
|
@@ -267,4 +202,80 @@ public function createMessage(Request $request, MessageNormalizer $normalizer):
|
267 | 202 |
|
268 | 203 | return new JsonResponse($normalizer->normalize($data), Response::HTTP_CREATED);
|
269 | 204 | }
|
| 205 | + |
| 206 | + #[Route('/{messageId}', name: 'update_campaign', methods: ['PUT'])] |
| 207 | + #[OA\Put( |
| 208 | + path: '/campaigns/{messageId}', |
| 209 | + description: 'Updates campaign/message by id.', |
| 210 | + summary: 'Update campaign by id.', |
| 211 | + requestBody: new OA\RequestBody( |
| 212 | + description: 'Update message.', |
| 213 | + required: true, |
| 214 | + content: new OA\JsonContent( |
| 215 | + properties: [ |
| 216 | + new OA\Property(property: 'template_id', type: 'integer', example: 1), |
| 217 | + new OA\Property(property: 'message_content', ref: '#/components/schemas/MessageContentRequest'), |
| 218 | + new OA\Property(property: 'message_format', ref: '#/components/schemas/MessageFormatRequest'), |
| 219 | + new OA\Property(property: 'message_schedule', ref: '#/components/schemas/MessageScheduleRequest'), |
| 220 | + new OA\Property(property: 'message_options', ref: '#/components/schemas/MessageOptionsRequest'), |
| 221 | + ], |
| 222 | + type: 'object' |
| 223 | + ) |
| 224 | + ), |
| 225 | + tags: ['campaigns'], |
| 226 | + parameters: [ |
| 227 | + new OA\Parameter( |
| 228 | + name: 'session', |
| 229 | + description: 'Session ID obtained from authentication', |
| 230 | + in: 'header', |
| 231 | + required: true, |
| 232 | + schema: new OA\Schema( |
| 233 | + type: 'string' |
| 234 | + ) |
| 235 | + ), |
| 236 | + new OA\Parameter( |
| 237 | + name: 'messageId', |
| 238 | + description: 'message ID', |
| 239 | + in: 'path', |
| 240 | + required: true, |
| 241 | + schema: new OA\Schema(type: 'string') |
| 242 | + ) |
| 243 | + ], |
| 244 | + responses: [ |
| 245 | + new OA\Response( |
| 246 | + response: 200, |
| 247 | + description: 'Success', |
| 248 | + content: new OA\JsonContent(ref: '#/components/schemas/Message') |
| 249 | + ), |
| 250 | + new OA\Response( |
| 251 | + response: 403, |
| 252 | + description: 'Failure', |
| 253 | + content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') |
| 254 | + ), |
| 255 | + new OA\Response( |
| 256 | + response: 422, |
| 257 | + description: 'Failure', |
| 258 | + content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse') |
| 259 | + ), |
| 260 | + ] |
| 261 | + )] |
| 262 | + public function updateMessage( |
| 263 | + Request $request, |
| 264 | + #[MapEntity(mapping: ['messageId' => 'id'])] Message $message, |
| 265 | + SerializerInterface $serializer, |
| 266 | + ): JsonResponse { |
| 267 | + $authUser = $this->requireAuthentication($request); |
| 268 | + |
| 269 | + /** @return UpdateMessageRequest $updateMessageRequest */ |
| 270 | + $updateMessageRequest = $serializer->deserialize($request->getContent(), UpdateMessageRequest::class, 'json'); |
| 271 | + $updateMessageRequest->subscriberId = $message->getId(); |
| 272 | + $this->validator->validateDto($updateMessageRequest); |
| 273 | + |
| 274 | + return new JsonResponse( |
| 275 | + $this->normalizer->normalize( |
| 276 | + $this->messageManager->updateMessage($updateMessageRequest, $message, $authUser) |
| 277 | + ), |
| 278 | + Response::HTTP_OK |
| 279 | + ); |
| 280 | + } |
270 | 281 | }
|
0 commit comments