| 19 | use OCP\IRequest; |
| 20 | |
| 21 | class ApiController extends OCSController { |
| 22 | private ReportService $reportService; |
| 23 | private $logger; |
| 24 | |
| 25 | public function __construct(string $appName, |
| 26 | IRequest $request, |
| 27 | LoggerInterface $logger, |
| 28 | ReportService $reportService |
| 29 | ) { |
| 30 | parent::__construct($appName, $request); |
| 31 | $this->reportService = $reportService; |
| 32 | $this->logger = $logger; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Create an analytics report from an existing data file. |
| 37 | * |
| 38 | * @param int $fileId ID of the file to import |
| 39 | * |
| 40 | * @return DataResponse HTTP 200 with a link to the created report |
| 41 | * |
| 42 | */ |
| 43 | #[NoAdminRequired] |
| 44 | #[NoCSRFRequired] |
| 45 | #[ApiRoute(verb: 'POST', url: '/createFromDataFile')] |
| 46 | public function createFromDataFile($fileId): DataResponse { |
| 47 | if ($fileId) { |
| 48 | $reportId = $this->reportService->createFromDataFile($fileId); |
| 49 | $url = '/apps/analytics/r/' . $reportId; |
| 50 | return new DataResponse([ |
| 51 | 'version' => '0.1', |
| 52 | 'root' => [ |
| 53 | 'orientation' => 'vertical', |
| 54 | 'rows' => [ |
| 55 | [ |
| 56 | 'children' => [ |
| 57 | [ |
| 58 | 'element' => 'URL', |
| 59 | 'text' => 'Analytics report created', |
| 60 | 'url' => $url, |
| 61 | ], |
| 62 | ], |
| 63 | ], |
| 64 | ], |
| 65 | ], |
| 66 | ]); |
| 67 | } else { |
| 68 | return new DataResponse(['error' => 'fileId missing'], HTTP::STATUS_BAD_REQUEST); |
| 69 | } |
| 70 | } |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected