add: some user api and all api desc
This commit is contained in:
@@ -2,10 +2,13 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"errors"
|
||||
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -24,7 +27,50 @@ func NewSearchUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceCon
|
||||
}
|
||||
|
||||
func (l *SearchUserVerificationsLogic) SearchUserVerifications(in *pb.SearchUserVerificationsReq) (*pb.SearchUserVerificationsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.SearchUserVerificationsResp{}, nil
|
||||
if in.Limit > 1000 {
|
||||
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
|
||||
return nil, errors.New("limit exceeds max limit")
|
||||
}
|
||||
verifications, err := l.svcCtx.UserVeriModelRO.Query().Where(userverifications.Or(
|
||||
userverifications.UserIDEQ(in.UserId),
|
||||
userverifications.StatusEQ(in.Status),
|
||||
userverifications.Role(in.Role),
|
||||
)).
|
||||
Offset(int(in.Page * in.Limit)).
|
||||
Limit(int(in.Limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("Get all verifications err: %s", err.Error())
|
||||
return nil, errors.New("get all verifications err")
|
||||
}
|
||||
return &pb.SearchUserVerificationsResp{
|
||||
UserVerifications: convertModelUserVerificationsToProto(verifications),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func convertModelUserVerificationToProto(modelUserVerification *models.UserVerifications) *pb.UserVerifications {
|
||||
|
||||
if modelUserVerification == nil {
|
||||
return nil
|
||||
}
|
||||
out := &pb.UserVerifications{}
|
||||
err := copier.Copy(out, modelUserVerification)
|
||||
if err != nil {
|
||||
logx.Errorf("copy modelUserVerification err: %s", err.Error())
|
||||
return out
|
||||
}
|
||||
|
||||
out.CreatedAt = modelUserVerification.CreatedAt.Unix()
|
||||
out.UpdatedAt = modelUserVerification.UpdatedAt.Unix()
|
||||
return out
|
||||
}
|
||||
|
||||
func convertModelUserVerificationsToProto(modelUserVerifications []*models.UserVerifications) []*pb.UserVerifications {
|
||||
|
||||
out := make([]*pb.UserVerifications, 0, len(modelUserVerifications))
|
||||
for _, modelUserVerification := range modelUserVerifications {
|
||||
out = append(out, convertModelUserVerificationToProto(modelUserVerification))
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user