add: some user api and all api desc

This commit is contained in:
wwweww
2026-02-27 19:17:01 +08:00
parent a0c720eb2f
commit 5930fb0dde
156 changed files with 9457 additions and 1086 deletions
@@ -0,0 +1,68 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package verification_user
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/user_verifications/rpc/pb"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
"juwan-backend/common/utils/contextx"
"github.com/zeromicro/go-zero/core/logx"
)
type ApplyVerificationLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 提交或修改角色认证申请 (支持幂等更新)
func NewApplyVerificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyVerificationLogic {
return &ApplyVerificationLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ApplyVerificationLogic) ApplyVerification(req *types.ApplyVerificationReq) (resp *types.VerificationEmptyResp, err error) {
userId, err := contextx.UserIDFrom(l.ctx)
if err != nil {
logx.Errorf("get user id from context: %v", err)
return nil, contextx.ERRILLEGALUSER
}
verifications, err := l.svcCtx.UserVerificationsRpc.SearchUserVerifications(l.ctx, &pb.SearchUserVerificationsReq{
UserId: userId,
})
if err != nil {
logx.Errorf("search user verifications: %v", err)
return nil, errors.New("search user verifications failed")
}
materials, err := json.Marshal(req.Materials)
if err != nil {
logx.Errorf("marshal materials: %v", err)
return nil, err
}
if verifications == nil || len(verifications.UserVerifications) == 0 {
// 如果没有则增加
_, err = l.svcCtx.UserVerificationsRpc.AddUserVerifications(l.ctx, &pb.AddUserVerificationsReq{
Role: req.Role,
Materials: string(materials),
})
if err != nil {
logx.Errorf("add user verifications: %v", err)
return nil, errors.New("add user verifications failed")
}
} else {
}
return &types.VerificationEmptyResp{}, nil
}
@@ -0,0 +1,68 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package verification_user
import (
"context"
"juwan-backend/app/user_verifications/rpc/pb"
"juwan-backend/common/utils/contextx"
"time"
"juwan-backend/app/users/api/internal/svc"
"juwan-backend/app/users/api/internal/types"
"github.com/jinzhu/copier"
"github.com/zeromicro/go-zero/core/logx"
)
type GetMyVerificationsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取我的所有认证状态
func NewGetMyVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMyVerificationsLogic {
return &GetMyVerificationsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetMyVerificationsLogic) GetMyVerifications() (resp *types.GetMyVerificationsResp, err error) {
// todo: add your logic here and delete this line
userId, err := contextx.UserIDFrom(l.ctx)
if err != nil {
logx.Errorf("get user id from context: %v", err)
return nil, contextx.ERRILLEGALUSER
}
verifications, err := l.svcCtx.UserVerificationsRpc.SearchUserVerifications(l.ctx, &pb.SearchUserVerificationsReq{
UserId: userId,
Page: 1,
Limit: 100, // assuming a user won't have more than 100 verification records, adjust as needed
})
if err != nil {
return nil, err
}
var searchResults []types.VerificationItem
for _, v := range verifications.UserVerifications {
temp := types.VerificationItem{}
err = copier.Copy(&temp, v)
if err != nil {
logx.Errorf("copy verification item err: %s", err.Error())
continue
}
temp.CreatedAt = time.Unix(v.CreatedAt, 0).Format(time.DateTime)
temp.ReviewedAt = time.Unix(v.ReviewedAt, 0).Format(time.DateTime)
searchResults = append(searchResults, temp)
}
resp = &types.GetMyVerificationsResp{
List: searchResults,
}
return
}