feat(chat): add batch management for conversations

This commit is contained in:
AndyYang
2026-02-25 11:37:36 +08:00
committed by lyingbug
parent b536e86cd0
commit 172bf797ee
13 changed files with 610 additions and 1 deletions
+53
View File
@@ -303,3 +303,56 @@ func (h *Handler) DeleteSession(c *gin.Context) {
"message": "Session deleted successfully",
})
}
// batchDeleteRequest represents the request body for batch deleting sessions
type batchDeleteRequest struct {
IDs []string `json:"ids" binding:"required,min=1"`
}
// BatchDeleteSessions godoc
// @Summary 批量删除会话
// @Description 根据ID列表批量删除对话会话
// @Tags 会话
// @Accept json
// @Produce json
// @Param request body batchDeleteRequest true "批量删除请求"
// @Success 200 {object} map[string]interface{} "删除结果"
// @Failure 400 {object} errors.AppError "请求参数错误"
// @Security Bearer
// @Security ApiKeyAuth
// @Router /sessions/batch [delete]
func (h *Handler) BatchDeleteSessions(c *gin.Context) {
ctx := c.Request.Context()
var req batchDeleteRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.Errorf(ctx, "Invalid batch delete request: %v", err)
c.Error(errors.NewBadRequestError("invalid request: ids are required"))
return
}
// Sanitize all IDs
sanitizedIDs := make([]string, 0, len(req.IDs))
for _, id := range req.IDs {
sanitized := secutils.SanitizeForLog(id)
if sanitized != "" {
sanitizedIDs = append(sanitizedIDs, sanitized)
}
}
if len(sanitizedIDs) == 0 {
c.Error(errors.NewBadRequestError("no valid session IDs provided"))
return
}
if err := h.sessionService.BatchDeleteSessions(ctx, sanitizedIDs); err != nil {
logger.ErrorWithFields(ctx, err, nil)
c.Error(errors.NewInternalServerError(err.Error()))
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "Sessions deleted successfully",
})
}