86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package psql
|
|
|
|
import (
|
|
"ymgb/database"
|
|
|
|
"github.com/shopspring/decimal"
|
|
"github.com/vinovest/sqlx"
|
|
)
|
|
|
|
type ShopAuto struct {
|
|
ID int
|
|
Name string
|
|
Price decimal.Decimal
|
|
}
|
|
|
|
type ShopBusiness struct {
|
|
ID int
|
|
Name string
|
|
Price decimal.Decimal
|
|
Income decimal.Decimal
|
|
}
|
|
|
|
type ShopMaid struct {
|
|
ID int
|
|
Name string
|
|
Price decimal.Decimal
|
|
Income decimal.Decimal
|
|
}
|
|
|
|
type ShopMiner struct {
|
|
ID int
|
|
Name string
|
|
Price decimal.Decimal
|
|
Income decimal.Decimal
|
|
}
|
|
|
|
type ShopRepository struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
func newShopRepository(db *sqlx.DB) ShopRepository { return ShopRepository{db} }
|
|
func NewShopRepository(db *database.Context) ShopRepository {
|
|
return newShopRepository(db.Postgres)
|
|
}
|
|
|
|
func (rep ShopRepository) GetAllAuto() ([]ShopAuto, error) {
|
|
auto := make([]ShopAuto, 0)
|
|
err := rep.db.Select(&auto, "SELECT * FROM shop_auto ORDER BY id DESC;")
|
|
return auto, err
|
|
}
|
|
func (rep ShopRepository) GetAuto(id int32) (ShopAuto, error) {
|
|
auto := ShopAuto{}
|
|
err := rep.db.Get(&auto, "SELECT * FROM shop_auto WHERE id = $1;", id)
|
|
return auto, err
|
|
}
|
|
func (rep ShopRepository) GetAllBusinesses() ([]ShopBusiness, error) {
|
|
businesses := make([]ShopBusiness, 0)
|
|
err := rep.db.Select(&businesses, "SELECT * FROM shop_business ORDER BY id DESC;")
|
|
return businesses, err
|
|
}
|
|
func (rep ShopRepository) GetBusiness(id int32) (ShopBusiness, error) {
|
|
business := ShopBusiness{}
|
|
err := rep.db.Get(&business, "SELECT * FROM shop_business WHERE id = $1;", id)
|
|
return business, err
|
|
}
|
|
func (rep ShopRepository) GetAllMaids() ([]ShopMaid, error) {
|
|
maids := make([]ShopMaid, 0)
|
|
err := rep.db.Select(&maids, "SELECT * FROM shop_maid ORDER BY id DESC;")
|
|
return maids, err
|
|
}
|
|
func (rep ShopRepository) GetMaid(id int32) (ShopMaid, error) {
|
|
maid := ShopMaid{}
|
|
err := rep.db.Get(&maid, "SELECT * FROM shop_maid WHERE id = $1;", id)
|
|
return maid, err
|
|
}
|
|
func (rep ShopRepository) GetAllMiners() ([]ShopMiner, error) {
|
|
miners := make([]ShopMiner, 0)
|
|
err := rep.db.Select(&miners, "SELECT * FROM shop_miner ORDER BY id DESC;")
|
|
return miners, err
|
|
}
|
|
func (rep ShopRepository) GetMiner(id int32) (ShopMiner, error) {
|
|
miner := ShopMiner{}
|
|
err := rep.db.Get(&miner, "SELECT * FROM shop_miner WHERE id = $1;", id)
|
|
return miner, err
|
|
}
|