From e1fbb33f4877ae54589cc7cd88f3eb06a8a14d8b Mon Sep 17 00:00:00 2001 From: huanglei19951029 <81128461+huanglei19951029@users.noreply.github.com> Date: Mon, 15 Dec 2025 11:22:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=92=8C=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增登出接口 /logout - 新增检测登录状态接口 /user/checkLogin - 新增获取用户信息接口 /user/info - 新增第三方登录接口 /user/oauthAuthorize - 新增修改密码接口 /user/passWordReset - 新增更新用户信息接口 /user/update - 实现对应的业务逻辑结构体和处理函数 - 定义 OauthAuthorizeReq、OauthAuthorizeResp、PassWordResetReq 等数据模型 - 在路由中注册新增的用户相关接口处理器 - 调整登录响应码从 0 改为 200 以符合标准 HTTP 状态码规范 --- api/app.json | 195 ++++++++++++++++++ api/desc/app/user.api | 39 ++++ api/internal/handler/routes.go | 30 +++ api/internal/logic/user/check_login_logic.go | 30 +++ .../user/get_user_info_by_token_logic.go | 30 +++ api/internal/logic/user/logout_logic.go | 29 +++ .../logic/user/oauth_authorize_logic.go | 30 +++ .../logic/user/pass_word_reset_logic.go | 30 +++ .../logic/user/update_user_info_logic.go | 30 +++ api/internal/logic/user_public/login_logic.go | 3 +- api/internal/types/types.go | 17 ++ 11 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 api/internal/logic/user/check_login_logic.go create mode 100644 api/internal/logic/user/get_user_info_by_token_logic.go create mode 100644 api/internal/logic/user/logout_logic.go create mode 100644 api/internal/logic/user/oauth_authorize_logic.go create mode 100644 api/internal/logic/user/pass_word_reset_logic.go create mode 100644 api/internal/logic/user/update_user_info_logic.go diff --git a/api/app.json b/api/app.json index 886fd7f..e7cfeb9 100644 --- a/api/app.json +++ b/api/app.json @@ -92,6 +92,34 @@ } } }, + "/logout": { + "post": { + "description": "登出", + "tags": [ + "user" + ], + "summary": "登出", + "operationId": "Logout", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "type": "object", + "$ref": "#/definitions/IDReq" + } + } + ], + "responses": { + "200": { + "description": "BaseDataInfo", + "schema": { + "$ref": "#/definitions/BaseDataInfo" + } + } + } + } + }, "/register": { "post": { "description": "Register | 注册", @@ -148,6 +176,52 @@ } } }, + "/user/checkLogin": { + "post": { + "description": "CheckLogin | 检测登录状态", + "tags": [ + "user" + ], + "summary": "CheckLogin | 检测登录状态", + "operationId": "CheckLogin", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "type": "object", + "$ref": "#/definitions/IDReq" + } + } + ], + "responses": { + "200": { + "description": "BaseDataInfo", + "schema": { + "$ref": "#/definitions/BaseDataInfo" + } + } + } + } + }, + "/user/info": { + "post": { + "description": "@ Get UserInfo detail By Token | 获取用户信息", + "tags": [ + "user" + ], + "summary": "@ Get UserInfo detail By Token | 获取用户信息", + "operationId": "GetUserInfoByToken", + "responses": { + "200": { + "description": "UserInfo", + "schema": { + "$ref": "#/definitions/UserInfo" + } + } + } + } + }, "/user/list": { "post": { "description": "List userInfo | 获取用户列表", @@ -175,6 +249,90 @@ } } } + }, + "/user/oauthAuthorize": { + "post": { + "description": "OauthAuthorize | 第三方登录接口", + "tags": [ + "user" + ], + "summary": "OauthAuthorize | 第三方登录接口", + "operationId": "OauthAuthorize", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "type": "object", + "$ref": "#/definitions/OauthAuthorizeReq" + } + } + ], + "responses": { + "200": { + "description": "OauthAuthorizeResp", + "schema": { + "$ref": "#/definitions/OauthAuthorizeResp" + } + } + } + } + }, + "/user/passWordReset": { + "post": { + "description": "PassWordReset | 修改密码", + "tags": [ + "user" + ], + "summary": "PassWordReset | 修改密码", + "operationId": "PassWordReset", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "type": "object", + "$ref": "#/definitions/PassWordResetReq" + } + } + ], + "responses": { + "200": { + "description": "BaseDataInfo", + "schema": { + "$ref": "#/definitions/BaseDataInfo" + } + } + } + } + }, + "/user/update": { + "post": { + "description": "Update userInfo | 更新用户信息", + "tags": [ + "user" + ], + "summary": "Update userInfo | 更新用户信息", + "operationId": "UpdateUserInfo", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "type": "object", + "$ref": "#/definitions/UserInfo" + } + } + ], + "responses": { + "200": { + "description": "BaseDataInfo", + "schema": { + "$ref": "#/definitions/BaseDataInfo" + } + } + } + } } }, "definitions": { @@ -719,6 +877,27 @@ }, "x-go-package": "mingyang-admin-app-api/internal/types" }, + "OauthAuthorizeReq": { + "type": "object", + "x-go-package": "mingyang-admin-app-api/internal/types" + }, + "OauthAuthorizeResp": { + "type": "object", + "properties": { + "code": { + "description": "Error code | 错误代码", + "type": "integer", + "format": "int64", + "x-go-name": "Code" + }, + "msg": { + "description": "Message | 提示信息", + "type": "string", + "x-go-name": "Msg" + } + }, + "x-go-package": "mingyang-admin-app-api/internal/types" + }, "PageInfo": { "description": "The page request parameters | 列表请求参数", "type": "object", @@ -744,6 +923,22 @@ }, "x-go-package": "mingyang-admin-app-api/internal/types" }, + "PassWordResetReq": { + "type": "object", + "properties": { + "password": { + "description": "Password", + "type": "string", + "x-go-name": "Password" + }, + "userName": { + "description": "UserName or Email or Mobile", + "type": "string", + "x-go-name": "UserName" + } + }, + "x-go-package": "mingyang-admin-app-api/internal/types" + }, "RegisterReq": { "type": "object", "properties": { diff --git a/api/desc/app/user.api b/api/desc/app/user.api index 38bc6d4..a044057 100644 --- a/api/desc/app/user.api +++ b/api/desc/app/user.api @@ -139,6 +139,19 @@ type ( // The device list data | User信息列表数据 Data []UserInfo `json:"data"` } + OauthAuthorizeReq { + + } + OauthAuthorizeResp { + BaseMsgResp + } + PassWordResetReq { + // UserName or Email or Mobile + UserName string `json:"userName,optional"` + // Password + Password string `json:"password"` + } + ) @server ( @@ -167,9 +180,35 @@ service App { // Get userInfo detail by ID | 获取用户信息 @handler getUserInfoById post /user (IDReq) returns (UserInfo) + + //@ Get UserInfo detail By Token | 获取用户信息 + @handler getUserInfoByToken + post /user/info () returns (UserInfo) //List userInfo | 获取用户列表 @handler listUserInfo post /user/list (UserListReq) returns (UserListResp) + + //Update userInfo | 更新用户信息 + @handler updateUserInfo + post /user/update (UserInfo) returns (BaseDataInfo) + + // Logout | 退出登录 + @handler logout + post /user/logout (IDReq) returns (BaseDataInfo) + + // PassWordReset | 修改密码 + @handler passWordReset + post /user/passWordReset (PassWordResetReq) returns (BaseDataInfo) + + // CheckLogin | 检测登录状态 + @handler checkLogin + post /user/checkLogin (IDReq) returns (BaseDataInfo) + + //OauthAuthorize | 第三方登录接口 + @handler oauthAuthorize + post /user/oauthAuthorize (OauthAuthorizeReq) returns (OauthAuthorizeResp) + + } diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 7ac6f5c..95768c9 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -54,11 +54,41 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/user", Handler: user.GetUserInfoByIdHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/user/info", + Handler: user.GetUserInfoByTokenHandler(serverCtx), + }, { Method: http.MethodPost, Path: "/user/list", Handler: user.ListUserInfoHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/user/update", + Handler: user.UpdateUserInfoHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/user/logout", + Handler: user.LogoutHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/user/passWordReset", + Handler: user.PassWordResetHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/user/checkLogin", + Handler: user.CheckLoginHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/user/oauthAuthorize", + Handler: user.OauthAuthorizeHandler(serverCtx), + }, }..., ), ) diff --git a/api/internal/logic/user/check_login_logic.go b/api/internal/logic/user/check_login_logic.go new file mode 100644 index 0000000..063dc99 --- /dev/null +++ b/api/internal/logic/user/check_login_logic.go @@ -0,0 +1,30 @@ +package user + +import ( + "context" + + "mingyang-admin-app-api/internal/svc" + "mingyang-admin-app-api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CheckLoginLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCheckLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckLoginLogic { + return &CheckLoginLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CheckLoginLogic) CheckLogin(req *types.IDReq) (resp *types.BaseDataInfo, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/user/get_user_info_by_token_logic.go b/api/internal/logic/user/get_user_info_by_token_logic.go new file mode 100644 index 0000000..736eb41 --- /dev/null +++ b/api/internal/logic/user/get_user_info_by_token_logic.go @@ -0,0 +1,30 @@ +package user + +import ( + "context" + + "mingyang-admin-app-api/internal/svc" + "mingyang-admin-app-api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetUserInfoByTokenLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetUserInfoByTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoByTokenLogic { + return &GetUserInfoByTokenLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetUserInfoByTokenLogic) GetUserInfoByToken() (resp *types.UserInfo, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/user/logout_logic.go b/api/internal/logic/user/logout_logic.go new file mode 100644 index 0000000..285f886 --- /dev/null +++ b/api/internal/logic/user/logout_logic.go @@ -0,0 +1,29 @@ +package user + +import ( + "context" + + "mingyang-admin-app-api/internal/svc" + "mingyang-admin-app-api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type LogoutLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic { + return &LogoutLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *LogoutLogic) Logout(req *types.IDReq) (resp *types.BaseDataInfo, err error) { + + return +} diff --git a/api/internal/logic/user/oauth_authorize_logic.go b/api/internal/logic/user/oauth_authorize_logic.go new file mode 100644 index 0000000..ce2266b --- /dev/null +++ b/api/internal/logic/user/oauth_authorize_logic.go @@ -0,0 +1,30 @@ +package user + +import ( + "context" + + "mingyang-admin-app-api/internal/svc" + "mingyang-admin-app-api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type OauthAuthorizeLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewOauthAuthorizeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OauthAuthorizeLogic { + return &OauthAuthorizeLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *OauthAuthorizeLogic) OauthAuthorize(req *types.OauthAuthorizeReq) (resp *types.OauthAuthorizeResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/user/pass_word_reset_logic.go b/api/internal/logic/user/pass_word_reset_logic.go new file mode 100644 index 0000000..ced931e --- /dev/null +++ b/api/internal/logic/user/pass_word_reset_logic.go @@ -0,0 +1,30 @@ +package user + +import ( + "context" + + "mingyang-admin-app-api/internal/svc" + "mingyang-admin-app-api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type PassWordResetLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewPassWordResetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PassWordResetLogic { + return &PassWordResetLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *PassWordResetLogic) PassWordReset(req *types.PassWordResetReq) (resp *types.BaseDataInfo, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/user/update_user_info_logic.go b/api/internal/logic/user/update_user_info_logic.go new file mode 100644 index 0000000..7ee805a --- /dev/null +++ b/api/internal/logic/user/update_user_info_logic.go @@ -0,0 +1,30 @@ +package user + +import ( + "context" + + "mingyang-admin-app-api/internal/svc" + "mingyang-admin-app-api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateUserInfoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInfoLogic { + return &UpdateUserInfoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateUserInfoLogic) UpdateUserInfo(req *types.UserInfo) (resp *types.BaseDataInfo, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/user_public/login_logic.go b/api/internal/logic/user_public/login_logic.go index 4f91ad7..2e41049 100644 --- a/api/internal/logic/user_public/login_logic.go +++ b/api/internal/logic/user_public/login_logic.go @@ -39,8 +39,7 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err erro user := loginUser.User return &types.LoginResp{ BaseMsgResp: types.BaseMsgResp{ - Code: 0, - Msg: "登录成功", + Code: 200, }, AuthToken: &types.AuthToken{ AccessToken: token.AccessToken, diff --git a/api/internal/types/types.go b/api/internal/types/types.go index f3d9e3b..9cb1aa0 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -397,3 +397,20 @@ type UserListInfo struct { // The device list data | User信息列表数据 Data []UserInfo `json:"data"` } + +// swagger:model OauthAuthorizeReq +type OauthAuthorizeReq struct { +} + +// swagger:model OauthAuthorizeResp +type OauthAuthorizeResp struct { + BaseMsgResp +} + +// swagger:model PassWordResetReq +type PassWordResetReq struct { + // UserName or Email or Mobile + UserName string `json:"userName,optional"` + // Password + Password string `json:"password"` +}