部分联系人和会话接口
This commit is contained in:
122
internal/api/conversation_handler.go
Normal file
122
internal/api/conversation_handler.go
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* package api
|
||||
* 作用:会话列表(最近聊天)相关 API 处理器
|
||||
*/
|
||||
package api
|
||||
|
||||
import (
|
||||
"xk-websocket-v2/internal/service"
|
||||
"xk-websocket-v2/internal/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
/**
|
||||
* GetConversationListHandler
|
||||
* 功能:获取当前用户的会话列表
|
||||
* 路径:GET /api/conversations
|
||||
*/
|
||||
func GetConversationListHandler(c *gin.Context) {
|
||||
userID, _ := c.Get("user_id")
|
||||
|
||||
list, err := service.ConversationSvc.GetConversations(userID.(string))
|
||||
if err != nil {
|
||||
utils.InternalError(c, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
utils.SuccessWithData(c, list, "获取成功")
|
||||
}
|
||||
|
||||
/**
|
||||
* ResetConversationUnreadHandler
|
||||
* 功能:重置会话未读数
|
||||
* 路径:POST /api/conversations/reset-unread
|
||||
*/
|
||||
func ResetConversationUnreadHandler(c *gin.Context) {
|
||||
userID, _ := c.Get("user_id")
|
||||
|
||||
var req struct {
|
||||
TargetID string `json:"target_id" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
utils.BadRequest(c, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := service.ConversationSvc.ResetUnread(userID.(string), req.TargetID); err != nil {
|
||||
utils.InternalError(c, "操作失败")
|
||||
return
|
||||
}
|
||||
|
||||
utils.Success(c, "已重置未读")
|
||||
}
|
||||
|
||||
/**
|
||||
* UpdateConversationHandler
|
||||
* 功能:更新会话标记(置顶、免打扰、特别关心)
|
||||
* 路径:POST /api/conversations/update
|
||||
*/
|
||||
func UpdateConversationHandler(c *gin.Context) {
|
||||
userID, _ := c.Get("user_id")
|
||||
|
||||
var req struct {
|
||||
TargetID string `json:"target_id" binding:"required"`
|
||||
IsTop *bool `json:"is_top"`
|
||||
IsMuted *bool `json:"is_muted"`
|
||||
IsSpecialCare *bool `json:"is_special_care"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
utils.BadRequest(c, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
updates := make(map[string]interface{})
|
||||
if req.IsTop != nil {
|
||||
updates["is_top"] = *req.IsTop
|
||||
}
|
||||
if req.IsMuted != nil {
|
||||
updates["is_muted"] = *req.IsMuted
|
||||
}
|
||||
if req.IsSpecialCare != nil {
|
||||
updates["is_special_care"] = *req.IsSpecialCare
|
||||
}
|
||||
|
||||
if len(updates) == 0 {
|
||||
utils.BadRequest(c, "没有可更新的字段")
|
||||
return
|
||||
}
|
||||
|
||||
if err := service.ConversationSvc.UpdateConversationFlags(userID.(string), req.TargetID, updates); err != nil {
|
||||
utils.InternalError(c, "更新失败")
|
||||
return
|
||||
}
|
||||
|
||||
utils.Success(c, "更新成功")
|
||||
}
|
||||
|
||||
/**
|
||||
* DeleteConversationHandler
|
||||
* 功能:删除会话
|
||||
* 路径:POST /api/conversations/delete
|
||||
*/
|
||||
func DeleteConversationHandler(c *gin.Context) {
|
||||
userID, _ := c.Get("user_id")
|
||||
|
||||
var req struct {
|
||||
TargetID string `json:"target_id" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
utils.BadRequest(c, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := service.ConversationSvc.DeleteConversation(userID.(string), req.TargetID); err != nil {
|
||||
utils.InternalError(c, "删除失败")
|
||||
return
|
||||
}
|
||||
|
||||
utils.Success(c, "删除成功")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user