forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Package store defines typed persistence operations and storage errors.
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/model/dto"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnavailable means a required storage dependency cannot serve the operation.
|
||||
ErrUnavailable = errors.New("storage unavailable")
|
||||
|
||||
// ErrNotFound means a record does not exist.
|
||||
ErrNotFound = errors.New("record not found")
|
||||
|
||||
// ErrConflict means a unique constraint failed.
|
||||
ErrConflict = errors.New("record already exists")
|
||||
|
||||
// ErrCapacity means the bounded store cannot accept more data.
|
||||
ErrCapacity = errors.New("storage capacity reached")
|
||||
)
|
||||
|
||||
// Interface defines persistence operations on validated typed records.
|
||||
// Implementations own atomicity, unique constraints and storage capacity, but not
|
||||
// authorization. Callers must validate membership before accessing chat records.
|
||||
type Interface interface {
|
||||
// CreateUser atomically enforces username uniqueness and assigns CreatedAt.
|
||||
CreateUser(ctx context.Context, user dto.UserDTO) (dto.UserDTO, error)
|
||||
|
||||
// User returns a user by ID or ErrNotFound.
|
||||
User(ctx context.Context, id uuid.UUID) (dto.UserDTO, error)
|
||||
|
||||
// UsersExist reports whether every supplied ID exists; an empty set returns true.
|
||||
UsersExist(ctx context.Context, ids []uuid.UUID) (bool, error)
|
||||
|
||||
// CreateChat atomically stores a chat and its member indexes, assigning CreatedAt.
|
||||
CreateChat(ctx context.Context, chat dto.ChatDTO) (dto.ChatDTO, error)
|
||||
|
||||
// Chat returns a defensive copy of the stored chat or ErrNotFound.
|
||||
Chat(ctx context.Context, id uuid.UUID) (dto.ChatDTO, error)
|
||||
|
||||
// Chats reads up to limit records after position from the user's chat index.
|
||||
Chats(ctx context.Context, userID uuid.UUID, position dto.PositionDTO, limit int) ([]dto.ChatDTO, error)
|
||||
|
||||
// CreateMessage appends one message atomically and assigns its ordering timestamp.
|
||||
CreateMessage(ctx context.Context, message dto.MessageDTO) (dto.MessageDTO, error)
|
||||
|
||||
// Messages reads up to limit records strictly after position in one chat.
|
||||
Messages(ctx context.Context, chatID uuid.UUID, position dto.PositionDTO, limit int) ([]dto.MessageDTO, error)
|
||||
}
|
||||
Reference in New Issue
Block a user