lab2
This commit is contained in:
+14
-1
@@ -30,7 +30,20 @@ func (d ChatDraft) Validate() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !slices.Contains(d.MemberIDs, d.CallerID) {
|
||||
if len(d.MemberIDs) == 0 {
|
||||
return fmt.Errorf("member_ids must not be empty: %w", ErrValidation)
|
||||
}
|
||||
|
||||
seen := make(map[uuid.UUID]struct{}, len(d.MemberIDs))
|
||||
for _, id := range d.MemberIDs {
|
||||
if _, ok := seen[id]; ok {
|
||||
return fmt.Errorf("member_ids contains duplicates: %w", ErrValidation)
|
||||
}
|
||||
|
||||
seen[id] = struct{}{}
|
||||
}
|
||||
|
||||
if _, ok := seen[d.CallerID]; !ok {
|
||||
return fmt.Errorf("member_ids must contain the caller: %w", ErrValidation)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user