1818use Symfony \Component \HttpFoundation \JsonResponse ;
1919use Symfony \Component \HttpFoundation \Request ;
2020use Symfony \Component \HttpFoundation \Response ;
21+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
2122use Symfony \Component \Routing \Attribute \Route ;
2223
2324/**
@@ -78,16 +79,25 @@ public function __construct(
7879 response: 403 ,
7980 description: 'Failure ' ,
8081 content: new OA \JsonContent (ref: '#/components/schemas/UnauthorizedResponse ' )
82+ ),
83+ new OA \Response (
84+ response: 404 ,
85+ description: 'Failure ' ,
86+ content: new OA \JsonContent (ref: '#/components/schemas/NotFoundErrorResponse ' )
8187 )
8288 ]
8389 )]
8490 public function getListMembers (
8591 Request $ request ,
86- #[MapEntity(mapping: [ ' listId ' => ' id ' ])] SubscriberList $ list ,
87- SubscriberNormalizer $ normalizer
92+ SubscriberNormalizer $ normalizer ,
93+ #[MapEntity(mapping: [ ' listId ' => ' id ' ])] ? SubscriberList $ list = null ,
8894 ): JsonResponse {
8995 $ this ->requireAuthentication ($ request );
9096
97+ if (!$ list ) {
98+ throw new NotFoundHttpException ('Subscriber list not found. ' );
99+ }
100+
91101 $ subscribers = $ this ->subscriptionManager ->getSubscriberListMembers ($ list );
92102 $ normalized = array_map (function ($ item ) use ($ normalizer ) {
93103 return $ normalizer ->normalize ($ item );
@@ -142,10 +152,14 @@ public function getListMembers(
142152 )]
143153 public function getSubscribersCount (
144154 Request $ request ,
145- #[MapEntity(mapping: ['listId ' => 'id ' ])] SubscriberList $ list
155+ #[MapEntity(mapping: ['listId ' => 'id ' ])] ? SubscriberList $ list = null ,
146156 ): JsonResponse {
147157 $ this ->requireAuthentication ($ request );
148158
159+ if (!$ list ) {
160+ throw new NotFoundHttpException ('Subscriber list not found. ' );
161+ }
162+
149163 return new JsonResponse (['subscribers_count ' => count ($ list ->getSubscribers ())], Response::HTTP_OK );
150164 }
151165
@@ -195,15 +209,20 @@ public function getSubscribersCount(
195209 items: new OA \Items (ref: '#/components/schemas/Subscription ' )
196210 )
197211 ),
212+ new OA \Response (
213+ response: 400 ,
214+ description: 'Failure ' ,
215+ content: new OA \JsonContent (ref: '#/components/schemas/BadRequestResponse ' )
216+ ),
198217 new OA \Response (
199218 response: 403 ,
200219 description: 'Failure ' ,
201220 content: new OA \JsonContent (ref: '#/components/schemas/UnauthorizedResponse ' )
202221 ),
203222 new OA \Response (
204- response: 400 ,
223+ response: 404 ,
205224 description: 'Failure ' ,
206- content: new OA \JsonContent (ref: '#/components/schemas/BadRequestResponse ' )
225+ content: new OA \JsonContent (ref: '#/components/schemas/NotFoundErrorResponse ' )
207226 ),
208227 new OA \Response (
209228 response: 409 ,
@@ -219,11 +238,15 @@ public function getSubscribersCount(
219238 )]
220239 public function createSubscription (
221240 Request $ request ,
222- #[MapEntity(mapping: [ ' listId ' => ' id ' ])] SubscriberList $ list ,
223- SubscriptionNormalizer $ serializer
241+ SubscriptionNormalizer $ serializer ,
242+ #[MapEntity(mapping: [ ' listId ' => ' id ' ])] ? SubscriberList $ list = null ,
224243 ): JsonResponse {
225244 $ this ->requireAuthentication ($ request );
226245
246+ if (!$ list ) {
247+ throw new NotFoundHttpException ('Subscriber list not found. ' );
248+ }
249+
227250 /** @var SubscriptionRequest $subscriptionRequest */
228251 $ subscriptionRequest = $ this ->validator ->validate ($ request , SubscriptionRequest::class);
229252 $ subscriptions = $ this ->subscriptionManager ->createSubscriptions ($ list , $ subscriptionRequest ->emails );
@@ -276,15 +299,19 @@ public function createSubscription(
276299 ),
277300 new OA \Response (
278301 response: 404 ,
279- description: 'Subscriber or subscription not found. '
302+ description: 'Failure ' ,
303+ content: new OA \JsonContent (ref: '#/components/schemas/NotFoundErrorResponse ' )
280304 )
281305 ]
282306 )]
283307 public function deleteSubscriptions (
284308 Request $ request ,
285- #[MapEntity(mapping: ['listId ' => 'id ' ])] SubscriberList $ list ,
309+ #[MapEntity(mapping: ['listId ' => 'id ' ])] ? SubscriberList $ list = null ,
286310 ): JsonResponse {
287311 $ this ->requireAuthentication ($ request );
312+ if (!$ list ) {
313+ throw new NotFoundHttpException ('Subscriber list not found. ' );
314+ }
288315 $ subscriptionRequest = new SubscriptionRequest ();
289316 $ subscriptionRequest ->emails = $ request ->query ->all ('emails ' );
290317
0 commit comments