crypto_alert_bot/internal/repository/repository.go
2026-04-28 11:42:52 +03:00

39 lines
2 KiB
Go

package repository
import (
"context"
"time"
"gitea.computernetthings.ru/yash/crypto_alert_bot/internal/entities"
"github.com/shopspring/decimal"
)
type Storage interface {
SaveUser(ctx context.Context, user *entities.User) (entities.UserID, error)
UserByID(ctx context.Context, id entities.UserID) (*entities.User, error)
UserByTelegramID(ctx context.Context, tgID entities.TelegramID) (*entities.User, error)
// InstrumentList returns instruments visible to userID: global ones plus any
// the user has explicitly added.
InstrumentList(ctx context.Context, userID entities.UserID, offset, limit int) ([]entities.Instrument, error)
// CreateInstrument upserts the instrument (and its currencies) and returns the ID,
// whether the row was just created or already existed.
CreateInstrument(ctx context.Context, instrument *entities.Instrument) (entities.InstrumentID, error)
// AddUserInstrument links an instrument to a user (idempotent).
AddUserInstrument(ctx context.Context, userID entities.UserID, instrumentID entities.InstrumentID) error
// RemoveUserInstrument removes a user's link to a non-global instrument.
RemoveUserInstrument(ctx context.Context, userID entities.UserID, instrumentID entities.InstrumentID) error
SaveAlert(ctx context.Context, alert *entities.Alert) (entities.AlertID, error)
AllActiveAlerts(ctx context.Context) ([]entities.Alert, error)
AlertByID(ctx context.Context, id entities.AlertID) (*entities.Alert, error)
AlertsByUserID(ctx context.Context, userID entities.UserID, offset, limit int) ([]entities.Alert, error)
DeleteAlert(ctx context.Context, id entities.AlertID) error
DisableAlert(ctx context.Context, id entities.AlertID) error
UpdateAlertPrice(ctx context.Context, id entities.AlertID, price decimal.Decimal) error
// GetLastAlertCheck returns the time of the last completed alert check.
// Returns zero time if no check has been recorded yet.
GetLastAlertCheck(ctx context.Context) (time.Time, error)
SetLastAlertCheck(ctx context.Context, t time.Time) error
}