package com.custom.webui.controller; import com.custom.webui.dto.resp.CategoryDTO; import com.custom.webui.dto.resp.Result; import com.custom.webui.security.CurrentUser; import com.custom.webui.service.CategoryService; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * 知识库分类接口。 * *
分类的作用是让「绑定知识库」从逐个勾选变成整类绑定。 * *
权限模型与文件一致:可见 = 自己的 + 全局的;可管理 = 自己的,或本人是管理员。
*/
@Slf4j
@RestController
@RequestMapping("/api/categories")
@RequiredArgsConstructor
public class CategoryController {
private final CategoryService categoryService;
/**
* 可见分类列表,带文档数、已入库数与集合名。
*
* @param chatId 传入时会标记每个分类是否已绑定到该会话,前端可显示选中态
*/
@GetMapping
public Result 分类内的**文档不会被删除**,只会变成「未分类」。
*/
@DeleteMapping("/{id}")
public Result> list(@RequestParam(value = "chatId", required = false) Long chatId) {
return Result.success(categoryService.listVisible(CurrentUser.requireUserId(), chatId));
}
/** 创建分类;管理员可传 global=true 创建全员可见的分类 */
@PostMapping
public Result