46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"github.com/topfans/backend/pkg/database"
|
|
"github.com/topfans/backend/pkg/models"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// MintCostRepository 铸造消耗配置仓库
|
|
type MintCostRepository interface {
|
|
// GetByMintCount 根据铸爱次数获取配置
|
|
GetByMintCount(mintCount int32) (*models.MintCostConfig, error)
|
|
|
|
// GetAll 获取所有配置
|
|
GetAll() ([]*models.MintCostConfig, error)
|
|
}
|
|
|
|
type mintCostRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewMintCostRepository 创建铸造消耗配置仓库
|
|
func NewMintCostRepository() MintCostRepository {
|
|
return &mintCostRepository{
|
|
db: database.GetDB(),
|
|
}
|
|
}
|
|
|
|
// GetByMintCount 根据铸爱次数获取配置
|
|
func (r *mintCostRepository) GetByMintCount(mintCount int32) (*models.MintCostConfig, error) {
|
|
var config models.MintCostConfig
|
|
if err := r.db.Where("mint_count = ?", mintCount).First(&config).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|
|
|
|
// GetAll 获取所有配置
|
|
func (r *mintCostRepository) GetAll() ([]*models.MintCostConfig, error) {
|
|
var configs []*models.MintCostConfig
|
|
if err := r.db.Order("mint_count ASC").Find(&configs).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return configs, nil
|
|
}
|