forked from github/cool-admin-java
feat: 行为管理改为注册模式 - handlers接口返回已注册handler列表
- AdminProductActionController: 新增 GET /handlers 返回后端已注册的ActionHandler列表 - ActionHandlerRegistry: 新增 getHandlers() 方法暴露所有handler - 行为管理只能注册后端已有handler的行为,不可随意创建
This commit is contained in:
@@ -33,4 +33,8 @@ public class ActionHandlerRegistry {
|
||||
public boolean hasHandler(String actionCode) {
|
||||
return handlerMap.containsKey(actionCode);
|
||||
}
|
||||
|
||||
public List<ActionHandler> getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -3,19 +3,38 @@ package com.cool.modules.product.controller.admin;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.cool.core.annotation.CoolRestController;
|
||||
import com.cool.core.base.BaseController;
|
||||
import com.cool.core.request.R;
|
||||
import com.cool.modules.product.action.ActionHandler;
|
||||
import com.cool.modules.product.action.ActionHandlerRegistry;
|
||||
import com.cool.modules.product.entity.ProductActionEntity;
|
||||
import com.cool.modules.product.service.ProductActionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "商品行为管理", description = "商品行为管理")
|
||||
@CoolRestController(api = {"add", "delete", "update", "page", "info"})
|
||||
public class AdminProductActionController extends BaseController<ProductActionService, ProductActionEntity> {
|
||||
|
||||
private final ActionHandlerRegistry actionHandlerRegistry;
|
||||
|
||||
@Override
|
||||
protected void init(HttpServletRequest request, JSONObject requestParams) {
|
||||
setPageOption(createOp());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取已注册的行为处理器列表")
|
||||
@GetMapping("/handlers")
|
||||
public R handlers() {
|
||||
List<Map<String, String>> handlers = actionHandlerRegistry.getHandlers().stream()
|
||||
.map(h -> Map.of("code", h.getCode(), "name", h.getCode()))
|
||||
.toList();
|
||||
return R.ok(handlers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user