From 1253c560f3e30a89388382971ecdbb7e76f45496 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Sun, 8 Jan 2017 09:37:11 +0100 Subject: [PATCH] implementing db backend ... --- controller/stationcontroller.php | 52 +++++++++++++++++++++++++++++++ img/fav_hover.png | Bin 0 -> 1437 bytes service/streamservice.php | 51 ++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 controller/stationcontroller.php create mode 100644 img/fav_hover.png create mode 100644 service/streamservice.php 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 0000000000000000000000000000000000000000..907e3f0b42efd81f19cdac0dd4b412683a5dbdd9 GIT binary patch literal 1437 zcmcIkZ%i9y9R6K<99LMk+KM6pTXd<$WE6!-T~Lk3mQs9<2wK!$G7!G=U6tUUqK zEHOhRkxn+K>;q&7EJFHJj}w45DsrS2jl3q?Hvqxb}RHKN=FFe(^4s_qpeN z-rw_kFVB0&3UnHAR9qAQh_$&{djT*6F(3&vlpg7=LIY8er^y12zb#+)v>`@Rlly8d zK(vg1F!57&Mkd&*NF>4_s00_`;ubW_ZWd{k%1R{;8RT-|L=Jm3L-MUV0Suf+wUm9ST|5 znYuvI>p%nK!y^Ib76;#_8K%9~hb$NfAQ}5^!k9t{0SCR{gFdc`CV&J6R}^s9(dL+3mSt z`NPlzi-&{NVn_s!oGanwQ#Ni9BzW>ow=osT-hZ2w^V5|HoQ?O6HCYcJ@2PMwO^i%_ z;bIQ#VMA~12Ag~ZnY3Tcj)gMvhAic}jgT7gU; z(G^5ptWJ>vq+V@lwNdBLY0YX{3;v8H{a5}1@{I)da^|(DVh|KFVcR^c1(yohHlpv% z*vNPR_vCt*>E+gq<1lW#u%3HMxN<$i|MmvAIMSxk3)`C+oJs4d&X!T3qIaH^ zi9t2ukwEZcnLtS|4_<4~#X;G@H}$%3tizqb&M(>CL%e+OT<0kf6^wXVln>XPrOJ0j zmT+HxXOD;q?cd3BnkuOoyw>Vsd$G_G-g{7J5He{WIf;Cj7txX)*d>e$R;xD4fhzb=#+KpSVS<7pM)5N+t98 zgd^|f&?GdDxrU@r_IP8Jk{OS22R8(`~hvV}3c=W$Rmt;xoj=gf@*xm2L{Hr!wmo>0k-}DEZ3mtC& literal 0 HcmV?d00001 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); + } + } + +}