summaryrefslogtreecommitdiff
path: root/store
diff options
context:
space:
mode:
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;
+ },
};