Fixed a bug where a new quantity was inserted when it hasnt changed
the build was successful Details

This commit is contained in:
kolaente 2017-11-28 16:19:59 +01:00
parent c6ae207c9b
commit b56465e996
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 13 additions and 3 deletions

View File

@ -57,9 +57,19 @@ func GetQuantityByBook(book Book) (quantity int64, err error) {
// SetBookQuantity sets a new quantity for a book
func (book Book) setBookQuantity(quantity int64) (err error) {
q := Quantity{BookID: book.ID, Quantity: quantity}
_, err = x.Insert(q)
return err
// Check if the quantity already exists and only insert it if not
qty, err := GetQuantityByBook(book)
if err != nil {
return err
}
if qty != quantity {
q := Quantity{BookID: book.ID, Quantity: quantity}
_, err = x.Insert(q)
return err
}
return nil
}
// GetBookByID gets a Book by its ID