From 05d6634d0cd84617779ef5284d10055480ccb037 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Thu, 19 Nov 2020 22:35:13 +0100 Subject: [PATCH] fix settingscontroller bug, add more props to db backend --- lib/Controller/FavoriteController.php | 29 ++++++++---- lib/Controller/RecentController.php | 20 +++++--- lib/Controller/SettingsController.php | 2 +- lib/Db/RecentMapper.php | 12 +++++ lib/Db/Station.php | 14 +++++- .../Version000000Date20181013124731.php | 12 +++++ lib/Service/FavoriteService.php | 18 ++++++- lib/Service/RecentService.php | 18 ++++++- src/components/Dashboard.vue | 2 +- src/components/Main.vue | 47 +++++++++---------- src/components/Sidebar.vue | 7 ++- 11 files changed, 130 insertions(+), 51 deletions(-) diff --git a/lib/Controller/FavoriteController.php b/lib/Controller/FavoriteController.php index 722d333..72bbd0d 100644 --- a/lib/Controller/FavoriteController.php +++ b/lib/Controller/FavoriteController.php @@ -44,20 +44,29 @@ class FavoriteController extends Controller { /** * @NoAdminRequired */ - public function create(string $stationuuid, string $name, string $favicon, string $urlresolved): DataResponse { - return new DataResponse($this->service->create($stationuuid, $name, - $favicon, $urlresolved, $this->userId)); - } + public function create(string $stationuuid, string $name, string $favicon, string $urlresolved, + string $bitrate, string $country, string $language, string $homepage, + string $codec, string $tags): DataResponse { + return new DataResponse($this->service->create($stationuuid, $name, + $favicon, $urlresolved, $bitrate, $country, $language, $homepage, $codec, + $tags, $this->userId)); + } /** * @NoAdminRequired */ - public function update(int $id, string $stationuuid, - string $name, string $favicon, string $urlresolved): DataResponse { - return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $urlresolved) { - return $this->service->update($id, $stationuuid, $name, $favicon, $urlresolved, $this->userId); - }); - } + public function update(int $id, string $stationuuid, + string $name, string $favicon, string $urlresolved, + string $bitrate, string $country, string $language, string $homepage, + string $codec, string $tags): DataResponse { + return $this->handleNotFound(function () use ($id, $stationuuid, $name, + $favicon, $urlresolved, $bitrate, $country, $language, $homepage, $codec, + $tags) { + return $this->service->update($id, $stationuuid, $name, $favicon, + $urlresolved, $bitrate, $country, $language, $homepage, $codec, + $tags, $this->userId); + }); + } /** * @NoAdminRequired diff --git a/lib/Controller/RecentController.php b/lib/Controller/RecentController.php index 8f39145..78c9695 100644 --- a/lib/Controller/RecentController.php +++ b/lib/Controller/RecentController.php @@ -44,18 +44,26 @@ class RecentController extends Controller { /** * @NoAdminRequired */ - public function create(string $stationuuid, string $name, string $favicon, string $urlresolved): DataResponse { + public function create(string $stationuuid, string $name, string $favicon, string $urlresolved, + string $bitrate, string $country, string $language, string $homepage, + string $codec, string $tags): DataResponse { return new DataResponse($this->service->create($stationuuid, $name, - $favicon, $urlresolved, $this->userId)); + $favicon, $urlresolved, $bitrate, $country, $language, $homepage, $codec, + $tags, $this->userId)); } /** * @NoAdminRequired */ - public function update(int $id, string $stationuuid, - string $name, string $favicon, string $urlresolved): DataResponse { - return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $urlresolved) { - return $this->service->update($id, $stationuuid, $name, $favicon, $urlresolved, $this->userId); + public function update(int $id, string $stationuuid, string $name, + string $favicon, string $urlresolved, string $bitrate, string $country, + string $language, string $homepage, string $codec, string $tags): DataResponse { + return $this->handleNotFound(function () use ($id, $stationuuid, $name, + $favicon, $urlresolved, $bitrate, $country, $language, $homepage, $codec, + $tags) { + return $this->service->update($id, $stationuuid, $name, $favicon, + $urlresolved, $bitrate, $country, $language, $homepage, $codec, + $tags, $this->userId); }); } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index b0307ef..c8f66ac 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -79,7 +79,7 @@ class SettingsController extends ApiController { */ public function setMenuState($menuState = ""): JSONResponse { if ($menuState == 'SEARCH') { - return true; + return new JSONResponse(['status' => 'success'], Http::STATUS_OK); }; $legalArguments = ['TOP', 'RECENT', 'NEW', 'FAVORITES', 'CATEGORIES']; if (!in_array($menuState, $legalArguments)) { diff --git a/lib/Db/RecentMapper.php b/lib/Db/RecentMapper.php index afbbd5d..e8b368c 100644 --- a/lib/Db/RecentMapper.php +++ b/lib/Db/RecentMapper.php @@ -27,6 +27,12 @@ class RecentMapper extends QBMapper { ->addSelect('name') ->addSelect('favicon') ->addSelect('urlresolved') + ->addSelect('bitrate') + ->addSelect('country') + ->addSelect('language') + ->addSelect('homepage') + ->addSelect('codec') + ->addSelect('tags') ->from('recent') ->orderBy('id', 'DESC') ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) @@ -45,6 +51,12 @@ class RecentMapper extends QBMapper { ->addSelect('name') ->addSelect('favicon') ->addSelect('urlresolved') + ->addSelect('bitrate') + ->addSelect('country') + ->addSelect('language') + ->addSelect('homepage') + ->addSelect('codec') + ->addSelect('tags') ->from('recent') ->orderBy('id', 'DESC') ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))); diff --git a/lib/Db/Station.php b/lib/Db/Station.php index 8780fa1..868f155 100644 --- a/lib/Db/Station.php +++ b/lib/Db/Station.php @@ -11,6 +11,12 @@ class Station extends Entity implements JsonSerializable { protected $name; protected $favicon; protected $urlresolved; + protected $bitrate; + protected $country; + protected $language; + protected $homepage; + protected $codec; + protected $tags; protected $userId; public function jsonSerialize(): array { @@ -19,7 +25,13 @@ class Station extends Entity implements JsonSerializable { 'stationuuid' => $this->stationuuid, 'name' => $this->name, 'favicon' => $this->favicon, - 'urlresolved' => $this->urlresolved + 'urlresolved' => $this->urlresolved, + 'bitrate' => $this->bitrate, + 'country' => $this->country, + 'language' => $this->language, + 'homepage' => $this->homepage, + 'codec' => $this->codec, + 'tags' => $this->tags ]; } } diff --git a/lib/Migration/Version000000Date20181013124731.php b/lib/Migration/Version000000Date20181013124731.php index 58dea7f..bffbcab 100644 --- a/lib/Migration/Version000000Date20181013124731.php +++ b/lib/Migration/Version000000Date20181013124731.php @@ -38,6 +38,12 @@ class Version000000Date20181013124731 extends SimpleMigrationStep { ]); $table->addColumn('favicon', 'text'); $table->addColumn('urlresolved', 'text'); + $table->addColumn('bitrate', 'text'); + $table->addColumn('country', 'text'); + $table->addColumn('language', 'text'); + $table->addColumn('homepage', 'text'); + $table->addColumn('codec', 'text'); + $table->addColumn('tags', 'text'); $table->setPrimaryKey(['id']); $table->addIndex(['user_id'], 'favorites_user_id_index'); @@ -60,6 +66,12 @@ class Version000000Date20181013124731 extends SimpleMigrationStep { ]); $table->addColumn('favicon', 'text'); $table->addColumn('urlresolved', 'text'); + $table->addColumn('bitrate', 'text'); + $table->addColumn('country', 'text'); + $table->addColumn('language', 'text'); + $table->addColumn('homepage', 'text'); + $table->addColumn('codec', 'text'); + $table->addColumn('tags', 'text'); $table->setPrimaryKey(['id']); $table->addIndex(['user_id'], 'recent_user_id_index'); diff --git a/lib/Service/FavoriteService.php b/lib/Service/FavoriteService.php index b9d7aea..9e6c934 100644 --- a/lib/Service/FavoriteService.php +++ b/lib/Service/FavoriteService.php @@ -45,23 +45,37 @@ class FavoriteService { } } - public function create($stationuuid, $name, $favicon, $urlresolved, $userId) { + public function create($stationuuid, $name, $favicon, $urlresolved, + $bitrate, $country, $language, $homepage, $codec, $tags, $userId) { $station = new Station(); $station->setStationuuid($stationuuid); $station->setName($name); $station->setFavicon($favicon); $station->setUrlresolved($urlresolved); + $station->setBitrate($bitrate); + $station->setCountry($country); + $station->setLanguage($language); + $station->setHomepage($homepage); + $station->setCodec($codec); + $station->setTags($tags); $station->setUserId($userId); return $this->mapper->insert($station); } - public function update($id, $stationuuid, $name, $favicon, $urlresolved, $userId) { + public function update($id, $stationuuid, $name, $favicon, $urlresolved, + $bitrate, $country, $language, $homepage, $codec, $tags, $userId) { try { $station = $this->mapper->find($id, $userId); $station->setStationuuid($stationuuid); $station->setName($name); $station->setFavicon($favicon); $station->setUrlresolved($urlresolved); + $station->setBitrate($bitrate); + $station->setCountry($country); + $station->setLanguage($language); + $station->setHomepage($homepage); + $station->setCodec($codec); + $station->setTags($tags); return $this->mapper->update($station); } catch (Exception $e) { $this->handleException($e); diff --git a/lib/Service/RecentService.php b/lib/Service/RecentService.php index 4b67f8e..4ce269c 100644 --- a/lib/Service/RecentService.php +++ b/lib/Service/RecentService.php @@ -45,23 +45,37 @@ class RecentService { } } - public function create($stationuuid, $name, $favicon, $urlresolved, $userId) { + public function create($stationuuid, $name, $favicon, $urlresolved, + $bitrate, $country, $language, $homepage, $codec, $tags, $userId) { $station = new Station(); $station->setStationuuid($stationuuid); $station->setName($name); $station->setFavicon($favicon); $station->setUrlresolved($urlresolved); + $station->setBitrate($bitrate); + $station->setCountry($country); + $station->setLanguage($language); + $station->setHomepage($homepage); + $station->setCodec($codec); + $station->setTags($tags); $station->setUserId($userId); return $this->mapper->insert($station); } - public function update($id, $stationuuid, $name, $favicon, $urlresolved, $userId) { + public function update($id, $stationuuid, $name, $favicon, $urlresolved, + $bitrate, $country, $language, $homepage, $codec, $tags, $userId) { try { $station = $this->mapper->find($id, $userId); $station->setStationuuid($stationuuid); $station->setName($name); $station->setFavicon($favicon); $station->setUrlresolved($urlresolved); + $station->setBitrate($bitrate); + $station->setCountry($country); + $station->setLanguage($language); + $station->setHomepage($homepage); + $station->setCodec($codec); + $station->setTags($tags); return $this->mapper->update($station); } catch (Exception $e) { $this->handleException($e); diff --git a/src/components/Dashboard.vue b/src/components/Dashboard.vue index d2c4667..f323dc0 100644 --- a/src/components/Dashboard.vue +++ b/src/components/Dashboard.vue @@ -55,7 +55,7 @@ export default { targetUrl: generateUrl('/apps/radio/#/favorites'), avatarUrl: n.favicon, mainText: n.name, - subText: n.tags, + subText: n.tags.replaceAll(',', ', '), } }) }, diff --git a/src/components/Main.vue b/src/components/Main.vue index 1334946..da9dedf 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -61,7 +61,7 @@ export default { blurHashes: require('../assets/blurHashes.json'), favorites: [], showSidebar: false, - sidebarStation: [], + sidebarStation: {}, }), computed: { player() { @@ -161,10 +161,16 @@ export default { } const stationMap = { id: -1, - name: station.name, - urlresolved: stationSrc, - favicon: station.favicon, - stationuuid: station.stationuuid, + name: station.name.toString(), + urlresolved: stationSrc.toString(), + favicon: station.favicon.toString(), + stationuuid: station.stationuuid.toString(), + bitrate: station.bitrate.toString(), + country: station.country.toString(), + language: station.language.toString(), + homepage: station.homepage.toString(), + codec: station.codec.toString(), + tags: station.tags.toString(), } await axios .post(generateUrl('/apps/radio/api/favorites'), stationMap) @@ -246,10 +252,16 @@ export default { } const stationMap = { id: -1, - name: station.name, - urlresolved: stationSrc, - favicon: station.favicon, - stationuuid: station.stationuuid, + name: station.name.toString(), + urlresolved: stationSrc.toString(), + favicon: station.favicon.toString(), + stationuuid: station.stationuuid.toString(), + bitrate: station.bitrate.toString(), + country: station.country.toString(), + language: station.language.toString(), + homepage: station.homepage.toString(), + codec: station.codec.toString(), + tags: station.tags.toString(), } await axios .post(generateUrl('/apps/radio/api/recent'), stationMap) @@ -390,27 +402,10 @@ export default { diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index f838ccd..ff5df09 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -79,8 +79,10 @@ export default { default() { return false }, }, sidebarStation: { - type: Array, - default() { return [] }, + type: Object, + default() { + return {} + }, }, }, computed: { @@ -103,6 +105,7 @@ export default { this.$emit('toggleSidebar') }, copyLink() { + console.log(this.sidebarStation.favicon) this.$copyText(this.urlResolved).then( function() { showSuccess(t('radio', 'Link copied to clipboard'))