refactor(struct):更改代码结构,隐藏控制器函数。
This commit is contained in:
parent
c3d3167e62
commit
c8982e5835
|
@ -19,11 +19,11 @@ func InitializeRegionController(router *gin.Engine) {
|
||||||
Router: router,
|
Router: router,
|
||||||
}
|
}
|
||||||
|
|
||||||
RegionController.Router.GET("/region/:rid", RegionController.FetchRegions)
|
RegionController.Router.GET("/region/:rid", fetchRegions)
|
||||||
RegionController.Router.GET("/regions/:rid", RegionController.FetchAllLeveledRegions)
|
RegionController.Router.GET("/regions/:rid", fetchAllLeveledRegions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_RegionController) FetchRegions(c *gin.Context) {
|
func fetchRegions(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
requestParentId := c.Param("rid")
|
requestParentId := c.Param("rid")
|
||||||
regions, err := service.RegionService.FetchSubRegions(requestParentId)
|
regions, err := service.RegionService.FetchSubRegions(requestParentId)
|
||||||
|
@ -38,7 +38,7 @@ func (_RegionController) FetchRegions(c *gin.Context) {
|
||||||
result.Json(http.StatusOK, "已经获取到相关的行政区划。", gin.H{"regions": regions})
|
result.Json(http.StatusOK, "已经获取到相关的行政区划。", gin.H{"regions": regions})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_RegionController) FetchAllLeveledRegions(c *gin.Context) {
|
func fetchAllLeveledRegions(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
requestRegionCode := c.Param("rid")
|
requestRegionCode := c.Param("rid")
|
||||||
regions, err := service.RegionService.FetchAllParentRegions(requestRegionCode)
|
regions, err := service.RegionService.FetchAllParentRegions(requestRegionCode)
|
||||||
|
|
|
@ -27,28 +27,28 @@ func InitializeUserController(router *gin.Engine) {
|
||||||
UserController = &_UserController{
|
UserController = &_UserController{
|
||||||
Router: router,
|
Router: router,
|
||||||
}
|
}
|
||||||
UserController.Router.POST("/login", UserController.Login)
|
UserController.Router.POST("/login", login)
|
||||||
UserController.Router.DELETE("/login", security.MustAuthenticated, UserController.Logout)
|
UserController.Router.DELETE("/login", security.MustAuthenticated, logout)
|
||||||
UserController.Router.DELETE("/password/:uid", security.OPSAuthorize, UserController.InvalidUserPassword)
|
UserController.Router.DELETE("/password/:uid", security.OPSAuthorize, invalidUserPassword)
|
||||||
UserController.Router.PUT("/password", UserController.ResetUserPassword)
|
UserController.Router.PUT("/password", resetUserPassword)
|
||||||
UserController.Router.GET("/accounts", security.OPSAuthorize, UserController.ListPagedUser)
|
UserController.Router.GET("/accounts", security.OPSAuthorize, listPagedUser)
|
||||||
UserController.Router.PUT("/account/enabled/state", security.OPSAuthorize, UserController.SwitchUserEnabling)
|
UserController.Router.PUT("/account/enabled/state", security.OPSAuthorize, switchUserEnabling)
|
||||||
UserController.Router.POST("/account", security.OPSAuthorize, UserController.CreateOPSAndManagementAccount)
|
UserController.Router.POST("/account", security.OPSAuthorize, createOPSAndManagementAccount)
|
||||||
UserController.Router.GET("/account/:uid", security.MustAuthenticated, UserController.GetUserDetail)
|
UserController.Router.GET("/account/:uid", security.MustAuthenticated, getUserDetail)
|
||||||
UserController.Router.POST("/enterprise", security.OPSAuthorize, UserController.CreateEnterpriseAccount)
|
UserController.Router.POST("/enterprise", security.OPSAuthorize, createEnterpriseAccount)
|
||||||
UserController.Router.PUT("/account/:uid", security.OPSAuthorize, UserController.ModifyAccountDetail)
|
UserController.Router.PUT("/account/:uid", security.OPSAuthorize, modifyAccountDetail)
|
||||||
UserController.Router.GET("/enterprise/quick/search", security.OPSAuthorize, UserController.QuickSearchEnterprise)
|
UserController.Router.GET("/enterprise/quick/search", security.OPSAuthorize, quickSearchEnterprise)
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginFormData struct {
|
type _LoginFormData struct {
|
||||||
Username string `json:"uname"`
|
Username string `json:"uname"`
|
||||||
Password string `json:"upass"`
|
Password string `json:"upass"`
|
||||||
Type int8 `json:"type"`
|
Type int8 `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) Login(c *gin.Context) {
|
func login(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
loginData := new(LoginFormData)
|
loginData := new(_LoginFormData)
|
||||||
err := c.BindJSON(loginData)
|
err := c.BindJSON(loginData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Error(http.StatusInternalServerError, "表单解析失败。")
|
result.Error(http.StatusInternalServerError, "表单解析失败。")
|
||||||
|
@ -78,7 +78,7 @@ func (_UserController) Login(c *gin.Context) {
|
||||||
result.LoginSuccess(session)
|
result.LoginSuccess(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) Logout(c *gin.Context) {
|
func logout(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
session, exists := c.Get("session")
|
session, exists := c.Get("session")
|
||||||
if !exists {
|
if !exists {
|
||||||
|
@ -93,7 +93,7 @@ func (_UserController) Logout(c *gin.Context) {
|
||||||
result.Success("用户已成功登出系统。")
|
result.Success("用户已成功登出系统。")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) InvalidUserPassword(c *gin.Context) {
|
func invalidUserPassword(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
targetUserId := c.Param("uid")
|
targetUserId := c.Param("uid")
|
||||||
verifyCode, err := service.UserService.InvalidUserPassword(targetUserId)
|
verifyCode, err := service.UserService.InvalidUserPassword(targetUserId)
|
||||||
|
@ -112,15 +112,15 @@ func (_UserController) InvalidUserPassword(c *gin.Context) {
|
||||||
result.Json(http.StatusAccepted, "用户密码已经失效", gin.H{"verify": verifyCode})
|
result.Json(http.StatusAccepted, "用户密码已经失效", gin.H{"verify": verifyCode})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResetPasswordFormData struct {
|
type _ResetPasswordFormData struct {
|
||||||
VerifyCode string `json:"verifyCode"`
|
VerifyCode string `json:"verifyCode"`
|
||||||
Username string `json:"uname"`
|
Username string `json:"uname"`
|
||||||
NewPassword string `json:"newPass"`
|
NewPassword string `json:"newPass"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) ResetUserPassword(c *gin.Context) {
|
func resetUserPassword(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
resetForm := new(ResetPasswordFormData)
|
resetForm := new(_ResetPasswordFormData)
|
||||||
c.BindJSON(resetForm)
|
c.BindJSON(resetForm)
|
||||||
verified, err := service.UserService.VerifyUserPassword(resetForm.Username, resetForm.VerifyCode)
|
verified, err := service.UserService.VerifyUserPassword(resetForm.Username, resetForm.VerifyCode)
|
||||||
if _, ok := err.(exceptions.NotFoundError); ok {
|
if _, ok := err.(exceptions.NotFoundError); ok {
|
||||||
|
@ -147,7 +147,7 @@ func (_UserController) ResetUserPassword(c *gin.Context) {
|
||||||
result.NotAccept("用户凭据未能成功更新。")
|
result.NotAccept("用户凭据未能成功更新。")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) ListPagedUser(c *gin.Context) {
|
func listPagedUser(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -180,14 +180,14 @@ func (_UserController) ListPagedUser(c *gin.Context) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserStateChangeFormData struct {
|
type _UserStateChangeFormData struct {
|
||||||
UserID string `json:"uid" form:"uid"`
|
UserID string `json:"uid" form:"uid"`
|
||||||
Enabled bool `json:"enabled" form:"enabled"`
|
Enabled bool `json:"enabled" form:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) SwitchUserEnabling(c *gin.Context) {
|
func switchUserEnabling(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
switchForm := new(UserStateChangeFormData)
|
switchForm := new(_UserStateChangeFormData)
|
||||||
c.BindJSON(switchForm)
|
c.BindJSON(switchForm)
|
||||||
err := service.UserService.SwitchUserState(switchForm.UserID, switchForm.Enabled)
|
err := service.UserService.SwitchUserState(switchForm.UserID, switchForm.Enabled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -202,7 +202,7 @@ func (_UserController) SwitchUserEnabling(c *gin.Context) {
|
||||||
result.Success("用户状态已经更新。")
|
result.Success("用户状态已经更新。")
|
||||||
}
|
}
|
||||||
|
|
||||||
type OPSAccountCreationFormData struct {
|
type _OPSAccountCreationFormData struct {
|
||||||
Username string `json:"username" form:"username"`
|
Username string `json:"username" form:"username"`
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Contact *string `json:"contact" form:"contact"`
|
Contact *string `json:"contact" form:"contact"`
|
||||||
|
@ -210,9 +210,9 @@ type OPSAccountCreationFormData struct {
|
||||||
Type int `json:"type" form:"type"`
|
Type int `json:"type" form:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) CreateOPSAndManagementAccount(c *gin.Context) {
|
func createOPSAndManagementAccount(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
creationForm := new(OPSAccountCreationFormData)
|
creationForm := new(_OPSAccountCreationFormData)
|
||||||
c.BindJSON(creationForm)
|
c.BindJSON(creationForm)
|
||||||
exists, err := service.UserService.IsUsernameExists(creationForm.Username)
|
exists, err := service.UserService.IsUsernameExists(creationForm.Username)
|
||||||
if exists {
|
if exists {
|
||||||
|
@ -241,7 +241,7 @@ func (_UserController) CreateOPSAndManagementAccount(c *gin.Context) {
|
||||||
result.Json(http.StatusCreated, "用户已经成功创建。", gin.H{"verify": verifyCode})
|
result.Json(http.StatusCreated, "用户已经成功创建。", gin.H{"verify": verifyCode})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) GetUserDetail(c *gin.Context) {
|
func getUserDetail(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
targetUserId := c.Param("uid")
|
targetUserId := c.Param("uid")
|
||||||
exists, err := service.UserService.IsUserExists(targetUserId)
|
exists, err := service.UserService.IsUserExists(targetUserId)
|
||||||
|
@ -260,7 +260,7 @@ func (_UserController) GetUserDetail(c *gin.Context) {
|
||||||
result.Json(http.StatusOK, "用户详细信息已获取到。", gin.H{"user": userDetail})
|
result.Json(http.StatusOK, "用户详细信息已获取到。", gin.H{"user": userDetail})
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnterpriseCreationFormData struct {
|
type _EnterpriseCreationFormData struct {
|
||||||
Username string `json:"username" form:"username"`
|
Username string `json:"username" form:"username"`
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Region *string `json:"region" form:"region"`
|
Region *string `json:"region" form:"region"`
|
||||||
|
@ -270,9 +270,9 @@ type EnterpriseCreationFormData struct {
|
||||||
UnitServiceFee *string `json:"unitServiceFee" form:"unitServiceFee"`
|
UnitServiceFee *string `json:"unitServiceFee" form:"unitServiceFee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) CreateEnterpriseAccount(c *gin.Context) {
|
func createEnterpriseAccount(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
creationForm := new(EnterpriseCreationFormData)
|
creationForm := new(_EnterpriseCreationFormData)
|
||||||
c.BindJSON(creationForm)
|
c.BindJSON(creationForm)
|
||||||
exists, err := service.UserService.IsUsernameExists(creationForm.Username)
|
exists, err := service.UserService.IsUsernameExists(creationForm.Username)
|
||||||
if exists {
|
if exists {
|
||||||
|
@ -306,7 +306,7 @@ func (_UserController) CreateEnterpriseAccount(c *gin.Context) {
|
||||||
result.Json(http.StatusCreated, "用户已经成功创建。", gin.H{"verify": verifyCode})
|
result.Json(http.StatusCreated, "用户已经成功创建。", gin.H{"verify": verifyCode})
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountModificationFormData struct {
|
type _AccountModificationFormData struct {
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Region *string `json:"region" form:"region"`
|
Region *string `json:"region" form:"region"`
|
||||||
Address *string `json:"address" form:"address"`
|
Address *string `json:"address" form:"address"`
|
||||||
|
@ -315,10 +315,10 @@ type AccountModificationFormData struct {
|
||||||
UnitServiceFee *string `json:"unitServiceFee" form:"unitServiceFee"`
|
UnitServiceFee *string `json:"unitServiceFee" form:"unitServiceFee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) ModifyAccountDetail(c *gin.Context) {
|
func modifyAccountDetail(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
targetUserId := c.Param("uid")
|
targetUserId := c.Param("uid")
|
||||||
modForm := new(AccountModificationFormData)
|
modForm := new(_AccountModificationFormData)
|
||||||
c.BindJSON(modForm)
|
c.BindJSON(modForm)
|
||||||
exists, err := service.UserService.IsUserExists(targetUserId)
|
exists, err := service.UserService.IsUserExists(targetUserId)
|
||||||
if !exists {
|
if !exists {
|
||||||
|
@ -348,7 +348,7 @@ func (_UserController) ModifyAccountDetail(c *gin.Context) {
|
||||||
result.Success("指定用户的信息已经更新。")
|
result.Success("指定用户的信息已经更新。")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) QuickSearchEnterprise(c *gin.Context) {
|
func quickSearchEnterprise(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
keyword := c.Query("keyword")
|
keyword := c.Query("keyword")
|
||||||
searchResult, err := service.UserService.SearchLimitUsers(keyword, 6)
|
searchResult, err := service.UserService.SearchLimitUsers(keyword, 6)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user