At least a title is now required when inserting or updating a book
This commit is contained in:
parent
b45ceeb3e5
commit
8c487d17d6
|
@ -6,7 +6,7 @@
|
|||
</div>
|
||||
{{ error.message }}
|
||||
<template v-if="error.response">
|
||||
{{ error.response.Message }}
|
||||
<br/>{{ error.response.data.Message }}
|
||||
</template>
|
||||
</div>
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
|||
<form class="ui form" v-bind:class="{ loading: loading }" v-if="!success">
|
||||
<div class="field">
|
||||
<label>Title</label>
|
||||
<input name="title" placeholder="Title" type="text" v-model="book.Title">
|
||||
<input name="title" placeholder="Title" type="text" v-model="book.Title" required>
|
||||
</div>
|
||||
<div class="three fields">
|
||||
<div class="field">
|
||||
|
@ -100,7 +100,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<a class="ui button" type="submit" @click="insertNewBook()">Submit</a>
|
||||
<a class="ui blue button" type="submit" @click="insertNewBook()">Submit</a>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -218,6 +218,9 @@
|
|||
this.addAuthorForm.splice(i, 1)
|
||||
},
|
||||
insertNewBook: function () {
|
||||
if (this.book.Title === '') {
|
||||
this.error = {message: 'Please provide at least a title.'}
|
||||
} else {
|
||||
this.loading = true
|
||||
|
||||
// Add all newly created authors to it
|
||||
|
@ -261,6 +264,7 @@
|
|||
.then(response => {
|
||||
this.loading = false
|
||||
this.success = 'The book was successfully updated!'
|
||||
this.error = ''
|
||||
})
|
||||
.catch(e => {
|
||||
this.loading = false
|
||||
|
@ -271,6 +275,7 @@
|
|||
.then(response => {
|
||||
this.loading = false
|
||||
this.success = 'The book was successfully inserted!'
|
||||
this.error = ''
|
||||
})
|
||||
.catch(e => {
|
||||
this.loading = false
|
||||
|
@ -280,6 +285,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue