39 lines
629 B
Go
39 lines
629 B
Go
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
|
|
}
|