feat(im): Task 5 - IM REST Controller + Router + Wire 集成
IMController (REST API):
- GET /api/v1/im/conversations: 会话列表
- GET /api/v1/im/messages: 历史消息(游标分页)
- PUT /api/v1/im/conversations/:id/pin: 置顶/取消
- DELETE /api/v1/im/conversations/🆔 删除会话
- DELETE /api/v1/im/conversations/:id/messages: 清空记录
- GET /api/v1/im/messages/search: 全局搜索
- GET /api/v1/im/unread: 全局未读数
Wire 集成:
- IMSet Provider Set + wire.Bind 接口注入
- App struct 新增 IM 字段
- wire_gen.go 手动更新
- OfflinePusher 通过 SetOfflinePusher 注入 WS Handler
Made-with: Cursor
This commit is contained in:
60
backend/go-service/app/im/provider.go
Normal file
60
backend/go-service/app/im/provider.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package im
|
||||
|
||||
import (
|
||||
"github.com/echochat/backend/app/im/controller"
|
||||
"github.com/echochat/backend/app/im/dao"
|
||||
"github.com/echochat/backend/app/im/handler"
|
||||
"github.com/echochat/backend/app/im/service"
|
||||
"github.com/echochat/backend/pkg/ws"
|
||||
"github.com/google/wire"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ProvideConversationDAO 创建 ConversationDAO 实例
|
||||
func ProvideConversationDAO(db *gorm.DB) *dao.ConversationDAO {
|
||||
return dao.NewConversationDAO(db)
|
||||
}
|
||||
|
||||
// ProvideMessageDAO 创建 MessageDAO 实例
|
||||
func ProvideMessageDAO(db *gorm.DB) *dao.MessageDAO {
|
||||
return dao.NewMessageDAO(db)
|
||||
}
|
||||
|
||||
// ProvideIMService 创建 IMService 实例
|
||||
// friendChecker 和 userInfoGetter 由 contact 模块的 FriendshipDAO 隐式实现
|
||||
func ProvideIMService(
|
||||
convDAO *dao.ConversationDAO,
|
||||
msgDAO *dao.MessageDAO,
|
||||
pubsub *ws.PubSub,
|
||||
rdb *redis.Client,
|
||||
friendChecker service.FriendChecker,
|
||||
userInfoGetter service.UserInfoGetter,
|
||||
) *service.IMService {
|
||||
return service.NewIMService(convDAO, msgDAO, pubsub, rdb, friendChecker, userInfoGetter)
|
||||
}
|
||||
|
||||
// ProvideIMEventHandler 创建 IM WS 事件处理器并注册事件到 Hub
|
||||
func ProvideIMEventHandler(imService *service.IMService, hub *ws.Hub) *handler.EventHandler {
|
||||
return handler.NewEventHandler(imService, hub)
|
||||
}
|
||||
|
||||
// ProvideOfflinePusher 创建离线消息推送器
|
||||
func ProvideOfflinePusher(imService *service.IMService, convDAO *dao.ConversationDAO, pubsub *ws.PubSub) *handler.OfflinePusher {
|
||||
return handler.NewOfflinePusher(imService, convDAO, pubsub)
|
||||
}
|
||||
|
||||
// ProvideIMController 创建 IM REST 控制器
|
||||
func ProvideIMController(imService *service.IMService) *controller.IMController {
|
||||
return controller.NewIMController(imService)
|
||||
}
|
||||
|
||||
// IMSet IM 模块 Wire Provider Set
|
||||
var IMSet = wire.NewSet(
|
||||
ProvideConversationDAO,
|
||||
ProvideMessageDAO,
|
||||
ProvideIMService,
|
||||
ProvideIMEventHandler,
|
||||
ProvideOfflinePusher,
|
||||
ProvideIMController,
|
||||
)
|
||||
Reference in New Issue
Block a user