42 lines
905 B
JavaScript
42 lines
905 B
JavaScript
export const state = () => ({
|
|
list: [],
|
|
film: {}
|
|
});
|
|
|
|
export const mutations = {
|
|
setList: (state, films) => {
|
|
state.list = films;
|
|
},
|
|
setFilm: (state, film) => {
|
|
state.film = film;
|
|
}
|
|
};
|
|
|
|
export const actions = {
|
|
async getList({ commit }) {
|
|
try {
|
|
const films = await this.$axios.$get(
|
|
"/api/films?fields=id,title,release_date,director,description,rt_score"
|
|
);
|
|
commit("setList", films);
|
|
} catch (e) {
|
|
throw Error(`API Error occurred: ${e.message}`);
|
|
}
|
|
},
|
|
async getFilm({ commit }, id) {
|
|
try {
|
|
const film = await this.$axios.$get(
|
|
`/api/films/${id}?fields=id,title,release_date,director,description,rt_score`
|
|
);
|
|
commit("setFilm", film);
|
|
} catch (e) {
|
|
throw Error(`API Error occurred: ${e.message}`);
|
|
}
|
|
}
|
|
};
|
|
|
|
export const getters = {
|
|
list: state => state.list,
|
|
film: state => state.film
|
|
};
|