Перенести чаты и сообщения в PostgreSQL

This commit is contained in:
2026-10-06 14:57:44 +03:00
parent 618d3919d1
commit 0b2db7eb2d
9 changed files with 559 additions and 499 deletions
+8 -3
View File
@@ -1,4 +1,4 @@
// Package chat is the chats module. Entities mirror future table rows and
// Package chat is the chats module. Entities mirror table rows and
// carry no behaviour; membership is a query rather than a field, and
// ChatWithMembers is the projection the API renders. Both entities derive
// CreatedAt from their UUIDv7 id, so the history order (created_at, id) is
@@ -6,7 +6,9 @@
package chat
import (
"bytes"
"fmt"
"slices"
"strings"
"time"
"unicode/utf8"
@@ -48,7 +50,8 @@ func NewChat(id uuid.UUID, title string) (Chat, error) {
}
// ValidateMembers checks the member list of a new chat and returns its own
// copy in the original order.
// copy ordered by id: members are a set, and this is the one order in which
// every read returns them.
func ValidateMembers(memberIDs []uuid.UUID, creator uuid.UUID) ([]uuid.UUID, error) {
if len(memberIDs) == 0 {
return nil, apperr.Invalid("member_ids must not be empty")
@@ -69,5 +72,7 @@ func ValidateMembers(memberIDs []uuid.UUID, creator uuid.UUID) ([]uuid.UUID, err
if _, ok := seen[creator]; !ok {
return nil, apperr.Invalid("member_ids must include the creator")
}
return append([]uuid.UUID(nil), memberIDs...), nil
members := slices.Clone(memberIDs)
slices.SortFunc(members, func(a, b uuid.UUID) int { return bytes.Compare(a[:], b[:]) })
return members, nil
}