feat: product store
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"product/internal/dao"
|
||||
"product/internal/model"
|
||||
"product/internal/svc"
|
||||
"product/product"
|
||||
"product/validator"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SortLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSortLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SortLogic {
|
||||
return &SortLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SortLogic) Sort(in *product.SortReq) (*product.Response, error) {
|
||||
var req validator.ProductSortValidator
|
||||
if msg := validateService.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return msgResponse(utils.Ok.Code, msg), nil
|
||||
}
|
||||
|
||||
var info dao.ProductSort
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)},
|
||||
}
|
||||
m := model.ProductModel{}.Init()
|
||||
err := m.GetOne(w, &info)
|
||||
if err != nil {
|
||||
log.Errorf("product sort get: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < 1 {
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
info.Sort = uint16(req.Sort)
|
||||
// 管理员信息后续从 ctx / metadata 取
|
||||
info.AdminName = ""
|
||||
info.AdminId = 0
|
||||
|
||||
if _, err = m.Edit(w, &info); err != nil {
|
||||
log.Errorf("product sort edit: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(utils.StringEmpty), nil
|
||||
}
|
||||
Reference in New Issue
Block a user