lab1
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Chat struct {
|
||||
ID uuid.UUID
|
||||
Title string
|
||||
MemberIDs []uuid.UUID
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (c Chat) HasMember(userID uuid.UUID) bool {
|
||||
return slices.Contains(c.MemberIDs, userID)
|
||||
}
|
||||
|
||||
type ChatDraft struct {
|
||||
Title string
|
||||
MemberIDs []uuid.UUID
|
||||
CallerID uuid.UUID
|
||||
}
|
||||
|
||||
func (d ChatDraft) Validate() error {
|
||||
if err := validateNotBlank("title", d.Title); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !slices.Contains(d.MemberIDs, d.CallerID) {
|
||||
return fmt.Errorf("member_ids must contain the caller: %w", ErrValidation)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user