From 2b093c73a306dd57ee5ae5c68e7d51a4d3447cfd Mon Sep 17 00:00:00 2001 From: Jonas Heinrich <onny@project-insanity.org> Date: Mon, 22 Mar 2021 09:43:23 +0100 Subject: [PATCH] show newest podcasts and episodes in library view --- CHANGELOG.md | 4 +++- lib/Controller/EpisodeController.php | 4 ++-- lib/Controller/ShowController.php | 10 +++++----- lib/Db/EpisodeMapper.php | 13 +++++++++++-- lib/Db/ShowMapper.php | 2 +- lib/Service/EpisodeService.php | 4 ++-- src/services/EpisodeApi.js | 3 ++- src/views/Library.vue | 2 +- src/views/Listening.vue | 2 +- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6295e91..67d4fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ yet implemented. - Make player metadata, title and show name as links [#167](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/167) @onny - Add pagination to listening and library view - [#195](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/195) @onny + [#195](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/195) @onny +- Show newest podcasts and episodes in library view + [#214](https://git.project-insanity.org/onny/nextcloud-app-podcast/-/issues/214) @onny ### Changed - Update npm modules diff --git a/lib/Controller/EpisodeController.php b/lib/Controller/EpisodeController.php index 5bac083..a2227ee 100644 --- a/lib/Controller/EpisodeController.php +++ b/lib/Controller/EpisodeController.php @@ -58,7 +58,7 @@ class EpisodeController extends Controller { * @NoAdminRequired */ public function index(int $episode_id = null, int $podcast_id = null, - int $count = 20, int $page = 0): DataResponse { + int $count = 20, int $page = 0, string $sortBy = null): DataResponse { if ($episode_id) { return new DataResponse($this->fyydapi->queryEpisode($episode_id)); @@ -66,7 +66,7 @@ class EpisodeController extends Controller { return new DataResponse($this->fyydapi->queryEpisodes($podcast_id, $count, $page)); } - $data = $this->service->findAll($this->userId); + $data = $this->service->findAll($this->userId, $sortBy); $data = array_slice($data, $page * $count, $count); if (count($data) == $count) { diff --git a/lib/Controller/ShowController.php b/lib/Controller/ShowController.php index d55271f..40e67ba 100644 --- a/lib/Controller/ShowController.php +++ b/lib/Controller/ShowController.php @@ -98,22 +98,22 @@ class ShowController extends Controller { /** * @NoAdminRequired */ - public function create(int $id, string $imgurl, string $author, + 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, $imgurl, $author, + return new DataResponse($this->service->create($id, $smallImageURL, $author, $title, $lastpub, $dateadded, $homepage, $feedurl, $this->userId)); } /** * @NoAdminRequired */ - public function update(int $id, string $imgurl, string $author, + 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, $imgurl, $author, + return $this->handleNotFound(function () use ($id, $smallImageURL, $author, $title, $lastpub, $dateadded, $homepage, $feedurl) { - return $this->service->update($id, $imgurl, $author, $title, $lastpub, + return $this->service->update($id, $smallImageURL, $author, $title, $lastpub, $dateadded, $homepage, $feedurl, $this->userId); }); } diff --git a/lib/Db/EpisodeMapper.php b/lib/Db/EpisodeMapper.php index db5fabd..fdb7a35 100644 --- a/lib/Db/EpisodeMapper.php +++ b/lib/Db/EpisodeMapper.php @@ -55,12 +55,21 @@ class EpisodeMapper extends QBMapper { * @param string $userId * @return array */ - public function findAll(string $userId): array { + public function findAll(string $userId, string $sortBy = null): array { + if ($sortBy) { + if ($sortBy == 'pubdate') { + $sortBy = 'pubdate'; + } else { + $sortBy = 'lastplayed'; + } + } else { + $sortBy = 'lastplayed'; + }; /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('episodes') - ->orderBy('lastplayed', 'DESC') + ->orderBy($sortBy, 'DESC') ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))); return $this->findEntities($qb); } diff --git a/lib/Db/ShowMapper.php b/lib/Db/ShowMapper.php index 9fb0638..6a94199 100644 --- a/lib/Db/ShowMapper.php +++ b/lib/Db/ShowMapper.php @@ -61,7 +61,7 @@ class ShowMapper extends QBMapper { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('shows') - ->orderBy('dateadded', 'DESC') + ->orderBy('lastpub', 'DESC') ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))); return $this->findEntities($qb); } diff --git a/lib/Service/EpisodeService.php b/lib/Service/EpisodeService.php index c0f2217..06cfd39 100644 --- a/lib/Service/EpisodeService.php +++ b/lib/Service/EpisodeService.php @@ -40,8 +40,8 @@ class EpisodeService { $this->mapper = $mapper; } - public function findAll(string $userId): array { - return $this->mapper->findAll($userId); + public function findAll(string $userId, string $sortBy = null): array { + return $this->mapper->findAll($userId, $sortBy); } private function handleException(Exception $e): void { diff --git a/src/services/EpisodeApi.js b/src/services/EpisodeApi.js index 99860c4..c95c082 100644 --- a/src/services/EpisodeApi.js +++ b/src/services/EpisodeApi.js @@ -72,7 +72,7 @@ export class EpisodeApi { }) } - queryEpisodes(podcastId = null, page = 0) { + queryEpisodes(podcastId = null, page = 0, sortBy = 'lastplayed') { let params = {} if (podcastId) { params = { @@ -84,6 +84,7 @@ export class EpisodeApi { params = { count: 20, page, + sortBy, } } return axios.get(this.url('/episodes'), { diff --git a/src/views/Library.vue b/src/views/Library.vue index 497643f..138fab3 100644 --- a/src/views/Library.vue +++ b/src/views/Library.vue @@ -109,7 +109,7 @@ export default { }, async queryEpisodes(page) { - const episodes = await episodeApiClient.queryEpisodes(null, page) + const episodes = await episodeApiClient.queryEpisodes(null, page, 'pubdate') this.episodes = this.episodes.concat(episodes.data.episodes) if (episodes.meta.paging.next_page === null) { this.page = null diff --git a/src/views/Listening.vue b/src/views/Listening.vue index c799fd4..1a58271 100644 --- a/src/views/Listening.vue +++ b/src/views/Listening.vue @@ -69,7 +69,7 @@ export default { ]), async queryEpisodes(page) { - const episodes = await episodeApiClient.queryEpisodes(null, page) + const episodes = await episodeApiClient.queryEpisodes(null, page, 'lastplayed') this.episodes = this.episodes.concat(episodes.data.episodes) if (episodes.meta.paging.next_page === null) { this.page = null -- GitLab