Added method to delete a todo item from a list
This commit is contained in:
25
routes/api/v1/item_delete.go
Normal file
25
routes/api/v1/item_delete.go
Normal file
@ -0,0 +1,25 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"strconv"
|
||||
"net/http"
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
)
|
||||
|
||||
func DeleteListItemByIDtemByID(c echo.Context) error {
|
||||
// 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."})
|
||||
}
|
||||
|
||||
err = models.DeleteListItemByIDtemByID(itemID)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, models.Message{"The item was deleted with success."})
|
||||
}
|
@ -58,4 +58,6 @@ func RegisterRoutes(e *echo.Echo) {
|
||||
a.GET("/lists/:id", apiv1.GetListByID)
|
||||
a.POST("/lists/:id", apiv1.AddOrUpdateList)
|
||||
a.PUT("/lists/:id", apiv1.AddOrUpdateListItem)
|
||||
|
||||
a.DELETE("/item/:id", apiv1.DeleteListItemByIDtemByID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user