From efcd1ff3cc277c440d3c6523637d07dfd919ffda Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 4 Oct 2022 11:45:14 +0200 Subject: Like a model --- store/models.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'store') diff --git a/store/models.js b/store/models.js index 04717f2..890ba8c 100644 --- a/store/models.js +++ b/store/models.js @@ -199,6 +199,60 @@ export const actions = { commit("loadingStatus", false, { root: true }); + return res; + }, + // Add like to a model + async addLike({ commit, rootGetters }, model_id) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/models/${model_id}/like`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + }) + .then(async (response) => { + res.status = response.status; + if (res.status != 201) { + res.data = await response.json(); + } + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + + return res; + }, + // Remove a like from a model + async removeLike({ commit, rootGetters }, model_id) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/models/${model_id}/like`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + }) + .then(async (response) => { + res.status = response.status; + if (res.status != 204) { + res.data = await response.json(); + } + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + return res; }, }; -- cgit v1.2.3-18-g5258