From ada9efc75dc9e0ce71fb5cd5c1cd92080b746283 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 15 Oct 2021 12:01:57 +0200 Subject: [PATCH] filter list of locations on backend side (GET location endpoint) --- .../vuejs/Activity/components/Location.vue | 2 +- .../Controller/LocationApiController.php | 30 +++++++++++++++++++ .../ChillMainExtension.php | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillMainBundle/Controller/LocationApiController.php diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue index 542d08d1a..b5d35f1a0 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -62,7 +62,7 @@ export default { getLocationsList() { getLocations().then(response => new Promise(resolve => { console.log('getLocations', response); - this.locations = response.results.filter(l => l.availableForUsers === true); + this.locations = response.results; resolve(); })) }, diff --git a/src/Bundle/ChillMainBundle/Controller/LocationApiController.php b/src/Bundle/ChillMainBundle/Controller/LocationApiController.php new file mode 100644 index 000000000..89c508716 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/LocationApiController.php @@ -0,0 +1,30 @@ +andWhere($query->expr()->orX( + $query->expr()->andX( + $query->expr()->eq('e.createdBy', ':user'), + $query->expr()->eq('e.createdAt', ':dateBefore') + ), + $query->expr()->eq('e.availableForUsers', "'TRUE'") + )) + ->setParameters([ + 'user' => $this->getUser(), + 'dateBefore' => (new \DateTime())->sub(new \DateInterval('P6M')) + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 4f54d86bb..8050fd9b6 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -447,6 +447,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, ], [ 'class' => \Chill\MainBundle\Entity\Location::class, + 'controller' => \Chill\MainBundle\Controller\LocationApiController::class, 'name' => 'location', 'base_path' => '/api/1.0/main/location', 'base_role' => 'ROLE_USER',