repod/lib/Controller/EpisodesController.php
Michel Roux 5683d353bb
All checks were successful
repod / nextcloud (push) Successful in 50s
repod / nodejs (push) Successful in 1m23s
Fix actions
2023-08-29 08:48:54 +02:00

48 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\RePod\Controller;
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
use OCA\RePod\AppInfo\Application;
use OCA\RePod\Core\EpisodeAction\EpisodeActionReader;
use OCA\RePod\Service\UserService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService;
use OCP\IRequest;
class EpisodesController extends Controller
{
public function __construct(
IRequest $request,
private IClientService $clientService,
private EpisodeActionReader $episodeActionReader,
private EpisodeActionRepository $episodeActionRepository,
private UserService $userService
) {
parent::__construct(Application::APP_ID, $request);
}
public function list(string $url): JSONResponse
{
$client = $this->clientService->newClient();
$feed = $client->get($url);
return new JSONResponse($this->episodeActionReader->parseRssXml((string) $feed->getBody()), $feed->getStatusCode());
}
public function action(string $url): JSONResponse
{
$action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID());
if ($action) {
return new JSONResponse($action->toArray());
}
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
}