Commit 98376bcf authored by ligaowei's avatar ligaowei

修复工具列表为空的问题,修改工具API返回所有工具而非仅用户工具

parent 2e585055
...@@ -129,7 +129,7 @@ public class ToolController { ...@@ -129,7 +129,7 @@ public class ToolController {
* 获取工具列表 * 获取工具列表
*/ */
@GetMapping @GetMapping
@Operation(summary = "获取工具列表", description = "获取当前用户的所有工具") @Operation(summary = "获取工具列表", description = "获取所有可用工具")
public ApiResponse<List<Tool>> getTools() { public ApiResponse<List<Tool>> getTools() {
try { try {
String userId = getCurrentUserId(); String userId = getCurrentUserId();
...@@ -137,7 +137,7 @@ public class ToolController { ...@@ -137,7 +137,7 @@ public class ToolController {
return ApiResponse.error(4001, "用户未认证"); return ApiResponse.error(4001, "用户未认证");
} }
List<Tool> tools = toolService.getUserTools(userId); List<Tool> tools = toolService.getAllTools();
return ApiResponse.success(tools, "获取工具列表成功"); return ApiResponse.success(tools, "获取工具列表成功");
} catch (Exception e) { } catch (Exception e) {
log.error("获取工具列表失败", e); log.error("获取工具列表失败", e);
......
...@@ -22,6 +22,13 @@ public interface ToolRepository extends BaseMapper<Tool> { ...@@ -22,6 +22,13 @@ public interface ToolRepository extends BaseMapper<Tool> {
@Select("SELECT * FROM tool WHERE owner = #{owner} AND deleted = 0 ORDER BY created_at DESC") @Select("SELECT * FROM tool WHERE owner = #{owner} AND deleted = 0 ORDER BY created_at DESC")
List<Tool> findByOwner(String owner); List<Tool> findByOwner(String owner);
/**
* 获取所有未删除的工具列表
* @return 工具列表
*/
@Select("SELECT * FROM tool WHERE deleted = 0 ORDER BY created_at DESC")
List<Tool> findAllActive();
/** /**
* 根据所有者和状态获取工具列表 * 根据所有者和状态获取工具列表
* @param owner 所有者ID * @param owner 所有者ID
......
...@@ -140,7 +140,20 @@ public class ToolService extends ServiceImpl<ToolRepository, Tool> { ...@@ -140,7 +140,20 @@ public class ToolService extends ServiceImpl<ToolRepository, Tool> {
* @return 工具列表 * @return 工具列表
*/ */
public List<Tool> getUserTools(String userId) { public List<Tool> getUserTools(String userId) {
return toolRepository.findByOwner(userId); List<Tool> userTools = toolRepository.findByOwner(userId);
// 如果用户没有工具,返回所有公共工具
if (userTools.isEmpty()) {
return toolRepository.findAllActive();
}
return userTools;
}
/**
* 获取所有工具
* @return 工具列表
*/
public List<Tool> getAllTools() {
return toolRepository.findAllActive();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment