实现交易子服务
This commit is contained in:
36
internal/infra/repository/pig_trade_repository.go
Normal file
36
internal/infra/repository/pig_trade_repository.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// PigTradeRepository 定义了猪只交易数据持久化的接口。
|
||||
// 领域服务通过此接口与数据层交互,实现解耦。
|
||||
type PigTradeRepository interface {
|
||||
// CreatePigSaleTx 在数据库中创建一条猪只销售记录。
|
||||
CreatePigSaleTx(tx *gorm.DB, sale *models.PigSale) error
|
||||
|
||||
// CreatePigPurchaseTx 在数据库中创建一条猪只采购记录。
|
||||
CreatePigPurchaseTx(tx *gorm.DB, purchase *models.PigPurchase) error
|
||||
}
|
||||
|
||||
// gormPigTradeRepository 是 PigTradeRepository 接口的 GORM 实现。
|
||||
type gormPigTradeRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewGormPigTradeRepository 创建一个新的 PigTradeRepository GORM 实现实例。
|
||||
func NewGormPigTradeRepository(db *gorm.DB) PigTradeRepository {
|
||||
return &gormPigTradeRepository{db: db}
|
||||
}
|
||||
|
||||
// CreatePigSaleTx 实现了在数据库中创建猪只销售记录的逻辑。
|
||||
func (r *gormPigTradeRepository) CreatePigSaleTx(tx *gorm.DB, sale *models.PigSale) error {
|
||||
return tx.Create(sale).Error
|
||||
}
|
||||
|
||||
// CreatePigPurchaseTx 实现了在数据库中创建猪只采购记录的逻辑。
|
||||
func (r *gormPigTradeRepository) CreatePigPurchaseTx(tx *gorm.DB, purchase *models.PigPurchase) error {
|
||||
return tx.Create(purchase).Error
|
||||
}
|
||||
Reference in New Issue
Block a user