荆州公司做网站,最近新闻摘抄,深圳市建设,安徽安庆房价一、上线接口#xff08;仅管理员#xff09;
1. 校验请求参数
2. 判断#xff08;测试#xff09;接口是否可以调用
引入调用接口的客户端#xff08;自己写的 SDK#xff09;注入客户端实例调用接口
3. 修改数据库中接口的状态 /*** 上线#xff08;发布#xff…一、上线接口仅管理员
1. 校验请求参数
2. 判断测试接口是否可以调用
引入调用接口的客户端自己写的 SDK注入客户端实例调用接口
3. 修改数据库中接口的状态 /*** 上线发布接口** param idRequest* param request* return*/PostMapping(/online)AuthCheck(mustRole admin)public BaseResponseBoolean onlineInterfaceInfo(RequestBody IdRequest idRequest,HttpServletRequest request) {if (idRequest null || idRequest.getId() 0) {throw new BusinessException(ErrorCode.PARAMS_ERROR);}// 1. 校验接口是否存在Long id idRequest.getId();InterfaceInfo oldInterfaceInfo interfaceInfoService.getById(id);if (oldInterfaceInfo null) {throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);}// 2. 校验接口是否可以调用com.ghost.leapiclientsdk.model.User user new com.ghost.leapiclientsdk.model.User();user.setUsername(testInterfaceInfo);String nameByJSON leAPIClient.getNameByJSON(user);if (StringUtils.isBlank(nameByJSON)) {throw new BusinessException(ErrorCode.SYSTEM_ERROR, 接口调用失败);}// 3. 修改数据库中接口的状态InterfaceInfo interfaceInfo new InterfaceInfo();interfaceInfo.setId(id);interfaceInfo.setStatus(InterfaceInfoStatusEnum.ONLINE.getValue());boolean result interfaceInfoService.updateById(interfaceInfo);return ResultUtils.success(result);}4. 测试上线接口功能
使用 Knife4j 接口文档进行测试 查看数据库中接口状态是否修改成功 二、下线接口仅管理员
1. 校验请求参数
2. 校验接口是否已经发布上线只有已经上线的接口才能下线
3. 修改数据库中接口的状态 /*** 下线关闭接口** param idRequest* param request* return*/PostMapping(/offline)public BaseResponseBoolean offlineInterfaceInfo(RequestBody IdRequest idRequest, HttpServletRequest request) {if (idRequest null || idRequest.getId() 0) {throw new BusinessException(ErrorCode.PARAMS_ERROR);}// 1. 校验接口是否存在Long id idRequest.getId();InterfaceInfo oldInterfaceInfo interfaceInfoService.getById(id);if (oldInterfaceInfo null) {throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);}// 2. 只有已经上线的接口才能下线if (oldInterfaceInfo.getStatus() ! InterfaceInfoStatusEnum.ONLINE.getValue()) {throw new BusinessException(ErrorCode.PARAMS_ERROR, 该接口尚未上线);}// 3. 修改数据库中接口的状态InterfaceInfo interfaceInfo new InterfaceInfo();interfaceInfo.setId(id);interfaceInfo.setStatus(InterfaceInfoStatusEnum.OFFLINE.getValue());boolean result interfaceInfoService.updateById(interfaceInfo);return ResultUtils.success(result);}
4. 测试上线接口功能
使用 Knife4j 接口文档进行测试 查看数据库中接口状态是否修改成功