|
18 | 18 | use Symfony\Component\HttpFoundation\Request; |
19 | 19 | use Symfony\Component\HttpFoundation\Response; |
20 | 20 | use Symfony\Component\Routing\Attribute\Route; |
| 21 | +use Throwable; |
21 | 22 |
|
22 | 23 | /** |
23 | 24 | * This controller provides REST API to access analytics data. |
@@ -356,4 +357,81 @@ public function getTopLocalParts(Request $request): JsonResponse |
356 | 357 |
|
357 | 358 | return $this->json($normalizedData, Response::HTTP_OK); |
358 | 359 | } |
| 360 | + |
| 361 | + #[Route('/dashboard', name: 'dashboard_statistics', methods: ['GET'])] |
| 362 | + #[OA\Get( |
| 363 | + path: '/api/v2/analytics/dashboard', |
| 364 | + description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . |
| 365 | + 'Returns dashboard cards with aggregate analytics metrics.', |
| 366 | + summary: 'Gets dashboard analytics statistics.', |
| 367 | + tags: ['analytics'], |
| 368 | + parameters: [ |
| 369 | + new OA\Parameter( |
| 370 | + name: 'php-auth-pw', |
| 371 | + description: 'Session key obtained from login', |
| 372 | + in: 'header', |
| 373 | + required: true, |
| 374 | + schema: new OA\Schema(type: 'string') |
| 375 | + ) |
| 376 | + ], |
| 377 | + responses: [ |
| 378 | + new OA\Response( |
| 379 | + response: 200, |
| 380 | + description: 'Success', |
| 381 | + content: new OA\JsonContent( |
| 382 | + properties: [ |
| 383 | + new OA\Property( |
| 384 | + property: 'total_subscribers', |
| 385 | + properties: [ |
| 386 | + new OA\Property(property: 'value', type: 'integer', example: 48294), |
| 387 | + new OA\Property(property: 'change_vs_last_month', type: 'number', format: 'float', example: 12.5), |
| 388 | + ], |
| 389 | + type: 'object' |
| 390 | + ), |
| 391 | + new OA\Property( |
| 392 | + property: 'active_campaigns', |
| 393 | + properties: [ |
| 394 | + new OA\Property(property: 'value', type: 'integer', example: 12), |
| 395 | + new OA\Property(property: 'change_vs_last_month', type: 'number', format: 'float', example: 0), |
| 396 | + ], |
| 397 | + type: 'object' |
| 398 | + ), |
| 399 | + new OA\Property( |
| 400 | + property: 'open_rate', |
| 401 | + properties: [ |
| 402 | + new OA\Property(property: 'value', type: 'number', format: 'float', example: 12), |
| 403 | + new OA\Property(property: 'change_vs_last_month', type: 'number', format: 'float', example: 0), |
| 404 | + ], |
| 405 | + type: 'object' |
| 406 | + ), |
| 407 | + new OA\Property( |
| 408 | + property: 'bounce_rate', |
| 409 | + properties: [ |
| 410 | + new OA\Property(property: 'value', type: 'number', format: 'float', example: 12), |
| 411 | + new OA\Property(property: 'change_vs_last_month', type: 'number', format: 'float', example: 0), |
| 412 | + ], |
| 413 | + type: 'object' |
| 414 | + ), |
| 415 | + ], |
| 416 | + type: 'object' |
| 417 | + ) |
| 418 | + ), |
| 419 | + new OA\Response( |
| 420 | + response: 403, |
| 421 | + description: 'Unauthorized', |
| 422 | + content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') |
| 423 | + ) |
| 424 | + ] |
| 425 | + )] |
| 426 | + public function getDashboardStatistics(Request $request): JsonResponse |
| 427 | + { |
| 428 | + $authUser = $this->requireAuthentication($request); |
| 429 | + if (!$authUser->getPrivileges()->has(PrivilegeFlag::Statistics)) { |
| 430 | + throw $this->createAccessDeniedException('You are not allowed to access statistics.'); |
| 431 | + } |
| 432 | + |
| 433 | + $response = $this->analyticsService->getSummaryStatistics(); |
| 434 | + |
| 435 | + return $this->json($response, Response::HTTP_OK); |
| 436 | + } |
359 | 437 | } |
0 commit comments