cleanup
This commit is contained in:
parent
125f0ba230
commit
cf4871af59
3 changed files with 26 additions and 24 deletions
22
models/list_create_update.go
Normal file
22
models/list_create_update.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
list.OwnerID = list.Owner.ID
|
||||||
|
|
||||||
|
if list.ID == 0 {
|
||||||
|
_, err = x.Insert(list)
|
||||||
|
} else {
|
||||||
|
_, err = x.ID(list.ID).Update(list)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
|
@ -34,7 +34,7 @@ func GetListByID(id int64) (list List, err error) {
|
||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// GetListsByUser gets all lists a user owns
|
||||||
func GetListsByUser(user *User) (lists []*List, err error) {
|
func GetListsByUser(user *User) (lists []*List, err error) {
|
||||||
fullUser, _, err := GetUserByID(user.ID)
|
fullUser, _, err := GetUserByID(user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -52,24 +52,3 @@ func GetListsByUser(user *User) (lists []*List, err error) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
list.OwnerID = list.Owner.ID
|
|
||||||
|
|
||||||
if list.ID == 0 {
|
|
||||||
_, err = x.Insert(list)
|
|
||||||
} else {
|
|
||||||
_, err = x.ID(list.ID).Update(list)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo"
|
|
||||||
"git.kolaente.de/konrad/list/models"
|
"git.kolaente.de/konrad/list/models"
|
||||||
|
"github.com/labstack/echo"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetListsByUser gets all lists a user owns
|
||||||
func GetListsByUser(c echo.Context) error {
|
func GetListsByUser(c echo.Context) error {
|
||||||
|
|
||||||
currentUser, err := models.GetCurrentUser(c)
|
currentUser, err := models.GetCurrentUser(c)
|
||||||
|
|
Loading…
Add table
Reference in a new issue