fixed lint + fmt

This commit is contained in:
konrad 2018-06-10 14:22:37 +02:00 committed by kolaente
parent f372128784
commit 2cf20fe1c4
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 11 additions and 10 deletions

View file

@ -128,7 +128,6 @@ func (err ErrIDCannotBeZero) Error() string {
// List errors // List errors
// =========== // ===========
// ErrListDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist. // ErrListDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
type ErrListDoesNotExist struct { type ErrListDoesNotExist struct {
ID int64 ID int64

View file

@ -1,5 +1,6 @@
package models package models
// List represents a list of items
type List struct { type List struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"` ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
Title string `xorm:"varchar(250)" json:"title"` Title string `xorm:"varchar(250)" json:"title"`
@ -10,6 +11,7 @@ type List struct {
Updated int64 `xorm:"updated" json:"updated"` Updated int64 `xorm:"updated" json:"updated"`
} }
// GetListByID returns a list by its ID
func GetListByID(id int64) (list List, err error) { func GetListByID(id int64) (list List, err error) {
list.ID = id list.ID = id
exists, err := x.Get(&list) exists, err := x.Get(&list)
@ -32,6 +34,7 @@ func GetListByID(id int64) (list List, err error){
return list, nil return list, nil
} }
// CreateOrUpdateList updates a list or creates it if it doesn't exist
func CreateOrUpdateList(list *List) (err error) { func CreateOrUpdateList(list *List) (err error) {
// Check if it exists // Check if it exists
_, err = GetListByID(list.ID) _, err = GetListByID(list.ID)

View file

@ -1,13 +1,13 @@
package v1 package v1
import ( import (
"net/http"
"github.com/labstack/echo"
"git.kolaente.de/konrad/list/models" "git.kolaente.de/konrad/list/models"
"github.com/labstack/echo"
"net/http"
"strconv" "strconv"
"fmt"
) )
// AddOrUpdateList Adds or updates a new list
func AddOrUpdateList(c echo.Context) error { func AddOrUpdateList(c echo.Context) error {
// Get the list // Get the list
@ -36,9 +36,8 @@ func AddOrUpdateList(c echo.Context) error {
if err != nil { if err != nil {
if models.IsErrListDoesNotExist(err) { if models.IsErrListDoesNotExist(err) {
return c.JSON(http.StatusBadRequest, models.Message{"The list does not exist."}) 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."})
} }
} }