mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-02 00:24:13 -05:00
refactor/ router endpoint
This commit is contained in:
@@ -27,6 +27,17 @@ const apiReq = {
|
||||
return response;
|
||||
},
|
||||
|
||||
put: async function (url, data) {
|
||||
let response = await axios.put(url, data).catch(function (error) {
|
||||
if (error.response) {
|
||||
processResponse(error.response);
|
||||
return response;
|
||||
} else return;
|
||||
});
|
||||
// processResponse(response);
|
||||
return response;
|
||||
},
|
||||
|
||||
get: async function (url, data) {
|
||||
let response = await axios.get(url, data).catch(function (error) {
|
||||
if (error.response) {
|
||||
|
||||
@@ -6,11 +6,11 @@ const backupBase = baseURL + "backups/";
|
||||
|
||||
const backupURLs = {
|
||||
// Backup
|
||||
available: `${backupBase}available/`,
|
||||
createBackup: `${backupBase}export/database/`,
|
||||
importBackup: (fileName) => `${backupBase}${fileName}/import/`,
|
||||
deleteBackup: (fileName) => `${backupBase}${fileName}/delete/`,
|
||||
downloadBackup: (fileName) => `${backupBase}${fileName}/download/`,
|
||||
available: `${backupBase}available`,
|
||||
createBackup: `${backupBase}export/database`,
|
||||
importBackup: (fileName) => `${backupBase}${fileName}/import`,
|
||||
deleteBackup: (fileName) => `${backupBase}${fileName}/delete`,
|
||||
downloadBackup: (fileName) => `${backupBase}${fileName}/download`,
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
|
||||
const categoryBase = baseURL + "/recipes/categories";
|
||||
const prefix = baseURL + "/recipes/categories";
|
||||
|
||||
const categoryURLs = {
|
||||
get_all: `${categoryBase}/all/`,
|
||||
get_category: (category) => `${categoryBase}/${category}/`,
|
||||
get_all: `${prefix}/all`,
|
||||
get_category: (category) => `${prefix}/${category}`,
|
||||
delete_category: (category) => `${prefix}/${category}`,
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -17,4 +18,8 @@ export default {
|
||||
let response = await apiReq.get(categoryURLs.get_category(category));
|
||||
return response.data;
|
||||
},
|
||||
async delete(category) {
|
||||
let response = await apiReq.delete(categoryURLs.delete_category(category));
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
|
||||
const mealplanBase = baseURL + "meal-plan/";
|
||||
const prefix = baseURL + "meal-plans/";
|
||||
|
||||
const mealPlanURLs = {
|
||||
// Meals
|
||||
create: `${mealplanBase}create/`,
|
||||
today: `${mealplanBase}today/`,
|
||||
thisWeek: `${mealplanBase}this-week/`,
|
||||
all: `${mealplanBase}all/`,
|
||||
delete: (planID) => `${mealplanBase}${planID}/delete/`,
|
||||
update: (planID) => `${mealplanBase}${planID}/update/`,
|
||||
all: `${prefix}all`,
|
||||
create: `${prefix}create`,
|
||||
thisWeek: `${prefix}this-week`,
|
||||
update: (planID) => `${prefix}${planID}`,
|
||||
delete: (planID) => `${prefix}${planID}`,
|
||||
today: `${prefix}today`,
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -40,7 +40,7 @@ export default {
|
||||
},
|
||||
|
||||
async update(id, body) {
|
||||
let response = await apiReq.post(mealPlanURLs.update(id), body);
|
||||
let response = await apiReq.put(mealPlanURLs.update(id), body);
|
||||
return response;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -4,18 +4,17 @@ import { store } from "../store/store";
|
||||
import { router } from "../main";
|
||||
import qs from "qs";
|
||||
|
||||
const recipeBase = baseURL + "recipe/";
|
||||
const prefix = baseURL + "recipes/";
|
||||
|
||||
const recipeURLs = {
|
||||
// Recipes
|
||||
allRecipes: baseURL + "all-recipes/",
|
||||
recipe: (slug) => recipeBase + slug + "/",
|
||||
recipeImage: (slug) => recipeBase + "image/" + slug + "/",
|
||||
createByURL: recipeBase + "create-url/",
|
||||
create: recipeBase + "create/",
|
||||
updateImage: (slug) => `${recipeBase}${slug}/update/image/`,
|
||||
update: (slug) => `${recipeBase}${slug}/update/`,
|
||||
delete: (slug) => `${recipeBase}${slug}/delete/`,
|
||||
allRecipes: baseURL + "recipes",
|
||||
create: prefix + "create",
|
||||
createByURL: prefix + "create-url",
|
||||
recipe: (slug) => prefix + slug,
|
||||
update: (slug) => prefix + slug,
|
||||
delete: (slug) => prefix + slug,
|
||||
recipeImage: (slug) => `${prefix}${slug}/image`,
|
||||
updateImage: (slug) => `${prefix}${slug}/image`,
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -43,7 +42,7 @@ export default {
|
||||
fd.append("image", fileObject);
|
||||
fd.append("extension", fileObject.name.split(".").pop());
|
||||
|
||||
let response = apiReq.post(recipeURLs.updateImage(recipeSlug), fd);
|
||||
let response = apiReq.put(recipeURLs.updateImage(recipeSlug), fd);
|
||||
|
||||
return response;
|
||||
},
|
||||
@@ -51,7 +50,7 @@ export default {
|
||||
async update(data) {
|
||||
const recipeSlug = data.slug;
|
||||
|
||||
let response = await apiReq.post(recipeURLs.update(recipeSlug), data);
|
||||
let response = await apiReq.put(recipeURLs.update(recipeSlug), data);
|
||||
store.dispatch("requestRecentRecipes");
|
||||
return response.data;
|
||||
},
|
||||
|
||||
@@ -5,8 +5,8 @@ const settingsBase = baseURL + "site-settings/";
|
||||
|
||||
const settingsURLs = {
|
||||
siteSettings: `${settingsBase}`,
|
||||
updateSiteSettings: `${settingsBase}update/`,
|
||||
testWebhooks: `${settingsBase}webhooks/test/`,
|
||||
updateSiteSettings: `${settingsBase}`,
|
||||
testWebhooks: `${settingsBase}webhooks/test`,
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
},
|
||||
|
||||
async update(body) {
|
||||
let response = await apiReq.post(settingsURLs.updateSiteSettings, body);
|
||||
let response = await apiReq.put(settingsURLs.updateSiteSettings, body);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
|
||||
const themesBase = baseURL + "site-settings/";
|
||||
const prefix = baseURL + "themes/";
|
||||
|
||||
const settingsURLs = {
|
||||
allThemes: `${themesBase}themes/`,
|
||||
specificTheme: (themeName) => `${themesBase}themes/${themeName}/`,
|
||||
createTheme: `${themesBase}themes/create/`,
|
||||
updateTheme: (themeName) => `${themesBase}themes/${themeName}/update/`,
|
||||
deleteTheme: (themeName) => `${themesBase}themes/${themeName}/delete/`,
|
||||
allThemes: `${baseURL}themes`,
|
||||
specificTheme: (themeName) => `${prefix}themes/${themeName}`,
|
||||
createTheme: `${prefix}themes/create`,
|
||||
updateTheme: (themeName) => `${prefix}themes/${themeName}`,
|
||||
deleteTheme: (themeName) => `${prefix}themes/${themeName}`,
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -32,7 +32,7 @@ export default {
|
||||
name: themeName,
|
||||
colors: colors,
|
||||
};
|
||||
let response = await apiReq.post(settingsURLs.updateTheme(themeName), body);
|
||||
let response = await apiReq.put(settingsURLs.updateTheme(themeName), body);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user