59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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
|
|
}
|