Refactor API routes and controllers for improved structure and clarity
- Updated API route structure to remove versioning and consolidate endpoints. - Refactored routing in `server.go` to use a unified `/api` prefix for all controllers. - Added new `ChannelController`, `ConversationController`, and `MessageController` to handle specific API functionalities. - Removed deprecated `OpenImContextMiddleware` and related logic. - Enhanced channel validation logic in `ChannelService` and `ChannelRepository`. - Updated frontend API calls to align with new endpoint structure.
This commit is contained in:
+4
-5
@@ -1,20 +1,19 @@
|
||||
package open
|
||||
package api
|
||||
|
||||
import (
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/irisx"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
type ImWidgetController struct {
|
||||
type ChannelController struct {
|
||||
Ctx iris.Context
|
||||
}
|
||||
|
||||
func (c *ImWidgetController) AnyConfig() *web.JsonResult {
|
||||
channel := irisx.GetChannel(c.Ctx)
|
||||
func (c *ChannelController) AnyConfig() *web.JsonResult {
|
||||
channel := services.ChannelService.GetEnabledChannel(c.Ctx)
|
||||
if channel == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
package open
|
||||
package api
|
||||
|
||||
import (
|
||||
"cs-agent/internal/builders"
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
type ImConversationController struct {
|
||||
type ConversationController struct {
|
||||
Ctx iris.Context
|
||||
}
|
||||
|
||||
func (c *ImConversationController) GetBy(id int64) *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *ConversationController) GetBy(id int64) *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
@@ -40,8 +40,8 @@ func (c *ImConversationController) GetBy(id int64) *web.JsonResult {
|
||||
return web.JsonData(detail)
|
||||
}
|
||||
|
||||
func (c *ImConversationController) PostCreate_or_match() *web.JsonResult {
|
||||
channel := irisx.GetChannel(c.Ctx)
|
||||
func (c *ConversationController) PostCreate_or_match() *web.JsonResult {
|
||||
channel := services.ChannelService.GetEnabledChannel(c.Ctx)
|
||||
if channel == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
@@ -57,8 +57,8 @@ func (c *ImConversationController) PostCreate_or_match() *web.JsonResult {
|
||||
return web.JsonData(builders.BuildConversation(item))
|
||||
}
|
||||
|
||||
func (c *ImConversationController) PostClose() *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *ConversationController) PostClose() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
+12
-12
@@ -1,4 +1,4 @@
|
||||
package open
|
||||
package api
|
||||
|
||||
import (
|
||||
"cs-agent/internal/builders"
|
||||
@@ -15,12 +15,12 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type ImMessageController struct {
|
||||
type MessageController struct {
|
||||
Ctx iris.Context
|
||||
}
|
||||
|
||||
func (c *ImMessageController) AnyList() *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *MessageController) AnyList() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
@@ -53,8 +53,8 @@ func (c *ImMessageController) AnyList() *web.JsonResult {
|
||||
return web.JsonCursorData(results, cast.ToString(nextCursor), hasMore)
|
||||
}
|
||||
|
||||
func (c *ImMessageController) PostSend() *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *MessageController) PostSend() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
@@ -74,8 +74,8 @@ func (c *ImMessageController) PostSend() *web.JsonResult {
|
||||
return web.JsonData(builders.BuildMessage(item))
|
||||
}
|
||||
|
||||
func (c *ImMessageController) PostRead() *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *MessageController) PostRead() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
@@ -93,8 +93,8 @@ func (c *ImMessageController) PostRead() *web.JsonResult {
|
||||
return web.JsonSuccess()
|
||||
}
|
||||
|
||||
func (c *ImMessageController) PostUpload_image() *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *MessageController) PostUpload_image() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
@@ -138,8 +138,8 @@ func (c *ImMessageController) PostUpload_image() *web.JsonResult {
|
||||
return web.JsonData(builders.BuildAsset(item))
|
||||
}
|
||||
|
||||
func (c *ImMessageController) PostUpload_attachment() *web.JsonResult {
|
||||
if irisx.GetChannel(c.Ctx) == nil {
|
||||
func (c *MessageController) PostUpload_attachment() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalInfo(c.Ctx)
|
||||
Reference in New Issue
Block a user