storage

package
v0.0.0-...-6bcd878 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConfig

type DBConfig struct {
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
	DBName   string `mapstructure:"db_name" yaml:"db_name"`
}

func (*DBConfig) GetDSN

func (config *DBConfig) GetDSN() string

type FavoriteList

type FavoriteList struct {
	gorm.Model
	UserID uint
	User   UserAccount `gorm:"ONDELETE:CASCADE"`
	Name   string
	Items  []FavoriteListItem
}

type FavoriteListItem

type FavoriteListItem struct {
	gorm.Model
	FavoriteListID uint
	FavoriteList   FavoriteList `gorm:"ONDELETE:CASCADE"`
	ProductID      uint
}

type SearchHistory

type SearchHistory struct {
	gorm.Model
	UserID       uint
	User         UserAccount `gorm:"ONDELETE:CASCADE"`
	QueryAddress string
	Results      []SearchHistoryResult
}

type SearchHistoryResult

type SearchHistoryResult struct {
	gorm.Model
	SearchHistoryID uint
	SearchHistory   SearchHistory `gorm:"ONDELETE:CASCADE"`
	ProductID       uint
}

type Storage

type Storage struct {
	*gorm.DB
}

func NewStorage

func NewStorage(masterConfig *DBConfig, replicaConfigs ...*DBConfig) *Storage

func (*Storage) AddItemToList

func (storage *Storage) AddItemToList(listID uint, productID uint) error

func (*Storage) Close

func (storage *Storage) Close()

func (*Storage) CreateFavoriteList

func (storage *Storage) CreateFavoriteList(list *FavoriteList) error

func (*Storage) CreateSearchHistory

func (storage *Storage) CreateSearchHistory(history *SearchHistory) error

func (*Storage) CreateSearchHistoryResult

func (storage *Storage) CreateSearchHistoryResult(result *SearchHistoryResult) error

func (*Storage) CreateUnauthorizedToken

func (storage *Storage) CreateUnauthorizedToken(token *UnauthorizedToken) error

func (*Storage) CreateUser

func (storage *Storage) CreateUser(user *UserAccount) error

func (*Storage) DeleteUnauthorizedTokensBeforeNow

func (storage *Storage) DeleteUnauthorizedTokensBeforeNow() error

func (*Storage) GetAllUnauthorizedTokens

func (storage *Storage) GetAllUnauthorizedTokens() ([]*UnauthorizedToken, error)

func (*Storage) GetFavoriteListByID

func (storage *Storage) GetFavoriteListByID(id uint) (*FavoriteList, error)

func (*Storage) GetFavoriteListByUserIDAndName

func (storage *Storage) GetFavoriteListByUserIDAndName(userID uint, name string) (*FavoriteList, error)

func (*Storage) GetFavoriteListsByUserID

func (storage *Storage) GetFavoriteListsByUserID(userID uint) (*[]FavoriteList, error)

func (*Storage) GetSearchHistoryByID

func (storage *Storage) GetSearchHistoryByID(id uint) (*SearchHistory, error)

func (*Storage) GetSearchHistoryByUserID

func (storage *Storage) GetSearchHistoryByUserID(userID uint, offset int, limit int) ([]SearchHistory, error)

func (*Storage) GetUnauthorizedToken

func (storage *Storage) GetUnauthorizedToken(token string) (*UnauthorizedToken, error)

func (*Storage) GetUserByEmail

func (storage *Storage) GetUserByEmail(email string) (*UserAccount, error)

func (*Storage) GetUserByID

func (storage *Storage) GetUserByID(id uint) (*UserAccount, error)

func (*Storage) GetUserByPhoneNumber

func (storage *Storage) GetUserByPhoneNumber(phoneNumber string) (*UserAccount, error)

func (*Storage) Migrate

func (storage *Storage) Migrate() error

func (*Storage) RemoveItemFromList

func (storage *Storage) RemoveItemFromList(listID uint, productID uint) error

type UnauthorizedToken

type UnauthorizedToken struct {
	gorm.Model
	UserID     uint
	User       UserAccount `gorm:"ONDELETE:CASCADE"`
	Token      string
	Expiration time.Time `gorm:"index"`
}

type UserAccount

type UserAccount struct {
	gorm.Model
	Email        string `gorm:"uniqueIndex:idx_email"`
	PhoneNumber  string `gorm:"uniqueIndex:idx_phone_number"`
	Gender       string `gorm:"type:VARCHAR(1)"`
	FirstName    string
	LastName     string
	PasswordHash string
}

Jump to

Keyboard shortcuts

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