Implemented Delete methods on list
This commit is contained in:
@ -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."})
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
// "git.kolaente.de/konrad/list/models"
|
||||
"github.com/labstack/echo"
|
||||
// "net/http"
|
||||
// "strconv"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func DeleteListByID(c echo.Context) error {
|
||||
@ -33,6 +34,7 @@ func DeleteListByID(c echo.Context) error {
|
||||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
/*
|
||||
// Check if we have our ID
|
||||
id := c.Param("id")
|
||||
// Make int
|
||||
@ -47,7 +49,7 @@ func DeleteListByID(c echo.Context) error {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
|
||||
err = models.DeleteListByID(itemID, &user)
|
||||
// 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."})
|
||||
@ -61,4 +63,7 @@ func DeleteListByID(c echo.Context) error {
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, models.Message{"The list was deleted with success."})
|
||||
*/
|
||||
|
||||
return echo.NewHTTPError(http.StatusNotImplemented)
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func RegisterRoutes(e *echo.Echo) {
|
||||
a.GET("/lists/:id", listHandler.ReadOneWeb)
|
||||
a.POST("/lists/:id", listHandler.UpdateWeb)
|
||||
a.PUT("/lists/:id", apiv1.AddListItem)
|
||||
a.DELETE("/lists/:id", apiv1.DeleteListByID)
|
||||
a.DELETE("/lists/:id", listHandler.DeleteWeb)
|
||||
|
||||
a.DELETE("/item/:id", apiv1.DeleteListItemByIDtemByID)
|
||||
a.POST("/item/:id", apiv1.UpdateListItem)
|
||||
|
Reference in New Issue
Block a user