refactor: 重构资产实体和DTO结构类型
将gjson.Json类型替换为具体的结构体和map类型,修正DAO层链式调用,启用SKU元数据校验逻辑
This commit is contained in:
@@ -23,7 +23,7 @@ func (d *assetSku) Insert(ctx context.Context, req *dto.CreateAssetSkuReq) (id i
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Ctx(ctx).Data(&res).Insert()
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (d *assetSku) Insert(ctx context.Context, req *dto.CreateAssetSkuReq) (id i
|
||||
|
||||
// Update 更新SKU
|
||||
func (d *assetSku) Update(ctx context.Context, req *dto.UpdateAssetSkuReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Ctx(ctx).OmitEmpty().Where(entity.AssetCol.Id, req.Id).Update()
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Data(&req).OmitEmpty().Where(entity.AssetCol.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (d *assetSku) Delete(ctx context.Context, req *dto.DeleteAssetSkuReq) (rows
|
||||
|
||||
// GetOne 获取单个SKU
|
||||
func (d *assetSku) GetOne(ctx context.Context, req *dto.GetAssetSkuReq, fields ...string) (res *entity.AssetSku, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Ctx(ctx).Where(entity.AssetCol.Id, req.Id).Fields(fields).One()
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.AssetSkuCollection).Where(entity.AssetCol.Id, req.Id).Fields(fields).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -104,8 +104,10 @@ func (d *assetSku) buildListFilter(ctx context.Context, req *dto.ListAssetSkuReq
|
||||
}
|
||||
model.Where(entity.AssetSkuCol.Id, req.Id)
|
||||
model.Where(entity.AssetSkuCol.Status, req.Status)
|
||||
model.WhereGT(entity.AssetSkuCol.Price, req.MinPrice)
|
||||
model.WhereLT(entity.AssetSkuCol.Price, req.MaxPrice)
|
||||
if req.MinPrice > 0 && req.MaxPrice > 0 {
|
||||
model.WhereGT(entity.AssetSkuCol.Price, req.MinPrice)
|
||||
model.WhereLT(entity.AssetSkuCol.Price, req.MaxPrice)
|
||||
}
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user