This commit is contained in:
parent
27aff98a72
commit
a8dae49f45
19
gorm.sh
19
gorm.sh
|
|
@ -132,11 +132,14 @@ import (
|
|||
"voucher/internal/data/model"
|
||||
"voucher/internal/biz/repo"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/data"
|
||||
err2 "voucher/api/err"
|
||||
)
|
||||
|
||||
// ${table_capitalized}RepoImpl .
|
||||
type ${table_capitalized}RepoImpl struct {
|
||||
Base[model.${table_capitalized}, bo.${table_capitalized}Bo]
|
||||
db *data.Db
|
||||
}
|
||||
|
||||
// New${table_capitalized}RepoImpl .
|
||||
|
|
@ -144,6 +147,10 @@ func New${table_capitalized}RepoImpl() repo.${table_capitalized}Repo {
|
|||
return &${table_capitalized}RepoImpl{}
|
||||
}
|
||||
|
||||
func (r *${table_capitalized}RepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||
return p.db.DB(ctx).WithContext(ctx).Model(model.${table_capitalized}{})
|
||||
}
|
||||
|
||||
func (r *${table_capitalized}RepoImpl) Create(ctx context.Context, req *bo.${table_capitalized}Bo) (*bo.${table_capitalized}Bo, error) {
|
||||
// todo 待实现
|
||||
return nil, nil
|
||||
|
|
@ -152,7 +159,17 @@ func (r *${table_capitalized}RepoImpl) Create(ctx context.Context, req *bo.${tab
|
|||
// GetByID 根据 ID 获取 ${table_capitalized}
|
||||
func (r *${table_capitalized}RepoImpl) GetByID(ctx context.Context,id int32) (*bo.${table_capitalized}Bo, error) {
|
||||
var item model.${table_capitalized}
|
||||
// todo 待实现
|
||||
|
||||
tx := p.DB(ctx).Where(model.${table_capitalized}{ID: id}).First(&item)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, fmt.Errorf("b fail %w", tx.Error)
|
||||
}
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, err2.ErrorDbNotFound("数据不存在")
|
||||
}
|
||||
|
||||
return r.ToBo(&item), nil
|
||||
}
|
||||
EOL
|
||||
|
|
|
|||
Loading…
Reference in New Issue