From 85b1c63219cd59568841e39bdde07f23f5c1e729 Mon Sep 17 00:00:00 2001 From: Fauvet Matthis Date: Fri, 21 Jun 2024 19:38:47 +0200 Subject: [PATCH] added possibility to filter datas --- onzer.riot | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/onzer.riot b/onzer.riot index 9da8940..35199b6 100644 --- a/onzer.riot +++ b/onzer.riot @@ -75,6 +75,25 @@ this.artist_style = "isDeactivate"; this.song_style = "isDeactivate"; }, + execQuery(table, filter = undefined, id = undefined){ + 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(); + }); + } } -