Skip to content

Commit ddaf6bd

Browse files
committed
Add more data to dashboard_statistics
1 parent 97d5bbd commit ddaf6bd

3 files changed

Lines changed: 129 additions & 64 deletions

File tree

src/Statistics/Controller/AnalyticsController.php

Lines changed: 102 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -381,57 +381,115 @@ public function getTopLocalParts(Request $request): JsonResponse
381381
content: new OA\JsonContent(
382382
properties: [
383383
new OA\Property(
384-
property: 'total_subscribers',
384+
property: 'summary_statistics',
385385
properties: [
386-
new OA\Property(property: 'value', type: 'integer', example: 48294),
387386
new OA\Property(
388-
property: 'change_vs_last_month',
389-
type: 'number',
390-
format: 'float',
391-
example: 12.5
387+
property: 'total_subscribers',
388+
properties: [
389+
new OA\Property(property: 'value', type: 'integer', example: 48294),
390+
new OA\Property(
391+
property: 'change_vs_last_month',
392+
type: 'number',
393+
format: 'float',
394+
example: 12.5
395+
),
396+
],
397+
type: 'object'
392398
),
393-
],
394-
type: 'object'
395-
),
396-
new OA\Property(
397-
property: 'active_campaigns',
398-
properties: [
399-
new OA\Property(property: 'value', type: 'integer', example: 12),
400399
new OA\Property(
401-
property: 'change_vs_last_month',
402-
type: 'number',
403-
format: 'float',
404-
example: 0
400+
property: 'active_campaigns',
401+
properties: [
402+
new OA\Property(property: 'value', type: 'integer', example: 12),
403+
new OA\Property(
404+
property: 'change_vs_last_month',
405+
type: 'number',
406+
format: 'float',
407+
example: 0
408+
),
409+
],
410+
type: 'object'
405411
),
406-
],
407-
type: 'object'
408-
),
409-
new OA\Property(
410-
property: 'open_rate',
411-
properties: [
412-
new OA\Property(property: 'value', type: 'number', format: 'float', example: 12),
413412
new OA\Property(
414-
property: 'change_vs_last_month',
415-
type: 'number',
416-
format: 'float',
417-
example: 0
413+
property: 'open_rate',
414+
properties: [
415+
new OA\Property(
416+
property: 'value',
417+
type: 'number',
418+
format: 'float',
419+
example: 12
420+
),
421+
new OA\Property(
422+
property: 'change_vs_last_month',
423+
type: 'number',
424+
format: 'float',
425+
example: 0
426+
),
427+
],
428+
type: 'object'
418429
),
419-
],
420-
type: 'object'
421-
),
422-
new OA\Property(
423-
property: 'bounce_rate',
424-
properties: [
425-
new OA\Property(property: 'value', type: 'number', format: 'float', example: 12),
426430
new OA\Property(
427-
property: 'change_vs_last_month',
428-
type: 'number',
429-
format: 'float',
430-
example: 0
431+
property: 'bounce_rate',
432+
properties: [
433+
new OA\Property(
434+
property: 'value',
435+
type: 'number',
436+
format: 'float',
437+
example: 12
438+
),
439+
new OA\Property(
440+
property: 'change_vs_last_month',
441+
type: 'number',
442+
format: 'float',
443+
example: 0
444+
),
445+
],
446+
type: 'object'
431447
),
432448
],
433449
type: 'object'
434450
),
451+
new OA\Property(
452+
property: 'recent_campaigns',
453+
type: 'array',
454+
items: new OA\Items(
455+
properties: [
456+
new OA\Property(property: 'name', type: 'string', example: 'March Newsletter'),
457+
new OA\Property(
458+
property: 'status',
459+
type: 'string',
460+
example: 'sent',
461+
nullable: true
462+
),
463+
new OA\Property(
464+
property: 'date',
465+
type: 'string',
466+
format: 'date',
467+
example: '2026-03-15',
468+
nullable: true
469+
),
470+
new OA\Property(property: 'open_rate', type: 'string', example: '42.50%'),
471+
new OA\Property(property: 'click_rate', type: 'string', example: '8.10%'),
472+
],
473+
type: 'object'
474+
)
475+
),
476+
new OA\Property(
477+
property: 'campaign_performance',
478+
type: 'array',
479+
items: new OA\Items(
480+
properties: [
481+
new OA\Property(
482+
property: 'date',
483+
type: 'string',
484+
format: 'date',
485+
example: '2026-03-19'
486+
),
487+
new OA\Property(property: 'opens', type: 'integer', example: 234),
488+
new OA\Property(property: 'clicks', type: 'integer', example: 57),
489+
],
490+
type: 'object'
491+
)
492+
),
435493
],
436494
type: 'object'
437495
)
@@ -450,7 +508,11 @@ public function getDashboardStatistics(Request $request): JsonResponse
450508
throw $this->createAccessDeniedException('You are not allowed to access statistics.');
451509
}
452510

453-
$response = $this->analyticsService->getSummaryStatistics();
511+
$response = [
512+
'summary_statistics' => $this->analyticsService->getSummaryStatistics(),
513+
'recent_campaigns' => $this->analyticsService->getRecentCampaigns(),
514+
'campaign_performance' => $this->analyticsService->getCampaignPerformance(),
515+
];
454516

455517
return $this->json($response, Response::HTTP_OK);
456518
}

tests/Integration/Statistics/Controller/AnalyticsControllerTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,16 @@ public function testGetDashboardStatisticsWithValidSessionReturnsCardsData(): vo
275275
$response = $this->getDecodedJsonResponseContent();
276276

277277
self::assertIsArray($response);
278-
self::assertArrayHasKey('total_subscribers', $response);
279-
self::assertArrayHasKey('active_campaigns', $response);
280-
self::assertArrayHasKey('open_rate', $response);
281-
self::assertArrayHasKey('bounce_rate', $response);
278+
self::assertArrayHasKey('summary_statistics', $response);
279+
self::assertArrayHasKey('recent_campaigns', $response);
280+
self::assertArrayHasKey('campaign_performance', $response);
282281

283282
foreach (['total_subscribers', 'active_campaigns', 'open_rate', 'bounce_rate'] as $metric) {
284-
self::assertIsArray($response[$metric]);
285-
self::assertArrayHasKey('value', $response[$metric]);
286-
self::assertArrayHasKey('change_vs_last_month', $response[$metric]);
287-
self::assertIsNumeric($response[$metric]['value']);
288-
self::assertIsNumeric($response[$metric]['change_vs_last_month']);
283+
self::assertIsArray($response['summary_statistics'][$metric]);
284+
self::assertArrayHasKey('value', $response['summary_statistics'][$metric]);
285+
self::assertArrayHasKey('change_vs_last_month', $response['summary_statistics'][$metric]);
286+
self::assertIsNumeric($response['summary_statistics'][$metric]['value']);
287+
self::assertIsNumeric($response['summary_statistics'][$metric]['change_vs_last_month']);
289288
}
290289
}
291290
}

tests/Unit/Statistics/Controller/AnalyticsControllerTest.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -507,22 +507,26 @@ public function testGetDashboardStatisticsReturnsJsonResponse(): void
507507

508508
self::assertEquals(Response::HTTP_OK, $response->getStatusCode());
509509
self::assertEquals([
510-
'total_subscribers' => [
511-
'value' => 80,
512-
'change_vs_last_month' => 10.5,
513-
],
514-
'active_campaigns' => [
515-
'value' => 12,
516-
'change_vs_last_month' => -4.25,
517-
],
518-
'open_rate' => [
519-
'value' => 40.0,
520-
'change_vs_last_month' => 3.3,
521-
],
522-
'bounce_rate' => [
523-
'value' => 6.67,
524-
'change_vs_last_month' => -1.1,
510+
'summary_statistics' => [
511+
'total_subscribers' => [
512+
'value' => 80,
513+
'change_vs_last_month' => 10.5,
514+
],
515+
'active_campaigns' => [
516+
'value' => 12,
517+
'change_vs_last_month' => -4.25,
518+
],
519+
'open_rate' => [
520+
'value' => 40.0,
521+
'change_vs_last_month' => 3.3,
522+
],
523+
'bounce_rate' => [
524+
'value' => 6.67,
525+
'change_vs_last_month' => -1.1,
526+
],
525527
],
528+
'recent_campaigns' => [],
529+
'campaign_performance' => [],
526530
], json_decode($response->getContent(), true));
527531
}
528532
}

0 commit comments

Comments
 (0)