refactor(di): migrate from setter to constructor injection for logService
- Remove SetLogService methods from user, post, comment, and admin post services - Add logService as constructor parameter to all dependent services - Centralize call-related and message error definitions in app_errors.go - Add ConversationID field to WSEventResponse for improved message tracking - Simplify wire provider functions by removing manual setter calls
This commit is contained in:
@@ -363,13 +363,14 @@ func (h *MessageHandler) HandleSendMessage(c *gin.Context) {
|
||||
|
||||
// 构建 WSEventResponse 格式响应
|
||||
wsResponse := dto.WSEventResponse{
|
||||
ID: msg.ID,
|
||||
Time: msg.CreatedAt.UnixMilli(),
|
||||
Type: "message",
|
||||
DetailType: params.DetailType,
|
||||
Seq: strconv.FormatInt(msg.Seq, 10),
|
||||
Segments: params.Segments,
|
||||
SenderID: userID,
|
||||
ID: msg.ID,
|
||||
Time: msg.CreatedAt.UnixMilli(),
|
||||
Type: "message",
|
||||
DetailType: params.DetailType,
|
||||
ConversationID: conversationID,
|
||||
Seq: strconv.FormatInt(msg.Seq, 10),
|
||||
Segments: params.Segments,
|
||||
SenderID: userID,
|
||||
}
|
||||
|
||||
response.Success(c, wsResponse)
|
||||
|
||||
@@ -39,10 +39,11 @@ type UserHandler struct {
|
||||
}
|
||||
|
||||
// NewUserHandler 创建用户处理器
|
||||
func NewUserHandler(userService service.UserService, activityService service.UserActivityService) *UserHandler {
|
||||
func NewUserHandler(userService service.UserService, activityService service.UserActivityService, logService *service.LogService) *UserHandler {
|
||||
return &UserHandler{
|
||||
userService: userService,
|
||||
activityService: activityService,
|
||||
logService: logService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +57,6 @@ func (h *UserHandler) SetActivityService(activityService service.UserActivitySer
|
||||
h.activityService = activityService
|
||||
}
|
||||
|
||||
// SetLogService 设置日志服务
|
||||
func (h *UserHandler) SetLogService(logService *service.LogService) {
|
||||
h.logService = logService
|
||||
}
|
||||
|
||||
// generateTokenID 生成Token ID
|
||||
func generateTokenID(token string) string {
|
||||
h := sha256.New()
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"carrot_bbs/internal/dto"
|
||||
apperrors "carrot_bbs/internal/errors"
|
||||
"carrot_bbs/internal/model"
|
||||
"carrot_bbs/internal/pkg/response"
|
||||
"carrot_bbs/internal/pkg/ws"
|
||||
@@ -338,13 +339,14 @@ func (h *WSHandler) handleChat(ctx context.Context, client *ws.Client, payload j
|
||||
}
|
||||
|
||||
resp := dto.WSEventResponse{
|
||||
ID: message.ID,
|
||||
Time: message.CreatedAt.UnixMilli(),
|
||||
Type: "message",
|
||||
DetailType: detailType,
|
||||
Seq: strconv.FormatInt(message.Seq, 10),
|
||||
Segments: req.Segments,
|
||||
SenderID: client.UserID,
|
||||
ID: message.ID,
|
||||
Time: message.CreatedAt.UnixMilli(),
|
||||
Type: "message",
|
||||
DetailType: detailType,
|
||||
ConversationID: req.ConversationID,
|
||||
Seq: strconv.FormatInt(message.Seq, 10),
|
||||
Segments: req.Segments,
|
||||
SenderID: client.UserID,
|
||||
}
|
||||
|
||||
msg := ws.ResponseMessage{
|
||||
@@ -474,7 +476,7 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
||||
zap.String("callee_id", req.CalleeID),
|
||||
zap.Error(err),
|
||||
)
|
||||
if errors.Is(err, service.ErrCallInProgress) {
|
||||
if errors.Is(err, apperrors.ErrCallInProgress) {
|
||||
h.wsHub.SendError(client, "call_in_progress", err.Error())
|
||||
return
|
||||
}
|
||||
@@ -514,7 +516,7 @@ func (h *WSHandler) handleCallAnswer(ctx context.Context, client *ws.Client, pay
|
||||
call, err := h.callService.Accept(ctx, req.CallID, client.UserID)
|
||||
if err != nil {
|
||||
// === 区分已接听错误 ===
|
||||
if errors.Is(err, service.ErrCallAlreadyAnswered) {
|
||||
if errors.Is(err, apperrors.ErrCallAlreadyAnswered) {
|
||||
h.wsHub.SendError(client, "call_already_answered", "通话已被其他设备接听")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user