32 lines
1.4 KiB
Go
32 lines
1.4 KiB
Go
package chat
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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 {
|
|
Append(ctx context.Context, message Message) 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)
|
|
}
|