factroy store
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/store/internal/dao"
|
||||
"lone-services/services/store/internal/model"
|
||||
"lone-services/services/store/validator"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/store/pb"
|
||||
"lone-services/services/store/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ContentLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContentLogic {
|
||||
return &ContentLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ContentLogic) Content(in *store.ContentRequest) (*store.Response, error) {
|
||||
var v validator.StoreContentValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
var action = utils.ActionAdd{}
|
||||
var info dao.StoreContent
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
modelObj := model.StoreModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
action.OldContent = info
|
||||
info.Content = v.Content
|
||||
info.AdminName = adminInfo.Name
|
||||
info.AdminId = adminInfo.ID
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Type = utils.LogActionTypeEdit
|
||||
action.ModuleName = utils.LogActionModuleStore
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
Reference in New Issue
Block a user