more optimization

This commit is contained in:
konrad 2018-07-11 00:28:53 +02:00 committed by kolaente
parent 237874eda6
commit e97fa30202
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 27 additions and 28 deletions

View file

@ -36,34 +36,34 @@ func DeleteListByID(c echo.Context) error {
// "$ref": "#/responses/Message"
/*
// Check if we have our ID
id := c.Param("id")
// Make int
itemID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
}
// Check if the user has the right to delete that list
user, err := models.GetCurrentUser(c)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
// err = models.DeleteListByID(itemID, &user)
if err != nil {
if models.IsErrNeedToBeListAdmin(err) {
return c.JSON(http.StatusForbidden, models.Message{"You need to be the list owner to delete a list."})
// Check if we have our ID
id := c.Param("id")
// Make int
itemID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
}
if models.IsErrListDoesNotExist(err) {
return c.JSON(http.StatusNotFound, models.Message{"This list does not exist."})
// Check if the user has the right to delete that list
user, err := models.GetCurrentUser(c)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
// err = models.DeleteListByID(itemID, &user)
if err != nil {
if models.IsErrNeedToBeListAdmin(err) {
return c.JSON(http.StatusForbidden, models.Message{"You need to be the list owner to delete a list."})
}
return c.JSON(http.StatusOK, models.Message{"The list was deleted with success."})
if models.IsErrListDoesNotExist(err) {
return c.JSON(http.StatusNotFound, models.Message{"This list does not exist."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
return c.JSON(http.StatusOK, models.Message{"The list was deleted with success."})
*/
return echo.NewHTTPError(http.StatusNotImplemented)

View file

@ -32,14 +32,13 @@ func Login(c echo.Context) error {
// "403":
// "$ref": "#/responses/Message"
u := new(models.UserLogin)
if err := c.Bind(u); err != nil {
u := models.UserLogin{}
if err := c.Bind(&u); err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Please provide a username and password."})
}
// Check user
user, err := models.CheckUserCredentials(u)
user, err := models.CheckUserCredentials(&u)
if err != nil {
return c.JSON(http.StatusUnauthorized, models.Message{"Wrong username or password."})
}

View file

@ -31,9 +31,9 @@ import (
"github.com/labstack/echo/middleware"
"git.kolaente.de/konrad/list/models"
crud "git.kolaente.de/konrad/list/routes/crud"
apiv1 "git.kolaente.de/konrad/list/routes/api/v1"
_ "git.kolaente.de/konrad/list/routes/api/v1/swagger" // for docs generation
"git.kolaente.de/konrad/list/routes/crud"
)
// NewEcho registers a new Echo instance