From 16d38beea201f74786563524d12e342ed8ce34b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8B=89=E8=BF=AA=E7=BB=B4?= Date: Wed, 8 Sep 2021 14:55:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E5=BF=85=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java b/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java index cd3d312..b991ec5 100644 --- a/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java +++ b/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java @@ -36,17 +36,26 @@ public class NotificationController { * @param receiver * @return */ - @GetMapping(value = "/{type}") - public ResponseData index(@PathVariable(name = "type", required = true) String type, + @GetMapping(value = "/{platform}/{type}") + public ResponseData index(@PathVariable(name = "platform", required = true) String platform, + @PathVariable(name = "type", required = true) String type, @RequestParam(name = "receiver", required = true) Integer receiver, @RequestParam(name = "page", required = false, defaultValue = "1") Integer pageNum, @RequestParam(name = "size", required = false, defaultValue = "20") Integer pageSize) { + //验证 {platform} 参数合法性,以判断请求来源 + if (!platform.trim().toLowerCase().equals(PLATFORM_CODE_GITLINK)) { + logger.debug("------>输入参数 {platform} 的值 {" + platform + "} 无效"); + DataPacketUtil.jsonFailResult("参数 {platform} 非法"); + } + + //验证 {receiver} 参数合法性 if (receiver <= 0 || receiver >= Integer.MAX_VALUE) { logger.debug("------>输入参数 {receiver} 的值 {" + receiver + "} 超出约定范围"); DataPacketUtil.jsonFailResult("参数 {receiver} 非法"); } + //判断 {type} 参数合法性,正确的值只能是 list、count if (type.trim().toLowerCase().equals("list")) { //用户请求的是 list logger.debug("------>{type} 参数是 list"); @@ -54,7 +63,7 @@ public class NotificationController { //TODO: 获取约定的必要参数 //调用业务逻辑获取数据结果 - List foundList = notificationService.getUnreadSysNotificationsList(PLATFORM_CODE_GITLINK, receiver, pageSize); + List foundList = notificationService.getUnreadSysNotificationsList(platform, receiver, pageSize); //拼装约定的 json 格式并返回 return DataPacketUtil.jsonSuccessResult(foundList); @@ -65,7 +74,7 @@ public class NotificationController { //TODO: 获取必要的参数 //调用业务逻辑获取数据结果 - Integer foundCount = notificationService.getSysNotificationNumberByType(PLATFORM_CODE_GITLINK, receiver, 1); + Integer foundCount = notificationService.getSysNotificationNumberByType(platform, receiver, 1); //拼装约定的 json 格式并返回 return DataPacketUtil.jsonSuccessResult(foundCount); -- 2.34.1