private App findAppById(Long appId) { Response<App> findResp = appService.findById(appId); if (!findResp.isSuccess()){ throw new RuntimeException("Failed to find app, id = " + appId); } App app = findResp.getData(); if (app == null){ throw new RuntimeException("The app isn't exist, id = " + appId); } return app; } }
/** * Paging the apps * @param pageNo the page no * @param pageSize the page size * @param appName the app full name * @return the app page data response */ @RequestMapping(method = RequestMethod.GET) public JsonResponse pagingApp( @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(value = "appName", defaultValue = "") String appName){ Response<Page<App>> pagingResp = appService.pagingApp(appName, pageNo, pageSize); if (!pagingResp.isSuccess()){ return JsonResponse.notOk(messages.get(pagingResp.getErr())); } return JsonResponse.ok(pagingResp.getData()); }
/** * Delete the app */ @RequestMapping(value = "/del", method = RequestMethod.POST) public JsonResponse delApp(@RequestBody AppDeleteDto appDeleteDto){ Response<Boolean> delResp = appService.delete(appDeleteDto.getAppName()); if (!delResp.isSuccess()){ Logs.error("failed to delete app({}), cause: {}", appDeleteDto.getAppName(), delResp.getErr()); } return JsonResponse.ok(delResp.getData()); } }
/** * Save the app */ @RequestMapping(method = RequestMethod.POST) public JsonResponse saveApp(@RequestBody AppSaveDto appSaveDto){ App app = new App(); app.setAppName(appSaveDto.getAppName()); app.setAppKey(appSaveDto.getAppKey()); app.setAppDesc(appSaveDto.getAppDesc()); Response<Long> saveResp = appService.save(app); if (!saveResp.isSuccess()){ Logs.error("failed to save app({}), cause: {}", app, saveResp.getErr()); return JsonResponse.notOk(saveResp.getErr()); } // inherit the app's jobs return JsonResponse.ok(saveResp.getData()); }