feat: client items
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
user "lone-services/rpc/user/pb"
|
||||
"lone-services/services/user/internal/dao"
|
||||
"lone-services/services/user/internal/model"
|
||||
"lone-services/services/user/internal/svc"
|
||||
"lone-services/services/user/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ClientLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClientLogic {
|
||||
return &ClientLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ClientLogic) Client(in *user.ClientReq) (*user.Response, error) {
|
||||
var req validator.ClientValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{}
|
||||
|
||||
if req.Name != utils.StringEmpty {
|
||||
w.Eq["name"] = req.Name
|
||||
}
|
||||
if req.Type != utils.StringEmpty {
|
||||
w.Eq["type"] = req.Type
|
||||
}
|
||||
if req.SubjectType != utils.NumberZero {
|
||||
w.Eq["subject_type"] = strconv.FormatUint(uint64(req.SubjectType), utils.NumberTen)
|
||||
}
|
||||
var items []dao.Client
|
||||
err := model.ClientModel{}.Init().Items(w, &items)
|
||||
if err != nil {
|
||||
l.Errorf("client items: %v", err)
|
||||
return outResponse(utils.ErrorInternalServer, utils.Fail.Msg), nil
|
||||
}
|
||||
|
||||
return okResponse(items), nil
|
||||
}
|
||||
@@ -33,6 +33,11 @@ func (s *UserServer) Info(ctx context.Context, in *user.InfoReq) (*user.Response
|
||||
return l.Info(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) Client(ctx context.Context, in *user.ClientReq) (*user.Response, error) {
|
||||
l := logic.NewClientLogic(ctx, s.svcCtx)
|
||||
return l.Client(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) UserItems(ctx context.Context, in *user.UserItemsReq) (*user.Response, error) {
|
||||
l := logic.NewUserItemsLogic(ctx, s.svcCtx)
|
||||
return l.UserItems(in)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
ClientReq = user.ClientReq
|
||||
InfoReq = user.InfoReq
|
||||
InternalCheckCreateData = user.InternalCheckCreateData
|
||||
InternalCheckCreateReq = user.InternalCheckCreateReq
|
||||
@@ -38,6 +39,7 @@ type (
|
||||
User interface {
|
||||
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Client(ctx context.Context, in *ClientReq, opts ...grpc.CallOption) (*Response, error)
|
||||
UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error)
|
||||
UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error)
|
||||
InternalCreate(ctx context.Context, in *InternalCreateReq, opts ...grpc.CallOption) (*InternalCreateData, error)
|
||||
@@ -70,6 +72,11 @@ func (m *defaultUser) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOp
|
||||
return client.Info(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) Client(ctx context.Context, in *ClientReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.Client(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.UserItems(ctx, in, opts...)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package validator
|
||||
|
||||
import "lone-services/pkg/validate"
|
||||
|
||||
type ClientValidator struct {
|
||||
Name string `validate:"omitempty,max=64"`
|
||||
Type string `validate:"omitempty,oneof=user sale store"`
|
||||
SubjectType uint32 `validate:"omitempty,oneof=1 2 3"`
|
||||
}
|
||||
|
||||
func (p ClientValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Name.max": "名称过长",
|
||||
"Type.oneof": "类型不正确",
|
||||
"SubjectType.oneof": "主体类型不正确",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user