修复了一些逻辑漏洞

This commit is contained in:
2025-12-05 16:21:43 +08:00
parent 3dfc468f50
commit d3fc16b546
6 changed files with 220 additions and 18 deletions

View File

@@ -9,6 +9,7 @@ import (
"xk-websocket-v2/internal/utils"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
/**
@@ -119,4 +120,30 @@ func DeleteConversationHandler(c *gin.Context) {
utils.Success(c, "删除成功")
}
/**
* GetConversationByRoomHandler
* 功能:根据 room_id 获取或创建会话
* 路径:GET /api/conversations/by-room/:room_id
*/
func GetConversationByRoomHandler(c *gin.Context) {
userID, _ := c.Get("user_id")
roomID := c.Param("room_id")
if roomID == "" {
utils.BadRequest(c, "room_id 不能为空")
return
}
conv, err := service.ConversationSvc.GetOrCreateConversationByRoom(userID.(string), roomID)
if err != nil {
if err == gorm.ErrRecordNotFound {
utils.NotFound(c, "房间不存在或无权访问")
} else {
utils.InternalError(c, "查询失败")
}
return
}
utils.SuccessWithData(c, conv, "获取成功")
}