feat: 完善Swagger API文档生成功能
This commit is contained in:
@@ -22,7 +22,18 @@ func NewChunkHandler(service interfaces.ChunkService) *ChunkHandler {
|
||||
return &ChunkHandler{service: service}
|
||||
}
|
||||
|
||||
// GetChunkByIDOnly gets a chunk by its ID only (without requiring knowledge_id)
|
||||
// GetChunkByIDOnly godoc
|
||||
// @Summary 通过ID获取分块
|
||||
// @Description 仅通过分块ID获取分块详情(不需要knowledge_id)
|
||||
// @Tags 分块管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "分块ID"
|
||||
// @Success 200 {object} map[string]interface{} "分块详情"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 404 {object} errors.AppError "分块不存在"
|
||||
// @Security Bearer
|
||||
// @Router /chunks/by-id/{id} [get]
|
||||
func (h *ChunkHandler) GetChunkByIDOnly(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start retrieving chunk by ID only")
|
||||
@@ -79,7 +90,19 @@ func (h *ChunkHandler) GetChunkByIDOnly(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// ListKnowledgeChunks lists all chunks for a given knowledge ID
|
||||
// ListKnowledgeChunks godoc
|
||||
// @Summary 获取知识分块列表
|
||||
// @Description 获取指定知识下的所有分块列表,支持分页
|
||||
// @Tags 分块管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param knowledge_id path string true "知识ID"
|
||||
// @Param page query int false "页码" default(1)
|
||||
// @Param page_size query int false "每页数量" default(10)
|
||||
// @Success 200 {object} map[string]interface{} "分块列表"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
// @Router /chunks/{knowledge_id} [get]
|
||||
func (h *ChunkHandler) ListKnowledgeChunks(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start retrieving knowledge chunks list")
|
||||
@@ -200,7 +223,20 @@ func (h *ChunkHandler) validateAndGetChunk(c *gin.Context) (*types.Chunk, string
|
||||
return chunk, knowledgeID, nil
|
||||
}
|
||||
|
||||
// UpdateChunk updates a chunk's properties
|
||||
// UpdateChunk godoc
|
||||
// @Summary 更新分块
|
||||
// @Description 更新指定分块的内容和属性
|
||||
// @Tags 分块管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param knowledge_id path string true "知识ID"
|
||||
// @Param id path string true "分块ID"
|
||||
// @Param request body UpdateChunkRequest true "更新请求"
|
||||
// @Success 200 {object} map[string]interface{} "更新后的分块"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 404 {object} errors.AppError "分块不存在"
|
||||
// @Security Bearer
|
||||
// @Router /chunks/{knowledge_id}/{id} [put]
|
||||
func (h *ChunkHandler) UpdateChunk(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start updating knowledge chunk")
|
||||
@@ -239,7 +275,19 @@ func (h *ChunkHandler) UpdateChunk(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteChunk deletes a specific chunk
|
||||
// DeleteChunk godoc
|
||||
// @Summary 删除分块
|
||||
// @Description 删除指定的分块
|
||||
// @Tags 分块管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param knowledge_id path string true "知识ID"
|
||||
// @Param id path string true "分块ID"
|
||||
// @Success 200 {object} map[string]interface{} "删除成功"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 404 {object} errors.AppError "分块不存在"
|
||||
// @Security Bearer
|
||||
// @Router /chunks/{knowledge_id}/{id} [delete]
|
||||
func (h *ChunkHandler) DeleteChunk(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start deleting knowledge chunk")
|
||||
@@ -263,7 +311,17 @@ func (h *ChunkHandler) DeleteChunk(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteChunksByKnowledgeID deletes all chunks for a given knowledge ID
|
||||
// DeleteChunksByKnowledgeID godoc
|
||||
// @Summary 删除知识下所有分块
|
||||
// @Description 删除指定知识下的所有分块
|
||||
// @Tags 分块管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param knowledge_id path string true "知识ID"
|
||||
// @Success 200 {object} map[string]interface{} "删除成功"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
// @Router /chunks/{knowledge_id} [delete]
|
||||
func (h *ChunkHandler) DeleteChunksByKnowledgeID(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start deleting all chunks under knowledge")
|
||||
@@ -289,7 +347,19 @@ func (h *ChunkHandler) DeleteChunksByKnowledgeID(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteGeneratedQuestion deletes a generated question by its ID
|
||||
// DeleteGeneratedQuestion godoc
|
||||
// @Summary 删除生成的问题
|
||||
// @Description 删除分块中生成的问题
|
||||
// @Tags 分块管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "分块ID"
|
||||
// @Param request body object{question_id=string} true "问题ID"
|
||||
// @Success 200 {object} map[string]interface{} "删除成功"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 404 {object} errors.AppError "分块不存在"
|
||||
// @Security Bearer
|
||||
// @Router /chunks/by-id/{id}/questions [delete]
|
||||
func (h *ChunkHandler) DeleteGeneratedQuestion(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start deleting generated question from chunk")
|
||||
|
||||
Reference in New Issue
Block a user