lab2: fix review — cache consistency, readiness, timeouts, uuid validation, tuple index
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-10 01:14:56 +03:00
parent a327909856
commit 40f260612f
21 changed files with 185 additions and 189 deletions
+8 -1
View File
@@ -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{}
}