最新可以跑单元测试
This commit is contained in:
52
server/home-user-auth/internal/handler/routes.go
Normal file
52
server/home-user-auth/internal/handler/routes.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/login",
|
||||
Handler: UserLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/fonts",
|
||||
Handler: UserFontsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/get-type",
|
||||
Handler: UserGetTypeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/basic-info",
|
||||
Handler: UserSaveBasicInfoHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/status-config",
|
||||
Handler: UserStatusConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/basic-info",
|
||||
Handler: UserBasicInfoHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/address-list",
|
||||
Handler: UserAddressListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
m := model.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Use
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
|
||||
@@ -26,7 +26,7 @@ func NewUserGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserG
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
|
||||
|
||||
@@ -26,7 +26,7 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
|
||||
@@ -25,7 +25,7 @@ func NewUserStatusConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserStatusConfigLogic) UserStatusConfig(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserStatusConfigLogic) UserStatusConfig(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
|
||||
data := &types.DataStatusConfig{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
@@ -125,4 +125,43 @@ type Auth struct {
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *Response) Set(Code int, Message string) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
}
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
Data: Data,
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: msg,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user