refactor: simplify route handlers by removing redundant ID parsing logic
This commit is contained in:
@@ -32,7 +32,7 @@ func Login(ctx *gin.Context) {
|
||||
func WxWorkLogin(ctx *gin.Context) {
|
||||
loginURL, err := services.WxWorkLoginService.BuildWxWorkLoginURL(ctx.Query("next"))
|
||||
if err != nil {
|
||||
redirectWxWorkError(ctx, err.Error())
|
||||
ctx.Redirect(http.StatusFound, "/login?wxworkError="+url.QueryEscape(wxWorkErrorMessage(err.Error())))
|
||||
return
|
||||
}
|
||||
ctx.Redirect(http.StatusFound, loginURL)
|
||||
@@ -41,7 +41,7 @@ func WxWorkLogin(ctx *gin.Context) {
|
||||
func WxWorkQRLogin(ctx *gin.Context) {
|
||||
loginURL, err := services.WxWorkLoginService.BuildWxWorkQRCodeLoginURL(ctx.Query("next"))
|
||||
if err != nil {
|
||||
redirectWxWorkError(ctx, err.Error())
|
||||
ctx.Redirect(http.StatusFound, "/login?wxworkError="+url.QueryEscape(wxWorkErrorMessage(err.Error())))
|
||||
return
|
||||
}
|
||||
ctx.Redirect(http.StatusFound, loginURL)
|
||||
@@ -57,7 +57,7 @@ func WxWorkCallback(ctx *gin.Context) {
|
||||
ctx.GetHeader("User-Agent"),
|
||||
)
|
||||
if err != nil {
|
||||
redirectWxWorkError(ctx, err.Error())
|
||||
ctx.Redirect(http.StatusFound, "/login?wxworkError="+url.QueryEscape(wxWorkErrorMessage(err.Error())))
|
||||
return
|
||||
}
|
||||
ctx.Redirect(http.StatusFound, "/dashboard/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next))
|
||||
@@ -94,9 +94,9 @@ func Profile(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, ret)
|
||||
}
|
||||
|
||||
func redirectWxWorkError(ctx *gin.Context, message string) {
|
||||
func wxWorkErrorMessage(message string) string {
|
||||
if idx := strings.Index(message, ": "); idx >= 0 {
|
||||
message = message[idx+2:]
|
||||
}
|
||||
ctx.Redirect(http.StatusFound, "/login?wxworkError="+url.QueryEscape(message))
|
||||
return message
|
||||
}
|
||||
|
||||
@@ -13,7 +13,11 @@ import (
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
func ConversationGetBy(ctx *gin.Context, id int64) {
|
||||
func ConversationGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if services.ChannelService.GetEnabledChannel(ctx) == nil {
|
||||
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
|
||||
return
|
||||
|
||||
@@ -44,7 +44,11 @@ func AgentGetList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, builders.BuildAgentProfileList(list))
|
||||
}
|
||||
|
||||
func AgentGetBy(ctx *gin.Context, id int64) {
|
||||
func AgentGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAgentView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -46,7 +46,11 @@ func AgentRunLogAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func AgentRunLogGetBy(ctx *gin.Context, id int64) {
|
||||
func AgentRunLogGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionConversationView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -50,7 +50,11 @@ func AgentTeamGetList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func AgentTeamGetBy(ctx *gin.Context, id int64) {
|
||||
func AgentTeamGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAgentTeamView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -93,7 +93,11 @@ func AgentTeamSchedulePostBatch_generate(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, builders.BuildAgentTeamScheduleBatchGenerateResponse(ret))
|
||||
}
|
||||
|
||||
func AgentTeamScheduleGetBy(ctx *gin.Context, id int64) {
|
||||
func AgentTeamScheduleGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAgentTeamScheduleView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -52,7 +52,11 @@ func AIAgentGetList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func AIAgentGetBy(ctx *gin.Context, id int64) {
|
||||
func AIAgentGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -50,7 +50,11 @@ func AIConfigAnyList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func AIConfigGetBy(ctx *gin.Context, id int64) {
|
||||
func AIConfigGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIConfigView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -40,7 +40,11 @@ func AssetAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func AssetGetBy(ctx *gin.Context, id int64) {
|
||||
func AssetGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAssetView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -33,7 +33,11 @@ func ChannelAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func ChannelGetBy(ctx *gin.Context, id int64) {
|
||||
func ChannelGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionChannelView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -37,7 +37,11 @@ func CompanyAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func CompanyGetBy(ctx *gin.Context, id int64) {
|
||||
func CompanyGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionCompanyView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -99,7 +99,11 @@ func ConversationAnyConversations(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func ConversationGetBy(ctx *gin.Context, id int64) {
|
||||
func ConversationGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionConversationView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -29,7 +29,11 @@ func CustomerPostList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: builders.BuildCustomerList(list), Page: paging})
|
||||
}
|
||||
|
||||
func CustomerGetBy(ctx *gin.Context, id int64) {
|
||||
func CustomerGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -60,7 +60,11 @@ func KnowledgeBaseAnyList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func KnowledgeBaseGetBy(ctx *gin.Context, id int64) {
|
||||
func KnowledgeBaseGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeBaseView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -47,7 +47,11 @@ func KnowledgeDocumentAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func KnowledgeDocumentGetBy(ctx *gin.Context, id int64) {
|
||||
func KnowledgeDocumentGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeDocumentView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -33,7 +33,11 @@ func KnowledgeFAQAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func KnowledgeFAQGetBy(ctx *gin.Context, id int64) {
|
||||
func KnowledgeFAQGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeFAQView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -48,7 +48,11 @@ func KnowledgeRetrieveLogAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func KnowledgeRetrieveLogGetBy(ctx *gin.Context, id int64) {
|
||||
func KnowledgeRetrieveLogGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeDocumentView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -47,7 +47,11 @@ func PermissionAnyList(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
||||
}
|
||||
|
||||
func PermissionGetBy(ctx *gin.Context, id int64) {
|
||||
func PermissionGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionPermissionView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -59,7 +59,11 @@ func RoleGetList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func RoleGetBy(ctx *gin.Context, id int64) {
|
||||
func RoleGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionRoleView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -61,7 +61,11 @@ func SkillDefinitionGetList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func SkillDefinitionGetBy(ctx *gin.Context, id int64) {
|
||||
func SkillDefinitionGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -37,7 +37,11 @@ func TagGetList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func TagGetBy(ctx *gin.Context, id int64) {
|
||||
func TagGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionTagView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -118,7 +118,11 @@ func TicketPostDelete_view(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, nil)
|
||||
}
|
||||
|
||||
func TicketGetBy(ctx *gin.Context, id int64) {
|
||||
func TicketGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionTicketView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
@@ -56,7 +56,11 @@ func UserAnyList_all(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, results)
|
||||
}
|
||||
|
||||
func UserGetBy(ctx *gin.Context, id int64) {
|
||||
func UserGetBy(ctx *gin.Context) {
|
||||
id, ok := httpx.GetPathInt64(ctx, "id")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionUserView); err != nil {
|
||||
httpx.WriteJSON(ctx, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user