diff --git a/src/stores/useFoodPreferenceStore.js b/src/stores/useFoodPreferenceStore.js new file mode 100644 index 0000000000000000000000000000000000000000..028f2cd981f181f9eeb5b4c6a22403e11e9130e4 --- /dev/null +++ b/src/stores/useFoodPreferenceStore.js @@ -0,0 +1,21 @@ +import {API} from "@/util/API" +import { defineStore} from "pinia"; + +export const useFoodPreferenceStore = defineStore("foodPreference", { + state: () => { + return { + foodPreferences: [], + }; + }, + persist: { + storage: localStorage, + }, + actions: { + fetchAllOptions() { + API.getFoodpreferences() + .then((foodPreferences) => { + this.foodPreferences = foodPreferences; + }) + } + } +}) \ No newline at end of file diff --git a/src/util/API.js b/src/util/API.js new file mode 100644 index 0000000000000000000000000000000000000000..aeb87801f419ddb6d31d55624c61b6f2232f7ce4 --- /dev/null +++ b/src/util/API.js @@ -0,0 +1,15 @@ +import axios from "axios"; +export const API = { + /** + * Fetches all available foodpreference options + */ + getFoodpreferences(){ + return axios.get(`${import.meta.env.VITE_BACKEND_URL}/foodpreferences`) + .then((response) => { + return response.data; + }).catch(() => { + throw new Error(); + }); + } + +}