diff --git a/appinfo/routes.php b/appinfo/routes.php index 51f07a7..e374330 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -23,8 +23,10 @@ return [ 'resources' => [ - 'station' => ['url' => '/stations'], - 'station_api' => ['url' => '/api/0.1/stations'] + 'favorite' => ['url' => '/api/favorites'], + 'favorite_api' => ['url' => '/api/0.1/favorites'], + 'recent' => ['url' => '/api/recents'], + 'recent_api' => ['url' => '/api/0.1/recents'] ], 'routes' => [ diff --git a/lib/Controller/StationApiController.php b/lib/Controller/StationApiController.php deleted file mode 100644 index 56e81ae..0000000 --- a/lib/Controller/StationApiController.php +++ /dev/null @@ -1,80 +0,0 @@ -service = $service; - $this->userId = $userId; - } - - /** - * @CORS - * @NoCSRFRequired - * @NoAdminRequired - */ - public function index(): DataResponse { - return new DataResponse($this->service->findAll($this->userId)); - } - - /** - * @CORS - * @NoCSRFRequired - * @NoAdminRequired - */ - public function show(int $id): DataResponse { - return $this->handleNotFound(function () use ($id) { - return $this->service->find($id, $this->userId); - }); - } - - /** - * @CORS - * @NoCSRFRequired - * @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)); - } - - /** - * @CORS - * @NoCSRFRequired - * @NoAdminRequired - */ - public function update(int $id, string $title, - string $content): DataResponse { - return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $urlresolved) { - return $this->service->update($id, $stationuuid, $name, $favicon, $urlresolved, $this->userId); - }); - } - - /** - * @CORS - * @NoCSRFRequired - * @NoAdminRequired - */ - public function destroy(int $id): DataResponse { - return $this->handleNotFound(function () use ($id) { - return $this->service->delete($id, $this->userId); - }); - } -} diff --git a/lib/Controller/StationController.php b/lib/Controller/StationController.php deleted file mode 100644 index fa28069..0000000 --- a/lib/Controller/StationController.php +++ /dev/null @@ -1,68 +0,0 @@ -service = $service; - $this->userId = $userId; - } - - /** - * @NoAdminRequired - */ - public function index(): DataResponse { - return new DataResponse($this->service->findAll($this->userId)); - } - - /** - * @NoAdminRequired - */ - public function show(int $id): DataResponse { - return $this->handleNotFound(function () use ($id) { - return $this->service->find($id, $this->userId); - }); - } - - /** - * @NoAdminRequired - */ - public function create(string $stationuuid, string $name, string $favicon, string $urlresolved = "lol"): DataResponse { - return new DataResponse($this->service->create($stationuuid, $name, - $favicon, $urlresolved, $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); - }); - } - - /** - * @NoAdminRequired - */ - public function destroy(int $id): DataResponse { - return $this->handleNotFound(function () use ($id) { - return $this->service->delete($id, $this->userId); - }); - } -} diff --git a/lib/Db/StationMapper.php b/lib/Db/StationMapper.php index 8ca37b4..74aa992 100644 --- a/lib/Db/StationMapper.php +++ b/lib/Db/StationMapper.php @@ -10,7 +10,7 @@ use OCP\IDBConnection; class StationMapper extends QBMapper { public function __construct(IDBConnection $db) { - parent::__construct($db, 'radio', Station::class); + parent::__construct($db, 'favorites', Station::class); } /** @@ -24,7 +24,7 @@ class StationMapper extends QBMapper { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('*') - ->from('radio') + ->from('favorites') ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))); return $this->findEntity($qb); @@ -38,7 +38,7 @@ class StationMapper extends QBMapper { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('*') - ->from('radio') + ->from('favorites') ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId))); return $this->findEntities($qb); } diff --git a/lib/Migration/Version000000Date20181013124731.php b/lib/Migration/Version000000Date20181013124731.php index 2072016..cddfa60 100644 --- a/lib/Migration/Version000000Date20181013124731.php +++ b/lib/Migration/Version000000Date20181013124731.php @@ -21,8 +21,8 @@ class Version000000Date20181013124731 extends SimpleMigrationStep { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - if (!$schema->hasTable('radio')) { - $table = $schema->createTable('radio'); + if (!$schema->hasTable('favorites')) { + $table = $schema->createTable('favorites'); $table->addColumn('id', 'integer', [ 'autoincrement' => true, 'notnull' => true, @@ -40,7 +40,7 @@ class Version000000Date20181013124731 extends SimpleMigrationStep { $table->addColumn('urlresolved', 'text'); $table->setPrimaryKey(['id']); - $table->addIndex(['user_id'], 'radio_user_id_index'); + $table->addIndex(['user_id'], 'favorites_user_id_index'); } return $schema; } diff --git a/src/components/Main.vue b/src/components/Main.vue index 129e47e..43897cf 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -97,7 +97,7 @@ export default { */ async doFavor(station) { try { - await axios.post(generateUrl('/apps/radio/stations'), station) + await axios.post(generateUrl('/apps/radio/api/favorites'), station) } catch (e) { showError(t('radio', 'Could not favor station')) } @@ -172,7 +172,7 @@ export default { const searchQuery = vm.$route.params.query queryURI = queryBase + '/byname/' + searchQuery } else if (menuState === 'FAVORITES') { - queryURI = generateUrl('/apps/radio/stations') + queryURI = generateUrl('/apps/radio/api/favorites') } await axios.get(queryURI, { @@ -211,7 +211,7 @@ export default { this.$store.dispatch('getVolumeState') }, async loadFavorites() { - await axios.get(generateUrl('/apps/radio/stations')) + await axios.get(generateUrl('/apps/radio/api/favorites')) .then(function(response) { this.favorites = response.data })