2018-07-16 08:18:15 +02:00
|
|
|
package models
|
|
|
|
|
2018-07-16 08:45:38 +02:00
|
|
|
// Delete deletes a team
|
2018-07-18 08:15:38 +02:00
|
|
|
func (t *Team) Delete() (err error) {
|
2018-07-16 08:18:15 +02:00
|
|
|
|
|
|
|
// Check if the team exists
|
2018-07-18 08:15:38 +02:00
|
|
|
_, err = GetTeamByID(t.ID)
|
2018-07-16 08:18:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the team
|
2018-07-18 08:15:38 +02:00
|
|
|
_, err = x.ID(t.ID).Delete(&Team{})
|
2018-07-16 08:18:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete team members
|
2018-07-18 08:15:38 +02:00
|
|
|
_, err = x.Where("team_id = ?", t.ID).Delete(&TeamMember{})
|
2018-07-16 08:18:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete team <-> namespace relations
|
2018-07-18 08:15:38 +02:00
|
|
|
_, err = x.Where("team_id = ?", t.ID).Delete(&TeamNamespace{})
|
2018-07-16 08:18:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete team <-> lists relations
|
2018-07-18 08:15:38 +02:00
|
|
|
_, err = x.Where("team_id = ?", t.ID).Delete(&TeamList{})
|
2018-07-16 08:18:15 +02:00
|
|
|
return
|
|
|
|
}
|