Files
YaeMikoBot/database/psql/shop.go
2026-01-14 14:29:03 +03:00

83 lines
2.1 KiB
Go

package psql
import (
"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: db}
}
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 := new(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 := new(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 := new(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 := new(ShopMiner)
err := rep.db.Get(miner, "SELECT * FROM shop_miner WHERE id = $1;", id)
return miner, err
}