Enable adding/removing users to list as well as add/update list items #11

Merged
robin merged 15 commits from dev into main 2026-08-20 15:55:38 +02:00
2 changed files with 15 additions and 0 deletions
Showing only changes of commit d026fa4d7c - Show all commits
+1
View File
@@ -37,6 +37,7 @@ type ListRepository interface {
AddUserToList(ctx context.Context, listID string, userID string) error
RemoveUserFromList(ctx context.Context, listID string, userID string) error
IsUserInList(ctx context.Context, listID string, userID string) (bool, error)
IsUserInListByListItem(ctx context.Context, listItemID string, userID string) (bool, error)
CreateListItem(ctx context.Context, listID string, title string) (*ListItem, error)
UpdateListItem(ctx context.Context, listItemID string, title string, isCompleted bool) error
}
+14
View File
@@ -96,6 +96,20 @@ func (r *ListRepo) IsUserInList(ctx context.Context, listID string, userID strin
return cnt > 0, nil
}
func (r *ListRepo) IsUserInListByListItem(ctx context.Context, listItemID string, userID string) (bool, error) {
var cnt int
err := r.db.QueryRowContext(ctx,
"SELECT COUNT(*) FROM list_users WHERE list_id = (SELECT list_id FROM list_items WHERE id = $1) AND user_id = $2",
listItemID, userID,
).Scan(&cnt)
if err != nil {
return false, fmt.Errorf("failed to check if user is in list: %w", err)
}
return cnt > 0, nil
}
func (r *ListRepo) CreateListItem(ctx context.Context, listID string, title string) (*domain.ListItem, error) {
l := &domain.ListItem{Title: title}