feat: added db transactions abstraction; cleaned up user registration; repos adapted new abstraction: all repos now support transactions, if present in ctx

This commit is contained in:
2026-09-01 14:55:20 +02:00
parent f87b0a0707
commit 2e3e82e776
14 changed files with 219 additions and 145 deletions
+11 -6
View File
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"log/slog"
"slices"
"time"
)
@@ -36,7 +35,7 @@ type ListItem struct {
}
type ListRepository interface {
CreateList(ctx context.Context, name string, userIDs []string) (*List, error)
CreateList(ctx context.Context, name string) (*List, error)
DeleteList(ctx context.Context, listID string) error
GetLists(ctx context.Context, userID string) ([]List, error)
AddUserToList(ctx context.Context, listID string, userID string) error
@@ -58,16 +57,22 @@ func NewListService(r ListRepository) *ListService {
return &ListService{repo: r}
}
func (s *ListService) CreateList(ctx context.Context, authUserID string, name string, userIDs []string) (*List, error) {
func (s *ListService) CreateList(ctx context.Context, authUserID string, name string) (*List, error) {
if name == "" {
return nil, ErrListNameEmpty
}
if !slices.Contains(userIDs, authUserID) {
userIDs = append(userIDs, authUserID)
list, err := s.repo.CreateList(ctx, name)
if err != nil {
return nil, err
}
return s.repo.CreateList(ctx, name, userIDs)
err = s.repo.AddUserToList(ctx, list.ID, authUserID)
if err != nil {
return nil, err
}
return list, nil
}
func (s *ListService) DeleteList(ctx context.Context, authUserID string, listID string) error {