diff --git a/frontend/src/components/BooksAddEdit.vue b/frontend/src/components/BooksAddEdit.vue
index 7a9439a..fb88d9c 100644
--- a/frontend/src/components/BooksAddEdit.vue
+++ b/frontend/src/components/BooksAddEdit.vue
@@ -6,7 +6,7 @@
{{ error.message }}
- {{ error.response.Message }}
+
{{ error.response.data.Message }}
@@ -20,7 +20,7 @@
@@ -218,64 +218,70 @@
this.addAuthorForm.splice(i, 1)
},
insertNewBook: function () {
- this.loading = true
+ if (this.book.Title === '') {
+ this.error = {message: 'Please provide at least a title.'}
+ } else {
+ this.loading = true
- // Add all newly created authors to it
- let as = this.newAuthors
+ // Add all newly created authors to it
+ let as = this.newAuthors
- for (const i in as) {
- this.book.Authors.push({
- ID: 0,
- Name: as[i]
- })
- }
-
- // Beautify all Authors aka split the names in forename and lastname
- for (const i in this.book.Authors) {
- let author = this.book.Authors[i].Name
- let firstname = ''
- let lastname = ''
-
- // Check if the name contains a space, if so split it up
- if ((new RegExp(' ')).test(author)) {
- let split = author.indexOf(' ')
- let splits = [author.slice(0, split), author.slice(split + 1)]
- firstname = splits[0]
- lastname = splits[1]
- } else {
- lastname = author
+ for (const i in as) {
+ this.book.Authors.push({
+ ID: 0,
+ Name: as[i]
+ })
}
- // Put it all together
- this.book.Authors[i] = {
- ID: this.book.Authors[i].ID,
- Forename: firstname,
- Lastname: lastname
- }
- }
+ // Beautify all Authors aka split the names in forename and lastname
+ for (const i in this.book.Authors) {
+ let author = this.book.Authors[i].Name
+ let firstname = ''
+ let lastname = ''
- // Finally Send it
- // If we want to newly insert it, make a different request
- if (this.edit) {
- HTTP.post('books/' + this.book.ID, {book: this.book})
- .then(response => {
- this.loading = false
- this.success = 'The book was successfully updated!'
- })
- .catch(e => {
- this.loading = false
- this.error = e
- })
- } else { // insert a new book
- HTTP.put('books', {book: this.book})
- .then(response => {
- this.loading = false
- this.success = 'The book was successfully inserted!'
- })
- .catch(e => {
- this.loading = false
- this.error = e
- })
+ // Check if the name contains a space, if so split it up
+ if ((new RegExp(' ')).test(author)) {
+ let split = author.indexOf(' ')
+ let splits = [author.slice(0, split), author.slice(split + 1)]
+ firstname = splits[0]
+ lastname = splits[1]
+ } else {
+ lastname = author
+ }
+
+ // Put it all together
+ this.book.Authors[i] = {
+ ID: this.book.Authors[i].ID,
+ Forename: firstname,
+ Lastname: lastname
+ }
+ }
+
+ // Finally Send it
+ // If we want to newly insert it, make a different request
+ if (this.edit) {
+ HTTP.post('books/' + this.book.ID, {book: this.book})
+ .then(response => {
+ this.loading = false
+ this.success = 'The book was successfully updated!'
+ this.error = ''
+ })
+ .catch(e => {
+ this.loading = false
+ this.error = e
+ })
+ } else { // insert a new book
+ HTTP.put('books', {book: this.book})
+ .then(response => {
+ this.loading = false
+ this.success = 'The book was successfully inserted!'
+ this.error = ''
+ })
+ .catch(e => {
+ this.loading = false
+ this.error = e
+ })
+ }
}
}
}
diff --git a/routes/api/v1/books_add.go b/routes/api/v1/books_add.go
index e04356b..f6ff44a 100644
--- a/routes/api/v1/books_add.go
+++ b/routes/api/v1/books_add.go
@@ -36,6 +36,11 @@ func BookAdd(c echo.Context) error {
}
}
+ // Check if we have at least a title
+ if bookToInsert.Title == "" {
+ return c.JSON(http.StatusBadRequest, models.Message{"You need at least a title to insert a new book!"})
+ }
+
// Insert the book
newBook, err := models.AddOrUpdateBook(bookToInsert)