From dcd1856ebbbf61143e46f2f7c4e7fc3cbbf2c44e Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 10 May 2021 10:43:28 +0200 Subject: [PATCH] adapt api endpoint, resolve id parameter passed in api functions --- .../public/vuejs/AccompanyingCourse/api.js | 27 ++++++---------- .../vuejs/AccompanyingCourse/store/index.js | 3 +- .../Resources/public/vuejs/_api/AddPersons.js | 32 +++++++++++++------ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js index 400efc8e4..e0145f91c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js @@ -1,18 +1,11 @@ -const - locale = 'fr', - format = 'json' - , accompanying_period_id = window.accompanyingCourseId //tmp -; - /* -* Endpoint chill_person_accompanying_course_api_show -* method GET, get AccompanyingCourse Object +* Endpoint v.2 chill_api_single_accompanying_course__entity +* method GET/HEAD, get AccompanyingCourse Instance * -* @accompanying_period_id___ integer -* @TODO var is not used but necessary in method signature +* @id integer - id of accompanyingCourse */ -let getAccompanyingCourse = (accompanying_period_id___) => { //tmp - const url = `/${locale}/person/api/1.0/accompanying-course/${accompanying_period_id}/show.${format}`; +let getAccompanyingCourse = (id) => { //tmp + const url = `/api/1.0/person/accompanying-course/${id}.json` return fetch(url) .then(response => { if (response.ok) { return response.json(); } @@ -24,12 +17,12 @@ let getAccompanyingCourse = (accompanying_period_id___) => { //tmp * Endpoint v.2 chill_api_single_accompanying_course_participation, * method POST/DELETE, add/close a participation to the accompanyingCourse * -* @accompanying_period_id integer - id of accompanyingCourse -* @person_id integer - id of person -* @method string - POST or DELETE +* @id integer - id of accompanyingCourse +* @person_id integer - id of person +* @method string - POST or DELETE */ -let postParticipation = (accompanying_period_id, person_id, method) => { - const url = `/api/1.0/person/accompanying-course/${accompanying_period_id}/participation.${format}` +let postParticipation = (id, person_id, method) => { + const url = `/api/1.0/person/accompanying-course/${id}/participation.json` return fetch(url, { method: method, headers: { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 92b97b850..2f986237d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -3,8 +3,7 @@ import { createStore } from 'vuex'; import { getAccompanyingCourse, postParticipation } from '../api'; const debug = process.env.NODE_ENV !== 'production'; - -const id = window.accompanyingCourseId; //tmp +const id = window.accompanyingCourseId; let initPromise = getAccompanyingCourse(id) .then(accompanying_course => new Promise((resolve, reject) => { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js index ccf6764bf..76b907c10 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js @@ -1,16 +1,12 @@ -const - locale = 'fr', - format = 'json' -; - /* -* Endpoint chill_person_search, method GET, get a list of persons +* Endpoint chill_person_search +* method GET, get a list of persons * * @query string - the query to search for */ let searchPersons = ({ query, options }) => { - console.log('options 2', options); - let url = `/${locale}/search.${format}?name=person_regular&q=${query}`; + console.log('options', options); + let url = `/fr/search.json?name=person_regular&q=${query}`; return fetch(url) .then(response => { if (response.ok) { return response.json(); } @@ -18,4 +14,22 @@ let searchPersons = ({ query, options }) => { }); }; -export { searchPersons }; +/* +* Endpoint v.2 chill_main_search_global +* method GET, get a list of persons and thirdparty +* +* NOTE: this is a temporary WIP endpoint, return inconsistent random results +* @query string - the query to search for +*/ +let searchPersons_2 = ({ query, options }) => { + console.log('options', options); + let url = `/api/1.0/search.json?q=${query}` + return fetch(url) + .then(response => { + if (response.ok) { return response.json(); } + throw Error('Error with request resource response'); + }); +}; + + +export { searchPersons, searchPersons_2 };