Library/models/authors_delete.go

28 lines
500 B
Go
Raw Normal View History

package models
2017-11-08 09:55:17 +00:00
// DeleteAuthorByID deletes an author by its ID
2018-03-06 11:36:49 +00:00
func DeleteAuthorByID(id int64, doer *User) error {
// Check if the id is 0
if id == 0 {
return ErrIDCannotBeZero{}
}
// Delete the author
_, err := x.Id(id).Delete(&Author{})
if err != nil {
return err
}
// Delete all book relations associated with that author
2017-11-07 15:35:10 +00:00
_, err = x.Delete(&AuthorBook{AuthorID: id})
2018-03-06 11:36:49 +00:00
if err != nil {
return err
}
// Logging
err = logAction(ActionTypeAuthorDeleted, doer, id)
return err
2017-11-07 15:35:10 +00:00
}