feat: analysis user auth and ws
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package analysislogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AgreementInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAgreementInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AgreementInfoLogic {
|
||||
return &AgreementInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AgreementInfoLogic) AgreementInfo(in *analysis.AgreementInfoReq) (*analysis.Response, error) {
|
||||
var req validator.AgreementInfoValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
var info dao.AgreementInfo
|
||||
err := model.AgreementModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"type_id": strconv.Itoa(int(req.Type)),
|
||||
"status": strconv.Itoa(utils.StatusOk),
|
||||
},
|
||||
}, &info)
|
||||
if err != nil {
|
||||
l.Errorf("agreement info: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return common.FailResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
return common.OkResponse(info), nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package analysislogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type InternalCreateUserLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewInternalCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InternalCreateUserLogic {
|
||||
return &InternalCreateUserLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *InternalCreateUserLogic) InternalCreateUser(in *analysis.InternalCreateUserReq) (*analysis.InternalCreateUserData, error) {
|
||||
add := dao.UserCreate{
|
||||
IsRegistered: uint8(utils.StatusFail),
|
||||
IsFaceVerified: uint8(utils.StatusFail),
|
||||
IsProfileCompleted: uint8(utils.StatusFail),
|
||||
}
|
||||
err := model.UserModel{}.Init().Create(&add)
|
||||
if err != nil {
|
||||
l.Errorf("internal create user: %v", err)
|
||||
return nil, status.Error(codes.Internal, utils.Fail.Msg)
|
||||
}
|
||||
return &analysis.InternalCreateUserData{Id: add.Id}, nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package analysislogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SwitchLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSwitchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SwitchLogic {
|
||||
return &SwitchLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SwitchLogic) Switch(in *analysis.SwitchReq) (*analysis.Response, error) {
|
||||
var req validator.SwitchValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
t := req.Type
|
||||
if t < utils.NumberOne {
|
||||
t = utils.NumberOne
|
||||
}
|
||||
|
||||
var result int
|
||||
switch t {
|
||||
case utils.NumberOne:
|
||||
result = utils.GetConfigInt("switch.wechat")
|
||||
default:
|
||||
result = utils.NumberOne
|
||||
}
|
||||
|
||||
return common.OkResponse(result), nil
|
||||
}
|
||||
Reference in New Issue
Block a user