From 48f3c440a2dd7ec9ceabb56194a11ec2d7d543b4 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 13 Oct 2021 14:22:53 +0200 Subject: [PATCH] adding an API GET Location endpoint, fetch locations and list them in vue multiselect --- .../Resources/public/vuejs/Activity/api.js | 19 ++++++-- .../vuejs/Activity/components/Location.vue | 43 +++++++++++++++++-- .../Resources/public/vuejs/Activity/store.js | 4 ++ .../ChillMainExtension.php | 21 +++++++++ .../ChillMainBundle/chill.api.specs.yaml | 11 +++++ 5 files changed, 91 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js index 79b4ec8fc..f61587de4 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js @@ -3,16 +3,29 @@ import { getSocialIssues } from 'ChillPersonAssets/vuejs/AccompanyingCourse/api. /* * Load socialActions by socialIssue (id) */ -const getSocialActionByIssue = (id) => { +const getSocialActionByIssue = (id) => { const url = `/api/1.0/person/social/social-action/by-social-issue/${id}.json`; return fetch(url) .then(response => { if (response.ok) { return response.json(); } - throw Error('Error with request resource response'); + throw Error('Error with request resource response'); }); }; +/* +* Load Locations + */ +const getLocations = () => { + const url = `/api/1.0/main/location.json`; + return fetch(url) + .then(response => { + if (response.ok) { return response.json(); } + throw Error('Error with request resource response'); + }); +}; + export { getSocialIssues, - getSocialActionByIssue + getSocialActionByIssue, + getLocations }; 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 6d4c968cc..e25923850 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -5,11 +5,19 @@ Localisation
-
@@ -18,9 +26,10 @@ diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js index 952cb5b25..57dc26918 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js @@ -114,6 +114,10 @@ const store = createStore({ state.activity.users = state.activity.users.filter(user => user !== payload); break; }; + }, + updateLocation(state, value) { + console.log('### mutation: updateLocation', value); + state.activity.location = value; } }, actions: { diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 21217c80e..8df374ce8 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -445,6 +445,27 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, ], ] ], + [ + 'class' => \Chill\MainBundle\Entity\Location::class, + 'name' => 'location', + 'base_path' => '/api/1.0/main/location', + 'base_role' => 'ROLE_USER', + 'actions' => [ + '_index' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true + ], + ], + '_entity' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + ] + ], + + ] + ] ] ]); } diff --git a/src/Bundle/ChillMainBundle/chill.api.specs.yaml b/src/Bundle/ChillMainBundle/chill.api.specs.yaml index 874ae669b..50bcd7c28 100644 --- a/src/Bundle/ChillMainBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillMainBundle/chill.api.specs.yaml @@ -537,3 +537,14 @@ paths: description: "ok" 401: description: "Unauthorized" + + /1.0/main/location.json: + get: + tags: + - location + summary: Return a list of locations + responses: + 200: + description: "ok" + 401: + description: "Unauthorized"