diff --git a/Featurecreep.md b/Featurecreep.md index 0c6157b3fb..5358c60770 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -38,11 +38,15 @@ Ab v0.3 können wir mit clients anfangen. * [ ] Todopunkte hinzufügen/abhaken/löschen * [x] Erstellen * [ ] Bearbeiten (abhaken) - * [ ] Löschen + * [x] Löschen #### v0.2 * [ ] Listen teilbar + * [ ] Mit anderen Nutzern + * [ ] Mit Link + * [ ] Offen + * [ ] Passwortgeschützt #### v0.3 diff --git a/models/list_items.go b/models/list_items.go index 7ab020664a..597c7ead68 100644 --- a/models/list_items.go +++ b/models/list_items.go @@ -64,3 +64,10 @@ func GetItemsByListID(listID int64) (items []*ListItem, err error) { return } + +// DeleteListItemByID deletes a list item by its ID +func DeleteListItemByIDtemByID(itemID int64) (err error) { + _, err = x.ID(itemID).Delete(ListItem{}) + + return +} diff --git a/routes/api/v1/item_delete.go b/routes/api/v1/item_delete.go new file mode 100644 index 0000000000..04bef7943c --- /dev/null +++ b/routes/api/v1/item_delete.go @@ -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."}) +} \ No newline at end of file diff --git a/routes/routes.go b/routes/routes.go index 16ff3432dc..4563232359 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -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) }