diff --git a/models/authors_delete.go b/models/authors_delete.go index 5c7c1f1..e11edd3 100644 --- a/models/authors_delete.go +++ b/models/authors_delete.go @@ -1,7 +1,14 @@ package models +import "fmt" + // DeleteAuthorByID deletes an author by its ID func DeleteAuthorByID(id int64) error { + // Check if the id is 0 + if id == 0 { + return fmt.Errorf("ID cannot be 0") + } + // Delete the author _, err := x.Id(id).Delete(&Author{}) diff --git a/models/books_delete.go b/models/books_delete.go index f48facf..600e025 100644 --- a/models/books_delete.go +++ b/models/books_delete.go @@ -1,7 +1,14 @@ 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{}) diff --git a/models/publishers_delete.go b/models/publishers_delete.go index 6ad8c5b..d7f6cf1 100644 --- a/models/publishers_delete.go +++ b/models/publishers_delete.go @@ -1,7 +1,14 @@ package models +import "fmt" + // DeletePublisherByID deletes a publisher by its ID func DeletePublisherByID(id int64) error { + // Check if the id is 0 + if id == 0 { + return fmt.Errorf("ID cannot be 0") + } + // Delete the publisher _, err := x.Id(id).Delete(&Publisher{})