store

package
v0.0.0-...-0722155 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeEmptyDatabase

func MakeEmptyDatabase(DBPath string, migrationPath string) (*sql.DB, error)

func OpenDatabase

func OpenDatabase(DBPath string) (*sql.DB, error)

func OpenRedis

func OpenRedis() *redis.Client

Types

type Customer

type Customer struct {
	Id       int64  `json:"id"`
	Username string `json:"username"`
	Location string `json:"location"`
	ItemId   int64  `json:"itemid"`
	MallId   int64  `json:"mallid"`
	BuyCount int64  `json:"buycount"`
}

type Item

type Item struct {
	Id          int64  `json:"id"`
	MallId      int64  `json:"mallid"`
	Total       int64  `json:"total"`
	Price       int64  `json:"price"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Data        string `json:"data"`
}

type Mall

type Mall struct {
	Id     int64 `json:"id"`
	UserId int64 `json:"userid"`
	// BeginTime and EndTime are stored in format of unix timestamp
	BeginTime int64 `json:"begintime"`
	EndTime   int64 `json:"endtime"`
	// state == 0 means the mall is canceled
	// state == 1 means the mall is open
	State int64 `json:"state"`
}

type MallCustomer

type MallCustomer struct {
	MallId   int64 `json:"mallid"`
	UserId   int64 `json:"userid"`
	ItemId   int64 `json:"itemid"`
	BuyCount int64 `json:"buycount"`
}

type Store

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

func NewStore

func NewStore(DBPath string) (*Store, error)

func (*Store) Buy

func (s *Store) Buy(user *User, orders []*MallCustomer) error

func (*Store) CreateMall

func (s *Store) CreateMall(user *User, mall *Mall, items []*Item) error

func (*Store) GetCustomersByMallId

func (s *Store) GetCustomersByMallId(mallId int64) ([]*Customer, error)

func (*Store) GetItemById

func (s *Store) GetItemById(itemId int64) (*Item, error)

func (*Store) GetItemsByMallId

func (s *Store) GetItemsByMallId(mallId int64) ([]*Item, error)

func (*Store) GetMallById

func (s *Store) GetMallById(mallId int64) (*Mall, error)

func (*Store) GetMalls

func (s *Store) GetMalls() ([]*Mall, error)

func (*Store) GetMallsByUserId

func (s *Store) GetMallsByUserId(userId int64) ([]*Mall, error)

func (*Store) GetOrdersByItemId

func (s *Store) GetOrdersByItemId(itemId int64) ([]*MallCustomer, error)

func (*Store) GetOrdersByMallId

func (s *Store) GetOrdersByMallId(mallId int64) ([]*MallCustomer, error)

func (*Store) GetOrdersByUserId

func (s *Store) GetOrdersByUserId(userId int64) ([]*MallCustomer, error)

func (*Store) GetUserById

func (s *Store) GetUserById(id int64) (*User, error)

func (*Store) GetUserByUsername

func (s *Store) GetUserByUsername(username string) (*User, error)

func (*Store) InsertItem

func (s *Store) InsertItem(tx *sql.Tx, item *Item) error

func (*Store) InsertMall

func (s *Store) InsertMall(tx *sql.Tx, mall *Mall) error

func (*Store) InsertUser

func (s *Store) InsertUser(user *User) error

func (*Store) UpdateMall

func (s *Store) UpdateMall(mall *Mall) error

func (*Store) ValidUser

func (s *Store) ValidUser(user *User) bool

type User

type User struct {
	Id       int64
	Username string
	Password string
	Location string
}

func NewUser

func NewUser(username, password, location string) *User

plaintext password -> hash

Jump to

Keyboard shortcuts

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