Fixed a bug where a new quantity was inserted when it hasnt changed
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
c6ae207c9b
commit
b56465e996
|
@ -57,9 +57,19 @@ func GetQuantityByBook(book Book) (quantity int64, err error) {
|
||||||
|
|
||||||
// SetBookQuantity sets a new quantity for a book
|
// SetBookQuantity sets a new quantity for a book
|
||||||
func (book Book) setBookQuantity(quantity int64) (err error) {
|
func (book Book) setBookQuantity(quantity int64) (err error) {
|
||||||
q := Quantity{BookID: book.ID, Quantity: quantity}
|
// Check if the quantity already exists and only insert it if not
|
||||||
_, err = x.Insert(q)
|
qty, err := GetQuantityByBook(book)
|
||||||
return err
|
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
|
// GetBookByID gets a Book by its ID
|
||||||
|
|
Loading…
Reference in New Issue