vikunja-api/models/list_create_update.go

33 lines
533 B
Go
Raw Normal View History

2018-06-10 14:43:35 +02:00
package models
// CreateOrUpdateList updates a list or creates it if it doesn't exist
func CreateOrUpdateList(list *List) (err error) {
// Check if it exists
_, err = GetListByID(list.ID)
if err != nil {
return
}
2018-07-04 08:15:47 +02:00
// Check if the user exists
list.Owner, _, err = GetUserByID(list.Owner.ID)
if err != nil {
return
}
2018-06-10 14:43:35 +02:00
list.OwnerID = list.Owner.ID
if list.ID == 0 {
_, err = x.Insert(list)
} else {
_, err = x.ID(list.ID).Update(list)
2018-07-04 08:15:47 +02:00
}
if err != nil {
2018-06-10 14:43:35 +02:00
return
}
2018-07-04 08:15:47 +02:00
*list, err = GetListByID(list.ID)
2018-06-10 14:43:35 +02:00
return
}