From a7124c3a24890d1f4178b594c7d2d5ca580ef0a0 Mon Sep 17 00:00:00 2001 From: Laura Fuentes Grau Date: Sun, 10 Nov 2019 18:59:24 +0100 Subject: [PATCH] wip #210 frontend can now send url with query parameters to backend --- src/common/array-store.js | 17 ++++-- src/common/data-managers/rest-data-manager.js | 58 +++++++++++++++++-- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/common/array-store.js b/src/common/array-store.js index 1d76845..bb00c3c 100644 --- a/src/common/array-store.js +++ b/src/common/array-store.js @@ -71,10 +71,10 @@ class ArrayStore extends ReduceStore { if (Array.isArray(action.data)) { action.data.forEach((id) => { - this.dataManager.load(id, action.token); + this.dataManager.load(id, action.token,action.param); }); } else { - this.dataManager.load(action.data, action.token); + this.dataManager.load(action.data, action.token,action.param); } return state; @@ -99,7 +99,7 @@ class ArrayStore extends ReduceStore { return super.reduce(state, action); case this.type + '/start-add': - this.dataManager.add(action.data, action.token); + this.dataManager.add(action.data, action.token,action.param); return state; case this.type + '/added': @@ -111,7 +111,7 @@ class ArrayStore extends ReduceStore { case this.type + '/start-remove': - this.dataManager.remove(action.data, action.token); + this.dataManager.remove(action.data, action.token,action.param); return state; case this.type + '/removed': @@ -133,11 +133,11 @@ class ArrayStore extends ReduceStore { return super.reduce(state, action); case this.type + '/start-edit': - this.dataManager.update(action.data, action.token); + this.dataManager.update(action.data, action.token,action.param); return state; case this.type + '/start-own-edit': - this.dataManager.update(action.data, action.token); + this.dataManager.update(action.data, action.token,action.param); return state; case this.type + '/edited': @@ -155,6 +155,11 @@ class ArrayStore extends ReduceStore { case this.type + '/edit-error': return state; + case 'exdashboard/querytest' : + console.log("querytest wurde aufgerufen"); + this.dataManager.update(action.data, action.token,action.param); + return state; + default: return state; } diff --git a/src/common/data-managers/rest-data-manager.js b/src/common/data-managers/rest-data-manager.js index 65b904d..33f2de6 100644 --- a/src/common/data-managers/rest-data-manager.js +++ b/src/common/data-managers/rest-data-manager.js @@ -53,9 +53,53 @@ class RestDataManager { } load(id, token = null,param = null) { + if (param === null) { + if (id != null) { + // load single object + RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => { + const data = this.filterKeys(response[this.type]); + + AppDispatcher.dispatch({ + type: this.type + 's/loaded', + data: data + }); + + if (this.onLoad != null) { + this.onLoad(data); + } + }).catch(error => { + AppDispatcher.dispatch({ + type: this.type + 's/load-error', + error: error + }); + }); + } else { + // load all objects + RestAPI.get(this.makeURL(this.url), token).then(response => { + const data = response[this.type + 's'].map(element => { + return this.filterKeys(element); + }); + + AppDispatcher.dispatch({ + type: this.type + 's/loaded', + data: data + }); + + if (this.onLoad != null) { + this.onLoad(data); + } + }).catch(error => { + AppDispatcher.dispatch({ + type: this.type + 's/load-error', + error: error + }); + }); + } + } + else{ if (id != null) { // load single object - RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => { + RestAPI.get(this.makeURL(this.url + '/' + id + '/' + param), token).then(response => { const data = this.filterKeys(response[this.type]); AppDispatcher.dispatch({ @@ -74,7 +118,7 @@ class RestDataManager { }); } else { // load all objects - RestAPI.get(this.makeURL(this.url), token).then(response => { + RestAPI.get(this.makeURL(this.url) + '/' + param, token).then(response => { const data = response[this.type + 's'].map(element => { return this.filterKeys(element); }); @@ -94,6 +138,8 @@ class RestDataManager { }); }); } + + } } add(object, token = null, param = null) { @@ -115,7 +161,7 @@ class RestDataManager { } else{ console.log("else was called in add"); - RestAPI.post(this.makeURL(this.url) + "?" + param, obj, token).then(response => { + RestAPI.post(this.makeURL(this.url) + "/" + param, obj, token).then(response => { AppDispatcher.dispatch({ type: this.type + 's/added', data: response[this.type] @@ -145,7 +191,7 @@ class RestDataManager { }); } else{ - RestAPI.delete(this.makeURL(this.url + '/' + object.id + '?' + param), token).then(response => { + RestAPI.delete(this.makeURL(this.url + '/' + object.id + '/' + param), token).then(response => { AppDispatcher.dispatch({ type: this.type + 's/removed', data: response[this.type], @@ -163,6 +209,7 @@ class RestDataManager { update(object, token = null, param = null) { var obj = {}; obj[this.type] = this.filterKeys(object); + console.log("wir haben den rdm erreicht!"); if(param === null) { RestAPI.put(this.makeURL(this.url + '/' + object.id), obj, token).then(response => { @@ -178,7 +225,8 @@ class RestDataManager { }); } else{ - RestAPI.put(this.makeURL(this.url + '/' + object.id + '?' + param), obj, token).then(response => { + console.log("here we have: " + this.url); + RestAPI.put(this.makeURL(this.url + '/' + object.id + '/' + param), obj, token).then(response => { AppDispatcher.dispatch({ type: this.type + 's/edited', data: response[this.type]