Files
mtusi2026lab7/internal/chat/repository.go
T
kudesn1k 8054913ef9
Application / e2e (pull_request) Blocked by required conditions
Application / unit (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Перенеси реализацию мессенджера из ЛР 6
Источник — проверенное рабочее дерево ЛР 6 поверх 18878d6, включая изменения после повторного ревью. SHA-256 списка исходных файлов: e45a3d85b41feff1da78dce3f20fd1f4af1c5ee629e6ed703218bc8e21ad58fe.
2026-11-30 10:54:41 +03:00

37 lines
1.7 KiB
Go

package chat
import (
"context"
"time"
"github.com/google/uuid"
)
// ChatRepository stores chats and their membership. Membership is answered
// by queries; the projection with members is assembled by the store in one
// query, never by loading a member list into the entity. Members are always
// returned ordered by id.
type ChatRepository interface {
// Create stores the chat row and its members atomically.
Create(ctx context.Context, chat Chat, memberIDs []uuid.UUID) error
// GetForMember returns the chat with members, or ErrNotFound when the
// chat does not exist or the user is not a member.
GetForMember(ctx context.Context, chatID, userID uuid.UUID) (ChatWithMembers, error)
IsMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error)
// ListByMember returns up to limit chats of the user ordered by
// (created_at, id), strictly after the chat identified by after when set.
ListByMember(ctx context.Context, userID uuid.UUID, after *uuid.UUID, limit int) ([]ChatWithMembers, error)
}
type MessageRepository interface {
// AppendOnce stores message under the sender's key unless the key was
// used in this chat within ttl, and returns the message the key is bound
// to: the given one or the earlier one.
AppendOnce(ctx context.Context, message Message, key string, ttl time.Duration) (Message, error)
DeleteExpiredKeys(ctx context.Context, olderThan time.Duration, limit int) (int64, error)
// ListByChat returns up to limit messages ordered by (created_at, id),
// strictly after the message identified by after when set. An unknown
// chat yields an empty history.
ListByChat(ctx context.Context, chatID uuid.UUID, after *uuid.UUID, limit int) ([]Message, error)
}