Create vuex modules for Films/Vehicles/Locations/People + Test adaptation

This commit is contained in:
2020-12-21 12:01:36 +01:00
parent d8cfe69fa0
commit fffbc87964
12 changed files with 172 additions and 95 deletions

View File

@@ -1,70 +1,7 @@
export const state = () => ({
films: [],
film: {},
location: {},
person: {},
vehicle: {}
});
export const state = () => ({});
export const mutations = {
setFilms: (state, films) => {
state.films = films;
},
setFilm: (state, film) => {
state.film = film;
},
setLocation: (state, location) => {
state.location = location;
},
setPerson: (state, person) => {
state.person = person;
},
setVehicle: (state, vehicle) => {
state.vehicle = vehicle;
}
};
export const mutations = {};
export const actions = {
async getFilms({ commit }) {
try {
const films = await this.$axios.$get("/api/films");
commit("setFilms", films);
} catch (e) {
throw Error("API Error occurred.");
}
},
async getFilm({ commit }, id) {
try {
const film = await this.$axios.$get(`/api/films/${id}`);
commit("setFilm", film);
} catch (e) {
throw Error("API Error occurred.");
}
},
async getLocation({ commit }, id) {
try {
const location = await this.$axios.$get(`/api/locations/${id}`);
commit("setLocation", location);
} catch (e) {
throw Error("API Error occurred.");
}
},
async getPerson({ commit }, id) {
try {
const person = await this.$axios.$get(`/api/people/${id}`);
commit("setPerson", person);
} catch (e) {
throw Error("API Error occurred.");
}
},
async getVehicle({ commit }, id) {
try {
const vehicle = await this.$axios.$get(`/api/vehicles/${id}`);
commit("setVehicle", vehicle);
} catch (e) {
throw Error("API Error occurred.");
}
}
};
export const actions = {};
export const getters = {};