kolaente
3c08e18cd2
All checks were successful
the build was successful
+ Resolved quantity stuff - there now is a new table which links books or items to a quantity
30 lines
506 B
Go
30 lines
506 B
Go
package models
|
|
|
|
import "fmt"
|
|
|
|
// DeleteBookByID deletes a book by its ID
|
|
func DeleteBookByID(id int64) error {
|
|
// Check if the id is 0
|
|
if id == 0 {
|
|
return fmt.Errorf("ID cannot be 0")
|
|
}
|
|
|
|
// Delete the book
|
|
_, err := x.Id(id).Delete(&Book{})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Delete all authors associated with that book
|
|
_, err = x.Delete(&AuthorBook{BookID: id})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Delete all quantites for this book
|
|
_, err = x.Delete(&Quantity{ItemID: id})
|
|
|
|
return err
|
|
}
|