2023-07-03 00:12:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\RePod\Controller;
|
|
|
|
|
|
|
|
use OCA\RePod\AppInfo\Application;
|
2023-07-28 02:37:57 +02:00
|
|
|
use OCA\RePod\Service\FyydService;
|
2023-07-03 00:12:40 +02:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
class TopController extends Controller
|
|
|
|
{
|
2023-07-03 00:52:14 +02:00
|
|
|
public function __construct(
|
|
|
|
IRequest $request,
|
2023-07-28 02:37:57 +02:00
|
|
|
private FyydService $fyydService
|
2023-07-03 00:52:14 +02:00
|
|
|
) {
|
2023-07-03 00:12:40 +02:00
|
|
|
parent::__construct(Application::APP_ID, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2023-07-28 02:37:57 +02:00
|
|
|
public function index(): JSONResponse
|
2023-07-27 23:01:24 +02:00
|
|
|
{
|
2023-07-25 21:44:25 +02:00
|
|
|
try {
|
2023-07-28 02:37:57 +02:00
|
|
|
$response = $this->fyydService->hot();
|
|
|
|
$json = (array) json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR);
|
2023-07-27 23:01:24 +02:00
|
|
|
|
2023-07-28 02:37:57 +02:00
|
|
|
return new JSONResponse($json, $response->getStatusCode());
|
2023-07-27 23:01:24 +02:00
|
|
|
} catch (\Exception $e) {
|
2023-07-03 00:20:18 +02:00
|
|
|
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
|
2023-07-03 00:12:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|