Create vuex modules for Films/Vehicles/Locations/People + Test adaptation
This commit is contained in:
@@ -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 = {};
|
||||
|
||||
Reference in New Issue
Block a user