feat: added delete endpoints for lists and list items

This commit is contained in:
2026-08-21 21:28:58 +02:00
parent a1ec7cc24a
commit c2912d8d79
5 changed files with 133 additions and 6 deletions
+82 -1
View File
@@ -47,7 +47,7 @@ func (h *ListHandler) CreateList(w http.ResponseWriter, r *http.Request) {
return
}
list, err := h.ListService.Create(ctx, authContext.UserID, payload.Name, payload.UserIDs)
list, err := h.ListService.CreateList(ctx, authContext.UserID, payload.Name, payload.UserIDs)
if err != nil {
slog.ErrorContext(ctx, "failed to create list", slog.Any("error", err))
response.Error(ctx, w, http.StatusInternalServerError, "failed to create list")
@@ -58,6 +58,46 @@ func (h *ListHandler) CreateList(w http.ResponseWriter, r *http.Request) {
response.JSON(ctx, w, http.StatusCreated, list)
}
// DeleteList handles the deletion of a list
//
// @Summary Delete list route
// @Description Deletes a list, cascading to user associations and items
// @Tags List
// @Accept json
// @Produce json
// @Param id path int true "List ID"
// @Success 204
// @Error 400 {object} response.ErrorResponse "failed to decode request url"
// @Error 500 {object} response.ErrorResponse "failed to delete list"
// @Router /lists/{id} [delete]
func (h *ListHandler) DeleteList(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
listID := r.PathValue("id")
if listID == "" {
slog.ErrorContext(ctx, "failed to read list id from path")
response.Error(ctx, w, http.StatusBadRequest, "failed to decode request url")
return
}
authContext, err := domain.GetAuthContext(ctx)
if err != nil {
slog.ErrorContext(ctx, "failed to get auth context", slog.Any("error", err))
response.Error(ctx, w, http.StatusInternalServerError, "failed to delete list")
return
}
err = h.ListService.DeleteList(ctx, authContext.UserID, listID)
if err != nil {
slog.ErrorContext(ctx, "failed to delete list", slog.Any("error", err))
response.Error(ctx, w, http.StatusInternalServerError, "failed to delete list")
return
}
slog.InfoContext(ctx, "deleted list successfully", slog.Any("list_id", listID))
response.Status(ctx, w, http.StatusNoContent)
}
// GetLists handles fetching lists for the current user
//
// @Summary Returns all lists of the user
@@ -226,6 +266,46 @@ func (h *ListHandler) CreateListItem(w http.ResponseWriter, r *http.Request) {
response.JSON(ctx, w, http.StatusCreated, item)
}
// DeleteListItem handles the deletion of a list item
//
// @Summary Delete list item route
// @Description Deletes an item
// @Tags List
// @Accept json
// @Produce json
// @Param id path int true "List Item ID"
// @Success 204
// @Error 400 {object} response.ErrorResponse "failed to decode request url"
// @Error 500 {object} response.ErrorResponse "failed to delete list item"
// @Router /lists/item/{id} [delete]
func (h *ListHandler) DeleteListItem(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
listItemID := r.PathValue("id")
if listItemID == "" {
slog.ErrorContext(ctx, "failed to read list item id from path")
response.Error(ctx, w, http.StatusBadRequest, "failed to decode request url")
return
}
authContext, err := domain.GetAuthContext(ctx)
if err != nil {
slog.ErrorContext(ctx, "failed to get auth context", slog.Any("error", err))
response.Error(ctx, w, http.StatusInternalServerError, "failed to delete list item")
return
}
err = h.ListService.DeleteListItem(ctx, authContext.UserID, listItemID)
if err != nil {
slog.ErrorContext(ctx, "failed to delete list item", slog.Any("error", err))
response.Error(ctx, w, http.StatusInternalServerError, "failed to delete list item")
return
}
slog.InfoContext(ctx, "deleted list item successfully", slog.Any("list_item_id", listItemID))
response.Status(ctx, w, http.StatusNoContent)
}
// UpdateListItem handles updating of a list item
//
// @Summary Update list item
@@ -274,6 +354,7 @@ func (h *ListHandler) UpdateListItem(w http.ResponseWriter, r *http.Request) {
// @Tags List
// @Accept json
// @Produce json
// @Param id path int true "List Item ID"
// @Param payload body request.SetListItemCompletedPayload true "Update list item is completed payload"
// @Success 204 {object} nil
// @Error 400 {object} response.ErrorResponse "failed to decode request url"