From e83295ef357b08870e7e6d1ee666e0ff0fa5ed22 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 7 Nov 2023 15:16:39 +0100 Subject: [PATCH] new: [sightings:view] Added endpoint sightings/view to get sightings by ID or UUID --- app/Controller/SightingsController.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Controller/SightingsController.php b/app/Controller/SightingsController.php index 7ba059918..bfe6491ff 100644 --- a/app/Controller/SightingsController.php +++ b/app/Controller/SightingsController.php @@ -119,6 +119,23 @@ class SightingsController extends AppController } } + public function view($idOrUUID) + { + $sighting = $this->Sighting->find('first', array( + 'conditions' => Validation::uuid($idOrUUID) ? ['Sighting.uuid' => $idOrUUID] : ['Sighting.id' => $idOrUUID], + 'recursive' => -1, + 'fields' => ['id', 'attribute_id'], + )); + $sightings = []; + if (!empty($sighting)) { + $sightings = $this->Sighting->listSightings($this->Auth->user(), $sighting['Sighting']['attribute_id'], 'attribute'); + } + if (empty($sightings)) { + throw new NotFoundException('Invalid sighting.'); + } + return $this->RestResponse->viewData($sightings[0]); + } + public function advanced($id, $context = 'attribute') { if (empty($id)) {