Library/models/publishers_delete.go

29 lines
584 B
Go
Raw Permalink Normal View History

package models
2017-11-08 09:55:17 +00:00
// DeletePublisherByID deletes a publisher by its ID
2018-03-06 11:36:49 +00:00
func DeletePublisherByID(id int64, doer *User) error {
// Check if the id is 0
if id == 0 {
return ErrIDCannotBeZero{}
}
// Delete the publisher
_, err := x.Id(id).Delete(&Publisher{})
if err != nil {
return err
}
// Set all publisher to 0 on all book with this publisher
2017-11-29 15:23:19 +00:00
_, err = x.Table("books").
2017-11-30 14:48:03 +00:00
Where("publisher_id = ?", id).
Update(map[string]interface{}{"publisher_id": 0})
2018-03-06 11:36:49 +00:00
if err != nil {
return err
}
// Logging
err = logAction(ActionTypePublisherDeleted, doer, id)
return err
2017-11-07 15:35:10 +00:00
}