From cf4871af59ed2cbaf55ca693c17acdfd86c53b47 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 10 Jun 2018 14:43:35 +0200 Subject: [PATCH] cleanup --- models/list_create_update.go | 22 ++++++++++++++++++++++ models/lists.go | 23 +---------------------- routes/api/v1/lists_list.go | 5 +++-- 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 models/list_create_update.go diff --git a/models/list_create_update.go b/models/list_create_update.go new file mode 100644 index 00000000000..ac8ad90c4c0 --- /dev/null +++ b/models/list_create_update.go @@ -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 + +} diff --git a/models/lists.go b/models/lists.go index a96eb60e08e..de09b99ba78 100644 --- a/models/lists.go +++ b/models/lists.go @@ -34,7 +34,7 @@ func GetListByID(id int64) (list List, err error) { return list, nil } -// +// GetListsByUser gets all lists a user owns func GetListsByUser(user *User) (lists []*List, err error) { fullUser, _, err := GetUserByID(user.ID) if err != nil { @@ -52,24 +52,3 @@ func GetListsByUser(user *User) (lists []*List, err error) { 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 - -} diff --git a/routes/api/v1/lists_list.go b/routes/api/v1/lists_list.go index 7dffb257c09..2789a8e557a 100644 --- a/routes/api/v1/lists_list.go +++ b/routes/api/v1/lists_list.go @@ -1,11 +1,12 @@ package v1 import ( - "github.com/labstack/echo" "git.kolaente.de/konrad/list/models" + "github.com/labstack/echo" "net/http" ) +// GetListsByUser gets all lists a user owns func GetListsByUser(c echo.Context) error { currentUser, err := models.GetCurrentUser(c) @@ -19,4 +20,4 @@ func GetListsByUser(c echo.Context) error { } return c.JSON(http.StatusOK, allLists) -} \ No newline at end of file +}