Documentation
¶
Index ¶
- type AllOrdersFilter
- type BaseFilter
- type MongoStore
- func (s *MongoStore) Close(ctx context.Context) error
- func (s *MongoStore) DecrementStock(ctx context.Context, id string, quantity int) (bool, error)
- func (s *MongoStore) GetAllOrders(ctx context.Context, f AllOrdersFilter) (orders []*models.Order, total int, err error)
- func (s *MongoStore) GetAllRecords(ctx context.Context) (records []*models.Record, err error)
- func (s *MongoStore) GetAllUsers(ctx context.Context, f UserFilter) (users []*models.User, total int, err error)
- func (s *MongoStore) GetFilteredRecords(ctx context.Context, f RecordFilter) (records []*models.Record, total int, err error)
- func (s *MongoStore) GetOrder(ctx context.Context, id string) (*models.Order, bool, error)
- func (s *MongoStore) GetOrdersByUser(ctx context.Context, f OrderFilter) (orders []*models.Order, total int, err error)
- func (s *MongoStore) GetRecord(ctx context.Context, id string) (*models.Record, bool, error)
- func (s *MongoStore) GetUser(ctx context.Context, id string) (*models.User, bool, error)
- func (s *MongoStore) GetUserByEmail(ctx context.Context, email string) (*models.User, bool, error)
- func (s *MongoStore) Ping(ctx context.Context) error
- func (s *MongoStore) SaveOrder(ctx context.Context, o *models.Order) error
- func (s *MongoStore) SaveRecord(ctx context.Context, r *models.Record) error
- func (s *MongoStore) SaveUser(ctx context.Context, u *models.User) error
- func (s *MongoStore) SeedData()
- type OrderFilter
- type OrderStore
- type RecordFilter
- type RecordStore
- type Store
- type UserFilter
- type UserStore
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 ¶
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 ¶
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 (*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) GetOrdersByUser ¶
func (s *MongoStore) GetOrdersByUser(ctx context.Context, f OrderFilter) (orders []*models.Order, total int, err error)
func (*MongoStore) GetUserByEmail ¶
func (*MongoStore) Ping ¶
func (s *MongoStore) Ping(ctx context.Context) error
Ping checks if MongoDB is reachable
func (*MongoStore) SaveRecord ¶
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