more optimization
This commit is contained in:
parent
237874eda6
commit
e97fa30202
3 changed files with 27 additions and 28 deletions
|
@ -36,34 +36,34 @@ func DeleteListByID(c echo.Context) error {
|
||||||
// "$ref": "#/responses/Message"
|
// "$ref": "#/responses/Message"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Check if we have our ID
|
// Check if we have our ID
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
// Make int
|
// Make int
|
||||||
itemID, err := strconv.ParseInt(id, 10, 64)
|
itemID, err := strconv.ParseInt(id, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
|
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."})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if models.IsErrListDoesNotExist(err) {
|
// Check if the user has the right to delete that list
|
||||||
return c.JSON(http.StatusNotFound, models.Message{"This list does not exist."})
|
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)
|
return echo.NewHTTPError(http.StatusNotImplemented)
|
||||||
|
|
|
@ -32,14 +32,13 @@ func Login(c echo.Context) error {
|
||||||
// "403":
|
// "403":
|
||||||
// "$ref": "#/responses/Message"
|
// "$ref": "#/responses/Message"
|
||||||
|
|
||||||
u := new(models.UserLogin)
|
u := models.UserLogin{}
|
||||||
if err := c.Bind(u); err != nil {
|
if err := c.Bind(&u); err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"Please provide a username and password."})
|
return c.JSON(http.StatusBadRequest, models.Message{"Please provide a username and password."})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check user
|
// Check user
|
||||||
user, err := models.CheckUserCredentials(u)
|
user, err := models.CheckUserCredentials(&u)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusUnauthorized, models.Message{"Wrong username or password."})
|
return c.JSON(http.StatusUnauthorized, models.Message{"Wrong username or password."})
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ import (
|
||||||
"github.com/labstack/echo/middleware"
|
"github.com/labstack/echo/middleware"
|
||||||
|
|
||||||
"git.kolaente.de/konrad/list/models"
|
"git.kolaente.de/konrad/list/models"
|
||||||
crud "git.kolaente.de/konrad/list/routes/crud"
|
|
||||||
apiv1 "git.kolaente.de/konrad/list/routes/api/v1"
|
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/api/v1/swagger" // for docs generation
|
||||||
|
"git.kolaente.de/konrad/list/routes/crud"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewEcho registers a new Echo instance
|
// NewEcho registers a new Echo instance
|
||||||
|
|
Loading…
Reference in a new issue