2018-06-12 18:17:21 +02:00
|
|
|
package models
|
|
|
|
|
2018-06-12 18:46:59 +02:00
|
|
|
func DeleteListByID(listID int64, doer *User) (err error) {
|
2018-06-12 18:17:21 +02:00
|
|
|
|
|
|
|
// Check if the list exists
|
2018-06-12 18:46:59 +02:00
|
|
|
list, err := GetListByID(listID)
|
2018-06-12 18:17:21 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-12 18:46:59 +02:00
|
|
|
if list.Owner.ID != doer.ID {
|
2018-07-09 23:17:19 +02:00
|
|
|
return ErrNeedToBeListAdmin{ListID: listID, UserID: doer.ID}
|
2018-06-12 18:46:59 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 18:17:21 +02:00
|
|
|
// Delete the list
|
|
|
|
_, err = x.ID(listID).Delete(&List{})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all todoitems on that list
|
|
|
|
_, err = x.Where("list_id = ?", listID).Delete(&ListItem{})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|