This commit is contained in:
2026-01-14 14:29:03 +03:00
parent 7d540962a1
commit 4dd87ddecc
17 changed files with 513 additions and 226 deletions

View File

@@ -1,6 +1,9 @@
package psql
import "github.com/shopspring/decimal"
import (
"github.com/shopspring/decimal"
"github.com/vinovest/sqlx"
)
type ShopAuto struct {
ID int
@@ -8,10 +11,6 @@ type ShopAuto struct {
Price decimal.Decimal
}
func (ShopAuto) TableName() string {
return "shop_auto"
}
type ShopBusiness struct {
ID int
Name string
@@ -19,10 +18,6 @@ type ShopBusiness struct {
Income decimal.Decimal
}
func (ShopBusiness) TableName() string {
return "shop_business"
}
type ShopMaid struct {
ID int
Name string
@@ -30,10 +25,6 @@ type ShopMaid struct {
Income decimal.Decimal
}
func (ShopMaid) TableName() string {
return "shop_maid"
}
type ShopMiner struct {
ID int
Name string
@@ -41,6 +32,51 @@ type ShopMiner struct {
Income decimal.Decimal
}
func (ShopMiner) TableName() string {
return "shop_miner"
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
}