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)
|
||||
|
||||
Reference in New Issue
Block a user