<?php /** * Podcast App * * @author Jonas Heinrich * @copyright 2021 Jonas Heinrich <onny@project-insanity.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ namespace OCA\Podcast\Controller; use OCA\Podcast\AppInfo\Application; use OCA\Podcast\Service\ShowService; use OCA\Podcast\Service\FyydApiService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; class ShowController extends Controller { /** @var ShowsService */ private $service; /** @var FyydApiService */ private $fyydapi; /** @var string */ private $userId; use Errors; public function __construct(IRequest $request, ShowService $service, FyydApiService $fyydapi, $userId) { parent::__construct(Application::APP_ID, $request); $this->service = $service; $this->fyydapi = $fyydapi; $this->userId = $userId; } /** * @NoAdminRequired */ public function index(int $podcast_id = null, string $category = null, int $count = 20, int $page = 0): DataResponse { $data = $this->service->findAll($this->userId); if ($category) { $list = $this->fyydapi->queryCategory($category, $count, $page); return new DataResponse($list); } else if ($podcast_id) { $list = $this->fyydapi->queryPodcast($podcast_id); foreach($data as $localEpisode) { if ($localEpisode->getId() === $list['data']['id']) { $list['data']['dateadded'] = $localEpisode->getDateadded(); } } return new DataResponse($list); } $data = array_slice($data, $page * $count, $count); if (count($data) === $count) { $nextPage = $page + 1; } else { $nextPage = null; }; $response = [ "meta" => [ "paging" => [ "next_page" => $nextPage, ], ], "data" => $data, ]; return new DataResponse($response); } /** * @NoAdminRequired */ public function show(int $id): DataResponse { return $this->handleNotFound(function () use ($id) { return $this->service->find($id, $this->userId); }); } /** * @NoAdminRequired */ public function create(int $id, string $smallImageURL, string $author, string $title, string $lastpub, int $dateadded, string $homepage, string $feedurl): DataResponse { return new DataResponse($this->service->create($id, $smallImageURL, $author, $title, $lastpub, $dateadded, $homepage, $feedurl, $this->userId)); } /** * @NoAdminRequired */ public function update(int $id, string $smallImageURL, string $author, string $title, string $lastpub, int $dateadded, string $homepage, string $feedurl): DataResponse { return $this->handleNotFound(function () use ($id, $smallImageURL, $author, $title, $lastpub, $dateadded, $homepage, $feedurl) { return $this->service->update($id, $smallImageURL, $author, $title, $lastpub, $dateadded, $homepage, $feedurl, $this->userId); }); } /** * @NoAdminRequired */ public function destroy(int $id): DataResponse { return $this->handleNotFound(function () use ($id) { return $this->service->delete($id, $this->userId); }); } }