diff --git a/controller/stationcontroller.php b/controller/stationcontroller.php new file mode 100644 index 0000000..d2037d0 --- /dev/null +++ b/controller/stationcontroller.php @@ -0,0 +1,52 @@ +service = $service; + $this->userId = $UserId; + } + + /** + * @NoAdminRequired + */ + public function favorites() { + return new DataResponse($this->service->findAll($this->userId)); + } + + /** + * @NoAdminRequired + * + * @param string $title + * @param string $content + */ + public function fav($id) { + return $this->service->create($id, $this->userId); + } + + /** + * @NoAdminRequired + * + * @param int $id + */ + public function unfav($id) { + return $this->handleNotFound(function () use ($id) { + return $this->service->delete($id, $this->userId); + }); + } + +} diff --git a/img/fav_hover.png b/img/fav_hover.png new file mode 100644 index 0000000..907e3f0 Binary files /dev/null and b/img/fav_hover.png differ diff --git a/service/streamservice.php b/service/streamservice.php new file mode 100644 index 0000000..dae6435 --- /dev/null +++ b/service/streamservice.php @@ -0,0 +1,51 @@ +mapper = $mapper; + } + + public function findAll($userId) { + return $this->mapper->findAll($userId); + } + + private function handleException ($e) { + if ($e instanceof DoesNotExistException || + $e instanceof MultipleObjectsReturnedException) { + throw new NotFoundException($e->getMessage()); + } else { + throw $e; + } + } + + public function fav($id, $userId) { + $station = new Station(); + $station->setId($id); + $station->setUserId($userId); + return $this->mapper->insert($station); + } + + public function unfav($id, $userId) { + try { + $station = $this->mapper->find($id, $userId); + $this->mapper->delete($station); + return $station; + } catch(Exception $e) { + $this->handleException($e); + } + } + +}