Перенесите реализацию ЛР 4 на стенд ЛР 5

This commit is contained in:
2026-11-18 15:33:31 +03:00
parent 276dbdad8a
commit 911d97a77a
153 changed files with 17451 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
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)
}