From 2cf20fe1c48abf0b725ec521563494e7491920be Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 10 Jun 2018 14:22:37 +0200 Subject: [PATCH] fixed lint + fmt --- models/error.go | 5 ++--- models/lists.go | 5 ++++- routes/api/v1/lists_add_update.go | 11 +++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/models/error.go b/models/error.go index 4c2bdf53785..393ca928480 100644 --- a/models/error.go +++ b/models/error.go @@ -128,9 +128,8 @@ func (err ErrIDCannotBeZero) Error() string { // List errors // =========== - // ErrListDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist. -type ErrListDoesNotExist struct{ +type ErrListDoesNotExist struct { ID int64 } @@ -142,4 +141,4 @@ func IsErrListDoesNotExist(err error) bool { func (err ErrListDoesNotExist) Error() string { return fmt.Sprintf("List does not exist [ID: %d]", err.ID) -} \ No newline at end of file +} diff --git a/models/lists.go b/models/lists.go index 957e0f6e139..35224a5f2b8 100644 --- a/models/lists.go +++ b/models/lists.go @@ -1,5 +1,6 @@ package models +// List represents a list of items type List struct { ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"` Title string `xorm:"varchar(250)" json:"title"` @@ -10,7 +11,8 @@ type List struct { Updated int64 `xorm:"updated" json:"updated"` } -func GetListByID(id int64) (list List, err error){ +// GetListByID returns a list by its ID +func GetListByID(id int64) (list List, err error) { list.ID = id exists, err := x.Get(&list) if err != nil { @@ -32,6 +34,7 @@ func GetListByID(id int64) (list List, err error){ return list, nil } +// 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) diff --git a/routes/api/v1/lists_add_update.go b/routes/api/v1/lists_add_update.go index 734c8974182..b14cab23f83 100644 --- a/routes/api/v1/lists_add_update.go +++ b/routes/api/v1/lists_add_update.go @@ -1,13 +1,13 @@ package v1 import ( - "net/http" - "github.com/labstack/echo" "git.kolaente.de/konrad/list/models" + "github.com/labstack/echo" + "net/http" "strconv" - "fmt" ) +// AddOrUpdateList Adds or updates a new list func AddOrUpdateList(c echo.Context) error { // Get the list @@ -36,9 +36,8 @@ func AddOrUpdateList(c echo.Context) error { if err != nil { if models.IsErrListDoesNotExist(err) { return c.JSON(http.StatusBadRequest, models.Message{"The list does not exist."}) - } else { - return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the list exists."}) } + return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the list exists."}) } } @@ -72,4 +71,4 @@ func AddOrUpdateList(c echo.Context) error { } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +}