diff --git a/model.js b/model.js new file mode 100644 index 0000000..f077c59 --- /dev/null +++ b/model.js @@ -0,0 +1,19 @@ +function execQuery(table, filter = "all", id = -1){ + let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/" + let computeHttpRequest; + if(filter !== undefined){ + switch(table){ + case "songs": + computeHttpRequest = baseHttpRequest+table+"?title="+filter; + default : + computeHttpRequest = baseHttpRequest+table+"?name="+filter; + } + } else if(id !== undefined) { + computeHttpRequest = baseHttpRequest+table+"/"+id; + } else { + computeHttpRequest = baseHttpRequest+table; + } + return fetch(computeHttpRequest).then(response => { + return response.json(); + }); +}; \ No newline at end of file diff --git a/onzer.riot b/onzer.riot index f19e16c..f1e2d9e 100644 --- a/onzer.riot +++ b/onzer.riot @@ -11,7 +11,7 @@