lab2: fix review round 2 — cache versioning, UUID normalization, cursor validation, ready deps
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-10 07:46:39 +03:00
parent 40f260612f
commit 6e3515d71b
8 changed files with 160 additions and 57 deletions
+17 -3
View File
@@ -28,16 +28,27 @@ func (s *ChatService) Create(ctx context.Context, callerID, title string, member
return nil, ErrInvalidInput
}
// Нормализация UUID: убираем разницу регистра.
normalized := make([]string, 0, len(memberIDs))
seen := make(map[string]struct{}, len(memberIDs))
callerFound := false
callerParsed, err := uuid.Parse(callerID)
if err != nil {
return nil, ErrInvalidInput
}
callerID = callerParsed.String()
for _, id := range memberIDs {
if _, err := uuid.Parse(id); err != nil {
parsed, err := uuid.Parse(id)
if err != nil {
return nil, ErrInvalidInput
}
id = parsed.String()
if _, dup := seen[id]; dup {
return nil, ErrInvalidInput
}
seen[id] = struct{}{}
normalized = append(normalized, id)
if id == callerID {
callerFound = true
}
@@ -58,7 +69,7 @@ func (s *ChatService) Create(ctx context.Context, callerID, title string, member
c := &domain.Chat{
ID: newID(),
Title: title,
MemberIDs: memberIDs,
MemberIDs: normalized,
CreatedAt: nowUTC(),
}
if err := s.chats.Create(ctx, c); err != nil {
@@ -68,9 +79,12 @@ 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 {
parsed, err := uuid.Parse(chatID)
if err != nil {
return nil, ErrInvalidInput
}
chatID = parsed.String()
ok, err := s.chats.IsMember(ctx, chatID, callerID)
if err != nil {
if errors.Is(err, repository.ErrNotFound) {