summaryrefslogtreecommitdiff
path: root/store
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-10-04 11:45:14 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-10-04 11:45:14 +0200
commitefcd1ff3cc277c440d3c6523637d07dfd919ffda (patch)
tree6b99274e34376f6d56c4e65facc9edb0f9656b1a /store
parent839b692bf605bfaae565b0d180c5da7a6d7f4d5c (diff)
Like a model
Diffstat (limited to 'store')
-rw-r--r--store/models.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/store/models.js b/store/models.js
index 04717f2..890ba8c 100644
--- a/store/models.js
+++ b/store/models.js
@@ -201,4 +201,58 @@ export const actions = {
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;
+ },
};