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
+126 -45
View File
@@ -6,7 +6,10 @@ package handler
import (
"net/http"
auth "juwan-backend/app/users/api/internal/handler/auth"
user "juwan-backend/app/users/api/internal/handler/user"
verification_admin "juwan-backend/app/users/api/internal/handler/verification_admin"
verification_user "juwan-backend/app/users/api/internal/handler/verification_user"
"juwan-backend/app/users/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
@@ -14,41 +17,44 @@ import (
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.Logger},
[]rest.Route{
{
// 用户登出
Method: http.MethodPost,
Path: "/:userId/logout",
Handler: user.LogoutHandler(serverCtx),
},
{
// 修改用户密码
Method: http.MethodPut,
Path: "/:userId/password",
Handler: user.UpdatePasswordHandler(serverCtx),
},
{
// 修改密码-使用验证码
Method: http.MethodPut,
Path: "/forgot-password/reset",
Handler: user.UpdatePasswordByVcodeHandler(serverCtx),
},
{
// 用户登录接口
Method: http.MethodPost,
Path: "/login",
Handler: user.LoginHandler(serverCtx),
},
{
// 用户注册接口
Method: http.MethodPost,
Path: "/register",
Handler: user.RegisterHandler(serverCtx),
},
}...,
),
[]rest.Route{
{
// 忘记密码-发送验证码
Method: http.MethodPost,
Path: "/forgot-password",
Handler: auth.ForgotPasswordHandler(serverCtx),
},
{
// 用户登录
Method: http.MethodPost,
Path: "/login",
Handler: auth.LoginHandler(serverCtx),
},
{
// 用户注册
Method: http.MethodPost,
Path: "/register",
Handler: auth.RegisterHandler(serverCtx),
},
{
// 重置密码
Method: http.MethodPost,
Path: "/reset-password",
Handler: auth.ResetPasswordHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1/auth"),
)
server.AddRoutes(
[]rest.Route{
{
// 退出登录
Method: http.MethodPost,
Path: "/logout",
Handler: auth.LogoutHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1/auth"),
)
@@ -57,16 +63,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Middleware{serverCtx.Logger},
[]rest.Route{
{
// 获取用户信息
Method: http.MethodGet,
Path: "/:userId",
Handler: user.GetUserInfoHandler(serverCtx),
// 关注用户
Method: http.MethodPost,
Path: "/:id/follow",
Handler: user.FollowUserHandler(serverCtx),
},
{
// 修改用户信息
Method: http.MethodPut,
Path: "/:userId",
Handler: user.UpdateUserInfoHandler(serverCtx),
// 取消关注用户
Method: http.MethodDelete,
Path: "/:id/follow",
Handler: user.UnfollowUserHandler(serverCtx),
},
{
// 获取当前登录用户信息
@@ -75,13 +81,88 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: user.GetMeHandler(serverCtx),
},
{
// 更改当前登录用户信息
// 更新个人资料
Method: http.MethodPut,
Path: "/me",
Handler: user.UpdateMeHandler(serverCtx),
},
{
// 更新通知偏好
Method: http.MethodPut,
Path: "/me/preferences/notifications",
Handler: user.UpdateNotificationSettingsHandler(serverCtx),
},
{
// 更新主题偏好
Method: http.MethodPut,
Path: "/me/preferences/theme",
Handler: user.UpdateThemeSettingsHandler(serverCtx),
},
{
// 切换当前激活角色
Method: http.MethodPost,
Path: "/me/switch-role",
Handler: user.SwitchRoleHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/v1/user"),
rest.WithPrefix("/api/v1/users"),
)
server.AddRoutes(
[]rest.Route{
{
// 获取指定用户信息
Method: http.MethodGet,
Path: "/:id",
Handler: user.GetUserInfoHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1/users"),
)
server.AddRoutes(
[]rest.Route{
{
// 管理员获取认证申请列表 (分页)
Method: http.MethodGet,
Path: "/verifications",
Handler: verification_admin.GetVerificationsHandler(serverCtx),
},
{
// 管理员通过申请
Method: http.MethodPost,
Path: "/verifications/:id/approve",
Handler: verification_admin.ApproveVerificationHandler(serverCtx),
},
{
// 管理员驳回申请
Method: http.MethodPost,
Path: "/verifications/:id/reject",
Handler: verification_admin.RejectVerificationHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1/admin"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.Logger},
[]rest.Route{
{
// 提交或修改角色认证申请 (支持幂等更新)
Method: http.MethodPost,
Path: "/me/verification",
Handler: verification_user.ApplyVerificationHandler(serverCtx),
},
{
// 获取我的所有认证状态
Method: http.MethodGet,
Path: "/me/verification",
Handler: verification_user.GetMyVerificationsHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/v1/users"),
)
}