88use OpenApi \Attributes as OA ;
99use PhpList \Core \Domain \Messaging \Model \Bounce ;
1010use PhpList \Core \Domain \Messaging \Repository \BounceRepository ;
11+ use PhpList \Core \Domain \Messaging \Repository \UserMessageBounceRepository ;
1112use PhpList \Core \Security \Authentication ;
1213use PhpList \RestBundle \Common \Controller \BaseController ;
1314use PhpList \RestBundle \Common \Service \Provider \PaginatedDataProvider ;
@@ -33,6 +34,7 @@ public function __construct(
3334 private readonly EntityManagerInterface $ entityManager ,
3435 private readonly BounceNormalizer $ normalizer ,
3536 private readonly PaginatedDataProvider $ paginatedProvider ,
37+ private readonly UserMessageBounceRepository $ userMessageBounceRepository
3638 ) {
3739 parent ::__construct ($ authentication , $ validator );
3840 }
@@ -158,4 +160,104 @@ public function delete(
158160
159161 return $ this ->json (null , Response::HTTP_NO_CONTENT );
160162 }
163+
164+ #[Route('/by/campaign ' , name: 'get_by_campaign ' , methods: ['GET ' ])]
165+ #[OA \Get(
166+ path: '/api/v2/bounces/by/campaign ' ,
167+ description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
168+ 'Returns a JSON list of bounce counts by campaign. ' ,
169+ summary: 'Gets a list of bounce counts by campaign. ' ,
170+ tags: ['bounces ' ],
171+ parameters: [
172+ new OA \Parameter (
173+ name: 'php-auth-pw ' ,
174+ description: 'Session key obtained from login ' ,
175+ in: 'header ' ,
176+ required: true ,
177+ schema: new OA \Schema (type: 'string ' )
178+ ),
179+ ],
180+ responses: [
181+ new OA \Response (
182+ response: 200 ,
183+ description: 'Success ' ,
184+ content: new OA \JsonContent (
185+ type: 'array ' ,
186+ items: new OA \Items (
187+ properties: [
188+ new OA \Property (property: 'message_id ' , type: 'integer ' , example: 1 ),
189+ new OA \Property (property: 'subject ' , type: 'string ' , example: 'System ' ),
190+ new OA \Property (property: 'total_bounces ' , type: 'integer ' , example: 3 ),
191+ ],
192+ type: 'object '
193+ )
194+ )
195+ ),
196+ new OA \Response (
197+ response: 403 ,
198+ description: 'Failure ' ,
199+ content: new OA \JsonContent (ref: '#/components/schemas/UnauthorizedResponse ' )
200+ )
201+ ]
202+ )]
203+ public function getBounceCountsByCampaign (Request $ request ): JsonResponse
204+ {
205+ $ authUser = $ this ->requireAuthentication ($ request );
206+
207+ return $ this ->json (
208+ data: $ this ->userMessageBounceRepository ->getCampaignBounceTotals ($ authUser ->getId ()),
209+ status: Response::HTTP_OK
210+ );
211+ }
212+
213+ #[Route('/by/subscriber ' , name: 'get_by_subscriber ' , methods: ['GET ' ])]
214+ #[OA \Get(
215+ path: '/api/v2/bounces/by/subscriber ' ,
216+ description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
217+ 'Returns a JSON list of bounce counts by subscriber. ' ,
218+ summary: 'Gets a list of bounce counts by subscriber. ' ,
219+ tags: ['bounces ' ],
220+ parameters: [
221+ new OA \Parameter (
222+ name: 'php-auth-pw ' ,
223+ description: 'Session key obtained from login ' ,
224+ in: 'header ' ,
225+ required: true ,
226+ schema: new OA \Schema (type: 'string ' )
227+ ),
228+ ],
229+ responses: [
230+ new OA \Response (
231+ response: 200 ,
232+ description: 'Success ' ,
233+ content: new OA \JsonContent (
234+ type: 'array ' ,
235+ items: new OA \Items (
236+ properties: [
237+ new OA \Property (property: 'subscriber_id ' , type: 'integer ' , example: 1 ),
238+ new OA \Property (property: 'email ' , type: 'string ' , example: 'example@email.com ' ),
239+ new OA \Property (property: 'confirmed ' , type: 'boolean ' , example: true ),
240+ new OA \Property (property: 'blacklisted ' , type: 'boolean ' , example: true ),
241+ new OA \Property (property: 'total_bounces ' , type: 'integer ' , example: 3 ),
242+ ],
243+ type: 'object '
244+ )
245+ )
246+ ),
247+ new OA \Response (
248+ response: 403 ,
249+ description: 'Failure ' ,
250+ content: new OA \JsonContent (ref: '#/components/schemas/UnauthorizedResponse ' )
251+ )
252+ ]
253+ )]
254+ public function getBounceCountsBySubscriber (Request $ request ): JsonResponse
255+ {
256+ $ authUser = $ this ->requireAuthentication ($ request );
257+
258+ return $ this ->json (
259+ data: $ this ->userMessageBounceRepository ->getListBounceTotals ($ authUser ->getId ()),
260+ status: Response::HTTP_OK
261+ );
262+ }
161263}
0 commit comments