feat: chore test
This commit is contained in:
@@ -13,6 +13,7 @@ type AddressItemLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewAddressItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddressItemLogic {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
order "lone-services/rpc/order/pb"
|
||||
"reflect"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type BaseLogic struct {
|
||||
}
|
||||
|
||||
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *order.Response {
|
||||
rv := reflect.ValueOf(in)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
return &order.Response{
|
||||
Code: utils.ErrorParams.Code,
|
||||
Msg: "request must be non‑nil proto pointer",
|
||||
}
|
||||
}
|
||||
|
||||
resp := validate.ValidateFromProto(in, v)
|
||||
if resp != utils.StringEmpty {
|
||||
return &order.Response{
|
||||
Code: utils.ErrorParams.Code,
|
||||
Msg: resp,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) fail(status utils.Status) (*order.Response, error) {
|
||||
return l.out(status, status.Msg)
|
||||
}
|
||||
func (l *BaseLogic) out(status utils.Status, msg string) (*order.Response, error) {
|
||||
return &order.Response{Code: status.Code, Msg: msg}, nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) ok(data any) (*order.Response, error) {
|
||||
buf, _ := jsoniter.Marshal(data)
|
||||
return &order.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
order "lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -12,6 +13,7 @@ type ItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic {
|
||||
@@ -22,9 +24,17 @@ func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ItemsLogic) Items(in *order.ItemsRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
func (l *ItemsLogic) Items(in *order.OrderItemsRequest) (*order.Response, error) {
|
||||
//调用其它服务实例
|
||||
//cli, err := svc.GetRpcClient(l.svcCtx.ExpressSvcName)
|
||||
//if err != nil {
|
||||
// l.Logger.Errorf("get express rpc err: %v", err)
|
||||
// //降级逻辑
|
||||
// return l.out(utils.ErrorInternalServer, "express"+utils.ErrorInternalServer.Msg)
|
||||
//}
|
||||
//expClient := express.NewExpressClient(cli.Conn())
|
||||
//res, _ := expClient.Ping(context.Background(), &express.Request{})
|
||||
//l.Logger.Error("res: %v", res)
|
||||
|
||||
//TODO new id now
|
||||
return &order.Response{}, nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type OrderAuditingItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewOrderAuditingItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAuditingItemsLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type OrderAuditingLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewOrderAuditingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAuditingLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type OrderCreateLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewOrderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderCreateLogic {
|
||||
|
||||
@@ -2,10 +2,14 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/internal/svc"
|
||||
"lone-services/services/order/validator"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -13,6 +17,7 @@ type WebAddressCreateLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebAddressCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressCreateLogic {
|
||||
@@ -24,7 +29,50 @@ func NewWebAddressCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||
}
|
||||
|
||||
func (l *WebAddressCreateLogic) WebAddressCreate(in *order.EditAddressRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.AddressEditValidator
|
||||
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)
|
||||
}
|
||||
encryPhone, cErr := utils.EncryptPhone(in.Mobile)
|
||||
if cErr != nil {
|
||||
l.Logger.Error(cErr)
|
||||
return l.fail(utils.ErrorEncryptAesError)
|
||||
}
|
||||
|
||||
data := dao.Address{
|
||||
TargetId: adminInfo.ID,
|
||||
TypeName: adminInfo.Name,
|
||||
District: in.District,
|
||||
DistrictIds: in.DistrictIds,
|
||||
Address: in.Address,
|
||||
Name: in.Name,
|
||||
Mobile: encryPhone,
|
||||
Type: in.Type,
|
||||
Status: utils.StatusApply,
|
||||
}
|
||||
|
||||
jsonStr, err := jsoniter.MarshalToString(data)
|
||||
if err != nil {
|
||||
l.Logger.Error("转换失败:", err)
|
||||
return l.fail(utils.ErrorJsonDataError)
|
||||
}
|
||||
|
||||
data.NewContent = jsonStr
|
||||
data.SaleId = adminInfo.SaleId
|
||||
data.GroupId = adminInfo.GroupId
|
||||
|
||||
modelObj := model.AddressModel{}.Init()
|
||||
|
||||
err = modelObj.Create(&data)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
return l.ok(data.Id)
|
||||
|
||||
return &order.Response{}, nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebAddressDefLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebAddressDefLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressDefLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebAddressEditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebAddressEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressEditLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebAddressItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebAddressItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressItemsLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebAddressStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebAddressStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressStatusLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebCartEditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebCartEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCartEditLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebCartLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCartLogic {
|
||||
|
||||
@@ -13,6 +13,7 @@ type WebCreateLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWebCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCreateLogic {
|
||||
|
||||
Reference in New Issue
Block a user