2018-08-30 18:52:12 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// Delete deletes a list <-> user relation
|
|
|
|
func (lu *ListUser) Delete() (err error) {
|
|
|
|
|
|
|
|
// Check if the user exists
|
2018-08-30 19:14:02 +02:00
|
|
|
_, err = GetUserByID(lu.UserID)
|
2018-08-30 18:52:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user has access to the list
|
|
|
|
has, err := x.Where("user_id = ? AND list_id = ?", lu.UserID, lu.ListID).
|
|
|
|
Get(&ListUser{})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !has {
|
|
|
|
return ErrUserDoesNotHaveAccessToList{ListID: lu.ListID, UserID: lu.UserID}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = x.Where("user_id = ? AND list_id = ?", lu.UserID, lu.ListID).
|
|
|
|
Delete(&ListUser{})
|
|
|
|
return
|
|
|
|
}
|