From e021affd2e3c4de72b1aafd2747d0aaf5563dd72 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 10 Nov 2017 16:57:55 +0100 Subject: [PATCH] Fully implemented method to delete books --- frontend/src/auth/index.js | 4 ++++ frontend/src/components/Books.vue | 26 +++++++++++++++++++++++--- frontend/src/http-common/index.js | 3 ++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/frontend/src/auth/index.js b/frontend/src/auth/index.js index 58ff291..f297e42 100644 --- a/frontend/src/auth/index.js +++ b/frontend/src/auth/index.js @@ -57,5 +57,9 @@ export default { return { 'Authorization': 'Bearer ' + localStorage.getItem('token') } + }, + + getToken () { + return localStorage.getItem('token') } } diff --git a/frontend/src/components/Books.vue b/frontend/src/components/Books.vue index 1a846f2..690f217 100644 --- a/frontend/src/components/Books.vue +++ b/frontend/src/components/Books.vue @@ -9,12 +9,19 @@
- An erro occured. + An error occured.
{{ error.message }} -
+ +
+ +
+
+ Success
+ {{ success }}
@@ -98,7 +105,8 @@ export default { ], loading: false, paginate: ['books'], - error: '' + error: '', + success: '' } }, created () { @@ -165,6 +173,18 @@ export default { }, deleteBook (obj) { console.log(obj.ID.content, 'delete') + HTTP.delete('books/' + obj.ID.content) + .then(response => { + console.log(response) + if (response.status === 200 && response.data.Message === 'success') { + this.success = 'The book was deleted successfully.' + this.loadBooks() + } + }) + .catch(e => { + // TODO: proper error handling + console.log(e) + }) }, editBook (id) { console.log(id, 'edit') diff --git a/frontend/src/http-common/index.js b/frontend/src/http-common/index.js index 40d5709..fde5214 100644 --- a/frontend/src/http-common/index.js +++ b/frontend/src/http-common/index.js @@ -1,8 +1,9 @@ import axios from 'axios' +// import auth from '../auth' export const HTTP = axios.create({ baseURL: `http://localhost:8082/api/v1/`, headers: { - Authorization: 'Bearer {token}' + 'Authorization': 'Bearer ' + localStorage.getItem('token') } })