From c835b6d1b89e43c8d7e0d5d074062e24f3e54a4a Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Fri, 6 Nov 2020 09:11:30 +0100 Subject: [PATCH] implementing favorite stations db backend --- lib/Controller/StationApiController.php | 10 +++++----- lib/Controller/StationController.php | 14 +++++++------- lib/Db/Station.php | 12 ++++++++---- .../Version000000Date20181013124731.php | 16 ++++++++++++---- lib/Service/StationService.php | 16 ++++++++++------ src/components/Main.vue | 10 ++++++---- 6 files changed, 48 insertions(+), 30 deletions(-) diff --git a/lib/Controller/StationApiController.php b/lib/Controller/StationApiController.php index 0dde685..d5c176c 100644 --- a/lib/Controller/StationApiController.php +++ b/lib/Controller/StationApiController.php @@ -50,9 +50,9 @@ class StationApiController extends ApiController { * @NoCSRFRequired * @NoAdminRequired */ - public function create(string $title, string $content): DataResponse { - return new DataResponse($this->service->create($title, $content, - $this->userId)); + public function create(string $stationuuid, string $name, string $favicon, string $url_resolved): DataResponse { + return new DataResponse($this->service->create($stationuuid, $name, + $favicon, $url_resolved, $this->userId)); } /** @@ -62,8 +62,8 @@ class StationApiController extends ApiController { */ public function update(int $id, string $title, string $content): DataResponse { - return $this->handleNotFound(function () use ($id, $title, $content) { - return $this->service->update($id, $title, $content, $this->userId); + return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $url_resolved) { + return $this->service->update($id, $stationuuid, $name, $favicon, $url_resolved, $this->userId); }); } diff --git a/lib/Controller/StationController.php b/lib/Controller/StationController.php index 5e61506..21960dd 100644 --- a/lib/Controller/StationController.php +++ b/lib/Controller/StationController.php @@ -42,18 +42,18 @@ class StationController extends Controller { /** * @NoAdminRequired */ - public function create(string $title, string $content): DataResponse { - return new DataResponse($this->service->create($title, $content, - $this->userId)); + public function create(string $stationuuid, string $name, string $favicon, string $url_resolved): DataResponse { + return new DataResponse($this->service->create($stationuuid, $name, + $favicon, $url_resolved, $this->userId)); } /** * @NoAdminRequired */ - public function update(int $id, string $title, - string $content): DataResponse { - return $this->handleNotFound(function () use ($id, $title, $content) { - return $this->service->update($id, $title, $content, $this->userId); + public function update(int $id, string $stationuuid, + string $name, string $favicon, string $url_resolved): DataResponse { + return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $url_resolved) { + return $this->service->update($id, $stationuuid, $name, $favicon, $url_resolved, $this->userId); }); } diff --git a/lib/Db/Station.php b/lib/Db/Station.php index 601f845..d3620e0 100644 --- a/lib/Db/Station.php +++ b/lib/Db/Station.php @@ -7,15 +7,19 @@ use JsonSerializable; use OCP\AppFramework\Db\Entity; class Station extends Entity implements JsonSerializable { - protected $title; - protected $content; + protected $stationuuid; + protected $name; + protected $favicon; + protected $url_resolved; protected $userId; public function jsonSerialize(): array { return [ 'id' => $this->id, - 'title' => $this->title, - 'content' => $this->content + 'stationuuid' => $this->stationuuid, + 'name' => $this->name, + 'favicon' => $this->favicon, + 'url_resolved' => $this->url_resolved ]; } } diff --git a/lib/Migration/Version000000Date20181013124731.php b/lib/Migration/Version000000Date20181013124731.php index 28d2b4a..b71988a 100644 --- a/lib/Migration/Version000000Date20181013124731.php +++ b/lib/Migration/Version000000Date20181013124731.php @@ -27,17 +27,25 @@ class Version000000Date20181013124731 extends SimpleMigrationStep { 'autoincrement' => true, 'notnull' => true, ]); - $table->addColumn('title', 'string', [ + $table->addColumn('stationuuid', 'string', [ 'notnull' => true, - 'length' => 200 + 'length' => 200, ]); $table->addColumn('user_id', 'string', [ 'notnull' => true, 'length' => 200, ]); - $table->addColumn('content', 'text', [ + $table->addColumn('name', 'text', [ 'notnull' => true, - 'default' => '' + 'length' => 200, + ]); + $table->addColumn('favicon', 'text', [ + 'notnull' => true, + 'length' => 200, + ]); + $table->addColumn('url_resolved', 'text', [ + 'notnull' => true, + 'length' => 200, ]); $table->setPrimaryKey(['id']); diff --git a/lib/Service/StationService.php b/lib/Service/StationService.php index fa3ede9..cd2840d 100644 --- a/lib/Service/StationService.php +++ b/lib/Service/StationService.php @@ -45,19 +45,23 @@ class StationService { } } - public function create($title, $content, $userId) { + public function create($stationuuid, $name, $favicon, $url_resolved, $userId) { $station = new Station(); - $station->setTitle($title); - $station->setContent($content); + $station->setStationUuid($stationuuid); + $station->setName($name); + $station->setFavicon($favicon); + $station->setUrlResolved($url_resolved); $station->setUserId($userId); return $this->mapper->insert($station); } - public function update($id, $title, $content, $userId) { + public function update($id, $stationuuid, $name, $userId) { try { $station = $this->mapper->find($id, $userId); - $station->setTitle($title); - $station->setContent($content); + $station->setStationUuid($stationuuid); + $station->setName($name); + $station->setFavicon($favicon); + $station->setUrlResolved($url_resolved); return $this->mapper->update($station); } catch (Exception $e) { $this->handleException($e); diff --git a/src/components/Main.vue b/src/components/Main.vue index 3e60ea4..4212132 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -93,12 +93,14 @@ export default { */ async doFavor(station) { try { - station = { + const newStation = { id: -1, - title: 'test', - content: 'testhallo', + stationuuid: station.stationuuid, + name: station.name, + favicon: station.favicon, + url_resolved: station.url_resolved, } - const response = await axios.post(generateUrl('/apps/radio/stations'), station) + const response = await axios.post(generateUrl('/apps/radio/stations'), newStation) console.log(response) // const index = this.stations.findIndex((match) => match.id === this.currentStationId) // this.$set(this.stations, index, response.data)