fix: 完善查询当前用户下所有的分类

This commit is contained in:
Bunny 2024-11-16 22:57:29 +08:00
parent 0ae6a9d9bd
commit 889c774520
3 changed files with 16 additions and 10 deletions

View File

@ -39,6 +39,13 @@ public class CategoryController {
@Autowired @Autowired
private CategoryService categoryService; private CategoryService categoryService;
@Operation(summary = "查询当前用户下所有的分类", description = "查询当前用户下所有的分类")
@GetMapping("noManage/getCategoryUserAllList")
public Mono<Result<List<CategoryUserVo>>> getCategoryUserAllList(@RequestParam(required = false) Long userId) {
List<CategoryUserVo> voList = categoryService.getCategoryUserAllList(userId);
return Mono.just(Result.success(voList));
}
@Operation(summary = "分页查询分类信息", description = "分页查询分类信息") @Operation(summary = "分页查询分类信息", description = "分页查询分类信息")
@GetMapping("getCategoryList/{page}/{limit}") @GetMapping("getCategoryList/{page}/{limit}")
public Mono<Result<PageResult<CategoryVo>>> getCategoryList( public Mono<Result<PageResult<CategoryVo>>> getCategoryList(
@ -65,13 +72,6 @@ public class CategoryController {
return Mono.just(Result.success(pageResult)); return Mono.just(Result.success(pageResult));
} }
@Operation(summary = "查询当前用户下所有的分类", description = "查询当前用户下所有的分类")
@GetMapping("noManage/getCategoryUserAllList")
public Mono<Result<List<CategoryUserVo>>> getCategoryUserAllList() {
List<CategoryUserVo> voList = categoryService.getCategoryUserAllList();
return Mono.just(Result.success(voList));
}
@Operation(summary = "添加分类信息", description = "添加分类信息") @Operation(summary = "添加分类信息", description = "添加分类信息")
@PostMapping("addCategory") @PostMapping("addCategory")
public Mono<Result<String>> addCategory(@Valid @RequestBody CategoryAddDto dto) { public Mono<Result<String>> addCategory(@Valid @RequestBody CategoryAddDto dto) {

View File

@ -44,7 +44,7 @@ public interface CategoryService extends IService<Category> {
* *
* @return 当前用户分类返回列表 * @return 当前用户分类返回列表
*/ */
List<CategoryUserVo> getCategoryUserAllList(); List<CategoryUserVo> getCategoryUserAllList(Long userId);
/** /**
* * 添加分类信息 * * 添加分类信息

View File

@ -90,9 +90,15 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
* @return 当前用户分类返回列表 * @return 当前用户分类返回列表
*/ */
@Override @Override
public List<CategoryUserVo> getCategoryUserAllList() { public List<CategoryUserVo> getCategoryUserAllList(Long userId) {
// 判断用户ID是否为空如果为空设置为当前的用户的ID
if (userId == null) {
userId = BaseContext.getUserId();
}
// 根据用户id返回父级列表
LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Category::getUserId, BaseContext.getUserId()) wrapper.eq(Category::getUserId, userId)
.or() .or()
.eq(Category::getIsBuiltin, true); .eq(Category::getIsBuiltin, true);
return list(wrapper) return list(wrapper)