feat(user): 添加用户相关接口和逻辑实现
- 新增登出接口 /logout - 新增检测登录状态接口 /user/checkLogin - 新增获取用户信息接口 /user/info - 新增第三方登录接口 /user/oauthAuthorize - 新增修改密码接口 /user/passWordReset - 新增更新用户信息接口 /user/update - 实现对应的业务逻辑结构体和处理函数 - 定义 OauthAuthorizeReq、OauthAuthorizeResp、PassWordResetReq 等数据模型 - 在路由中注册新增的用户相关接口处理器 - 调整登录响应码从 0 改为 200 以符合标准 HTTP 状态码规范
This commit is contained in:
parent
e1fbb33f48
commit
3779fe9701
|
|
@ -0,0 +1,45 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"mingyang-admin-app-api/internal/logic/user"
|
||||
"mingyang-admin-app-api/internal/svc"
|
||||
"mingyang-admin-app-api/internal/types"
|
||||
)
|
||||
|
||||
// swagger:route post /user/checkLogin user CheckLogin
|
||||
//
|
||||
// CheckLogin | 检测登录状态
|
||||
//
|
||||
// CheckLogin | 检测登录状态
|
||||
//
|
||||
// Parameters:
|
||||
// + name: body
|
||||
// require: true
|
||||
// in: body
|
||||
// type: IDReq
|
||||
//
|
||||
// Responses:
|
||||
// 200: BaseDataInfo
|
||||
|
||||
func CheckLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IDReq
|
||||
if err := httpx.Parse(r, &req, true); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewCheckLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CheckLogin(&req)
|
||||
if err != nil {
|
||||
err = svcCtx.Trans.TransError(r.Context(), err)
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"mingyang-admin-app-api/internal/logic/user"
|
||||
"mingyang-admin-app-api/internal/svc"
|
||||
)
|
||||
|
||||
// swagger:route post /user/info user GetUserInfoByToken
|
||||
//
|
||||
//@ Get UserInfo detail By Token | 获取用户信息
|
||||
//
|
||||
//@ Get UserInfo detail By Token | 获取用户信息
|
||||
//
|
||||
// Responses:
|
||||
// 200: UserInfo
|
||||
|
||||
func GetUserInfoByTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := user.NewGetUserInfoByTokenLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUserInfoByToken()
|
||||
if err != nil {
|
||||
err = svcCtx.Trans.TransError(r.Context(), err)
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"mingyang-admin-app-api/internal/logic/user"
|
||||
"mingyang-admin-app-api/internal/svc"
|
||||
"mingyang-admin-app-api/internal/types"
|
||||
)
|
||||
|
||||
// swagger:route post /logout user Logout
|
||||
//
|
||||
//登出
|
||||
//
|
||||
//登出
|
||||
//
|
||||
// Parameters:
|
||||
// + name: body
|
||||
// require: true
|
||||
// in: body
|
||||
// type: IDReq
|
||||
//
|
||||
// Responses:
|
||||
// 200: BaseDataInfo
|
||||
|
||||
func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IDReq
|
||||
if err := httpx.Parse(r, &req, true); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewLogoutLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Logout(&req)
|
||||
if err != nil {
|
||||
err = svcCtx.Trans.TransError(r.Context(), err)
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"mingyang-admin-app-api/internal/logic/user"
|
||||
"mingyang-admin-app-api/internal/svc"
|
||||
"mingyang-admin-app-api/internal/types"
|
||||
)
|
||||
|
||||
// swagger:route post /user/oauthAuthorize user OauthAuthorize
|
||||
//
|
||||
//OauthAuthorize | 第三方登录接口
|
||||
//
|
||||
//OauthAuthorize | 第三方登录接口
|
||||
//
|
||||
// Parameters:
|
||||
// + name: body
|
||||
// require: true
|
||||
// in: body
|
||||
// type: OauthAuthorizeReq
|
||||
//
|
||||
// Responses:
|
||||
// 200: OauthAuthorizeResp
|
||||
|
||||
func OauthAuthorizeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OauthAuthorizeReq
|
||||
if err := httpx.Parse(r, &req, true); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewOauthAuthorizeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.OauthAuthorize(&req)
|
||||
if err != nil {
|
||||
err = svcCtx.Trans.TransError(r.Context(), err)
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"mingyang-admin-app-api/internal/logic/user"
|
||||
"mingyang-admin-app-api/internal/svc"
|
||||
"mingyang-admin-app-api/internal/types"
|
||||
)
|
||||
|
||||
// swagger:route post /user/passWordReset user PassWordReset
|
||||
//
|
||||
// PassWordReset | 修改密码
|
||||
//
|
||||
// PassWordReset | 修改密码
|
||||
//
|
||||
// Parameters:
|
||||
// + name: body
|
||||
// require: true
|
||||
// in: body
|
||||
// type: PassWordResetReq
|
||||
//
|
||||
// Responses:
|
||||
// 200: BaseDataInfo
|
||||
|
||||
func PassWordResetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PassWordResetReq
|
||||
if err := httpx.Parse(r, &req, true); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewPassWordResetLogic(r.Context(), svcCtx)
|
||||
resp, err := l.PassWordReset(&req)
|
||||
if err != nil {
|
||||
err = svcCtx.Trans.TransError(r.Context(), err)
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"mingyang-admin-app-api/internal/logic/user"
|
||||
"mingyang-admin-app-api/internal/svc"
|
||||
"mingyang-admin-app-api/internal/types"
|
||||
)
|
||||
|
||||
// swagger:route post /user/update user UpdateUserInfo
|
||||
//
|
||||
//Update userInfo | 更新用户信息
|
||||
//
|
||||
//Update userInfo | 更新用户信息
|
||||
//
|
||||
// Parameters:
|
||||
// + name: body
|
||||
// require: true
|
||||
// in: body
|
||||
// type: UserInfo
|
||||
//
|
||||
// Responses:
|
||||
// 200: BaseDataInfo
|
||||
|
||||
func UpdateUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UserInfo
|
||||
if err := httpx.Parse(r, &req, true); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewUpdateUserInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateUserInfo(&req)
|
||||
if err != nil {
|
||||
err = svcCtx.Trans.TransError(r.Context(), err)
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue