feat: added delete endpoints for lists and list items
This commit is contained in:
@@ -59,6 +59,15 @@ func (r *ListRepo) CreateList(ctx context.Context, name string, userIDs []string
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (r *ListRepo) DeleteList(ctx context.Context, listID string) error {
|
||||
_, err := r.db.ExecContext(ctx, "DELETE FROM lists WHERE id = $1", listID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete list: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ListRepo) GetLists(ctx context.Context, userID string) ([]domain.List, error) {
|
||||
rows, err := r.db.QueryContext(ctx,
|
||||
"SELECT l.id, l.name, l.created_at, l.modified_at, (SELECT COUNT(*) FROM list_items WHERE list_id=l.id), (SELECT COUNT(*) FROM list_items WHERE list_id=l.id AND is_completed=true) FROM lists AS l INNER JOIN list_users ON lists.id=list_users.list_id WHERE list_users.user_id = $1",
|
||||
@@ -153,6 +162,15 @@ func (r *ListRepo) CreateListItem(ctx context.Context, listID string, title stri
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func (r *ListRepo) DeleteListItem(ctx context.Context, listItemID string) error {
|
||||
_, err := r.db.ExecContext(ctx, "DELETE FROM list_items WHERE id = $1", listItemID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete list item: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ListRepo) UpdateListItem(ctx context.Context, listItemID string, title string, isCompleted bool) error {
|
||||
_, err := r.db.ExecContext(ctx, "UPDATE list_items SET title = $1, is_completed = $2, modified_at = NOW() WHERE id = $3",
|
||||
title, isCompleted, listItemID,
|
||||
|
||||
Reference in New Issue
Block a user