Skip to content

Instantly share code, notes, and snippets.

@daviwesley
Created October 31, 2019 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviwesley/fbf32216ddf8fe1d45566d9521a2c280 to your computer and use it in GitHub Desktop.
Save daviwesley/fbf32216ddf8fe1d45566d9521a2c280 to your computer and use it in GitHub Desktop.
// service
import axios from "axios";
export const api = axios.create({
baseURL: `http://localhost:8080/api`
});
//
import { api } from "../service/";
deleteChapter(id_book, id_chapter) {
api.del(`/books/${id_book}/chapters/${id_chapter}`);
},
getOneChapter(state, id_book, id_chapter) {
api
.get(`/books/${id_book}/chapters/${id_chapter}`)
.then(chapters => (state.chapters = chapters));
},
createChapter(state, id_book, data) {
api
.post(`/books/${id_book}/chapters`, { data })
.then(res => (state.chapters = res))
.catch(e => (state.error = e));
},
changeChapter(id_book, id_chapter, data) {
api.put(`/books/${id_book}/chapters/${id_chapter}`, { data });
},
getAllChapter(state, id_book) {
api.get(`/books/${id_book}/chapters`).then(e => (state.chapters = e));
},
changeLoadingState(state, loading) {
state.loading = loading;
},
setError(state, error) {
state.error = error;
},
// Books
getAllBooks(state) {
api.get("/books").then(response => (state.books = response.data));
},
getOneBook(id_book) {
api.get(`/books/${id_book}`);
},
createBook(data) {
api.post("/books", { data });
},
deleteBook(id_book) {
api.delete(`/books/${id_book}`);
},
updateBook(id_book) {
api.put(`/books/${id_book}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment