1
0

Implemented Delete methods on list

This commit is contained in:
konrad
2018-07-10 13:27:25 +02:00
committed by kolaente
parent b1de837c4f
commit c8622b0029
5 changed files with 52 additions and 14 deletions

View File

@ -63,7 +63,6 @@ func (c *CRUDWebHandler) UpdateWeb(ctx echo.Context) error {
}
// Get the ID
var err error
id, err := models.GetIntURLParam("id", ctx)
if err != nil {
return ctx.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
@ -109,4 +108,34 @@ func (c *CRUDWebHandler) CreateWeb(ctx echo.Context) error {
}
return ctx.JSON(http.StatusOK, c.CObject)
}
// DeleteWeb is the web handler to delete something
func (c *CRUDWebHandler) DeleteWeb(ctx echo.Context) error {
// Get the ID
id, err := models.GetIntURLParam("id", ctx)
if err != nil {
return ctx.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
}
// Check if the user has the right to delete
user, err := models.GetCurrentUser(ctx)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError)
}
err = c.CObject.Delete(id, &user)
if err != nil {
if models.IsErrNeedToBeListAdmin(err) {
return echo.NewHTTPError(http.StatusForbidden, "You need to be the list admin to delete a list.")
}
if models.IsErrListDoesNotExist(err) {
return echo.NewHTTPError(http.StatusNotFound, "This list does not exist.")
}
return echo.NewHTTPError(http.StatusInternalServerError)
}
return ctx.JSON(http.StatusOK, models.Message{"Successfully deleted."})
}