store

package
v0.0.0-...-82454b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllOrdersFilter

type AllOrdersFilter struct {
	BaseFilter
}

AllOrdersFilter contains filter options for GetAllOrders

type BaseFilter

type BaseFilter struct {
	Page    int
	PerPage int
}

BaseFilter contains common pagination fields

type MongoStore

type MongoStore struct {
	// contains filtered or unexported fields
}

MongoStore implements Store using MongoDB.

func NewMongoStore

func NewMongoStore(uri, dbName string) (*MongoStore, error)

NewMongoStore creates a new MongoDB store

func (*MongoStore) Close

func (s *MongoStore) Close(ctx context.Context) error

Close disconnects from MongoDB

func (*MongoStore) DecrementStock

func (s *MongoStore) DecrementStock(ctx context.Context, id string, quantity int) (bool, error)

DecrementStock atomically decrements the stock of a record by the given quantity. Returns true if the stock was successfully decremented, false if insufficient stock.

func (*MongoStore) GetAllOrders

func (s *MongoStore) GetAllOrders(ctx context.Context, f AllOrdersFilter) (orders []*models.Order, total int, err error)

func (*MongoStore) GetAllRecords

func (s *MongoStore) GetAllRecords(ctx context.Context) (records []*models.Record, err error)

func (*MongoStore) GetAllUsers

func (s *MongoStore) GetAllUsers(ctx context.Context, f UserFilter) (users []*models.User, total int, err error)

func (*MongoStore) GetFilteredRecords

func (s *MongoStore) GetFilteredRecords(ctx context.Context, f RecordFilter) (records []*models.Record, total int, err error)

func (*MongoStore) GetOrder

func (s *MongoStore) GetOrder(ctx context.Context, id string) (*models.Order, bool, error)

func (*MongoStore) GetOrdersByUser

func (s *MongoStore) GetOrdersByUser(ctx context.Context, f OrderFilter) (orders []*models.Order, total int, err error)

func (*MongoStore) GetRecord

func (s *MongoStore) GetRecord(ctx context.Context, id string) (*models.Record, bool, error)

func (*MongoStore) GetUser

func (s *MongoStore) GetUser(ctx context.Context, id string) (*models.User, bool, error)

func (*MongoStore) GetUserByEmail

func (s *MongoStore) GetUserByEmail(ctx context.Context, email string) (*models.User, bool, error)

func (*MongoStore) Ping

func (s *MongoStore) Ping(ctx context.Context) error

Ping checks if MongoDB is reachable

func (*MongoStore) SaveOrder

func (s *MongoStore) SaveOrder(ctx context.Context, o *models.Order) error

func (*MongoStore) SaveRecord

func (s *MongoStore) SaveRecord(ctx context.Context, r *models.Record) error

func (*MongoStore) SaveUser

func (s *MongoStore) SaveUser(ctx context.Context, u *models.User) error

func (*MongoStore) SeedData

func (s *MongoStore) SeedData()

SeedData adds sample records to the store

type OrderFilter

type OrderFilter struct {
	BaseFilter
	UserID string
	Status string
}

OrderFilter contains filter options for GetOrdersByUser

type OrderStore

type OrderStore interface {
	GetOrder(ctx context.Context, id string) (*models.Order, bool, error)
	SaveOrder(ctx context.Context, o *models.Order) error
	GetOrdersByUser(ctx context.Context, filter OrderFilter) ([]*models.Order, int, error)
	GetAllOrders(ctx context.Context, filter AllOrdersFilter) ([]*models.Order, int, error)
}

OrderStore defines the interface for order storage

type RecordFilter

type RecordFilter struct {
	BaseFilter
	Genres     []string
	Decade     int
	Conditions []string
	Formats    []string
	Artist     string
	MinPrice   float64
	MaxPrice   float64
	InStock    bool
	Sort       string
}

RecordFilter contains filter options for GetFilteredRecords

type RecordStore

type RecordStore interface {
	GetRecord(ctx context.Context, id string) (*models.Record, bool, error)
	SaveRecord(ctx context.Context, r *models.Record) error
	GetAllRecords(ctx context.Context) ([]*models.Record, error)
	GetFilteredRecords(ctx context.Context, filter RecordFilter) ([]*models.Record, int, error)
	DecrementStock(ctx context.Context, id string, quantity int) (bool, error)
}

RecordStore defines the interface for record storage

type Store

type Store interface {
	UserStore
	RecordStore
	OrderStore
}

Store combines all in-memory storage interfaces. Token and idempotency storage are handled by Redis separately.

type UserFilter

type UserFilter struct {
	BaseFilter
}

UserFilter contains filter options for GetAllUsers

type UserStore

type UserStore interface {
	GetUser(ctx context.Context, id string) (*models.User, bool, error)
	SaveUser(ctx context.Context, u *models.User) error
	GetUserByEmail(ctx context.Context, email string) (*models.User, bool, error)
	GetAllUsers(ctx context.Context, filter UserFilter) ([]*models.User, int, error)
}

UserStore defines the interface for user storage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL