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