lab2: fix review — cache consistency, readiness, timeouts, uuid validation, tuple index
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/charawein/mtusi2026lab2/internal/domain"
|
||||
"github.com/charawein/mtusi2026lab2/internal/repository"
|
||||
)
|
||||
@@ -29,6 +31,9 @@ func (s *ChatService) Create(ctx context.Context, callerID, title string, member
|
||||
seen := make(map[string]struct{}, len(memberIDs))
|
||||
callerFound := false
|
||||
for _, id := range memberIDs {
|
||||
if _, err := uuid.Parse(id); err != nil {
|
||||
return nil, ErrInvalidInput
|
||||
}
|
||||
if _, dup := seen[id]; dup {
|
||||
return nil, ErrInvalidInput
|
||||
}
|
||||
@@ -63,6 +68,9 @@ func (s *ChatService) Create(ctx context.Context, callerID, title string, member
|
||||
}
|
||||
|
||||
func (s *ChatService) Get(ctx context.Context, callerID, chatID string) (*domain.Chat, error) {
|
||||
if _, err := uuid.Parse(chatID); err != nil {
|
||||
return nil, ErrInvalidInput
|
||||
}
|
||||
ok, err := s.chats.IsMember(ctx, chatID, callerID)
|
||||
if err != nil {
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
@@ -102,7 +110,6 @@ func (s *ChatService) List(ctx context.Context, callerID, cursor string, limit i
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
if items == nil {
|
||||
items = []*domain.Chat{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user