feat: added "IsUserInList" to list repository
This commit is contained in:
@@ -26,6 +26,7 @@ type ListRepository interface {
|
|||||||
CreateList(ctx context.Context, name string, userIDs []string) (*List, error)
|
CreateList(ctx context.Context, name string, userIDs []string) (*List, error)
|
||||||
AddUserToList(ctx context.Context, listID string, userID string) error
|
AddUserToList(ctx context.Context, listID string, userID string) error
|
||||||
RemoveUserFromList(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)
|
||||||
CreateListItem(ctx context.Context, listID string, title string) (*ListItem, error)
|
CreateListItem(ctx context.Context, listID string, title string) (*ListItem, error)
|
||||||
UpdateListItem(ctx context.Context, listItemID string, title string, isCompleted bool) error
|
UpdateListItem(ctx context.Context, listItemID string, title string, isCompleted bool) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,20 @@ func (r *ListRepo) RemoveUserFromList(ctx context.Context, listID string, userID
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *ListRepo) IsUserInList(ctx context.Context, listID string, userID string) (bool, error) {
|
||||||
|
var cnt int
|
||||||
|
|
||||||
|
err := r.db.QueryRowContext(ctx,
|
||||||
|
"SELECT COUNT(*) FROM list_users WHERE list_id = $1 AND user_id = $2",
|
||||||
|
listID, 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) {
|
func (r *ListRepo) CreateListItem(ctx context.Context, listID string, title string) (*domain.ListItem, error) {
|
||||||
l := &domain.ListItem{Title: title}
|
l := &domain.ListItem{Title: title}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user