From c3625d98da9ed97e5fce6c5f248d736c17d1a2e3 Mon Sep 17 00:00:00 2001 From: woody35545 Date: Thu, 12 Oct 2023 19:46:39 +0900 Subject: [PATCH] =?UTF-8?q?[~]=20#65=20TemplateController=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EB=B0=98=ED=99=98=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?Response=EB=A1=9C=20=ED=86=B5=EC=9D=BC=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TemplateController.java | 100 ++++++++---------- 1 file changed, 42 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/kns/tenquest/controller/TemplateController.java b/src/main/java/com/kns/tenquest/controller/TemplateController.java index 55e58a8..5c06bcc 100644 --- a/src/main/java/com/kns/tenquest/controller/TemplateController.java +++ b/src/main/java/com/kns/tenquest/controller/TemplateController.java @@ -5,8 +5,10 @@ import com.kns.tenquest.ENV; import com.kns.tenquest.RequestWrapper.TemplateWrapper; import com.kns.tenquest.dto.ResponseDto; +import com.kns.tenquest.dto.ServiceResult; import com.kns.tenquest.dto.TemplateDocDto; import com.kns.tenquest.dto.TemplateDto; +import com.kns.tenquest.response.Response; import com.kns.tenquest.response.Response_Deprecated; import com.kns.tenquest.response.ResponseStatus; import com.kns.tenquest.service.TemplateDocService; @@ -28,82 +30,64 @@ public class TemplateController { @ResponseBody @GetMapping("/templates") - public Response_Deprecated apiGetAllTemplates(){ - ResponseStatus responseStatus = ResponseStatus.OK; - DtoList templateDtoList = templateService.getAllTemplates(); - //return new ResponseDto(responseStatus,templateDtoList).toResponseJson(); - return templateDtoList.toResponse(responseStatus); - } //template Read API + public Response apiGetAllTemplates() { + ServiceResult sr = templateService.getAllTemplates(); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()); + new Response().Ok().data(sr.getData()); + } @ResponseBody @GetMapping("/templates/{memberId}") - public Response_Deprecated> apiGetAllMemberTemplates(@PathVariable("memberId")String memberId){ - ResponseStatus responseStatus = ResponseStatus.OK; - DtoList allMemberTemplates = templateService.getAllTemplatesByMember(memberId); - return new ResponseDto>(responseStatus,allMemberTemplates).toResponse(); + public Response apiGetAllMemberTemplates(@PathVariable("memberId")String memberId){ + ServiceResult sr = templateService.getAllTemplatesByMember(memberId); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()) : + new Response().Ok().data(sr.getData()); } @ResponseBody @GetMapping("/template-docs") - public Response_Deprecated apiGetAllTemplateDocs(){ - ResponseStatus responseStatus = ResponseStatus.OK; - DtoList templateDocDtoList = templateDocService.getAllTemplateDocs(); - //return new ResponseDto(responseStatus,templateDtoList).toResponseJson(); - return templateDocDtoList.toResponse(responseStatus); - } //template Read API + public Response apiGetAllTemplateDocs(){ + ServiceResult sr = templateDocService.getAllTemplateDocs(); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()) : + new Response().Ok().data(sr.getData()); + } @ResponseBody @GetMapping("templates/template-id") - public Response_Deprecated apiGetTemplate(@RequestParam("value") String templateId){ - TemplateWrapper templateWrapper = templateService.getTemplate(templateId); - ResponseStatus responseStatus = ResponseStatus.OK; - if(templateWrapper == null){ - responseStatus = ResponseStatus.NOT_FOUND; - } - return new ResponseDto(responseStatus,templateWrapper).toResponse(); + public Response apiGetTemplate(@RequestParam("value") String templateId){ + ServiceResult sr = templateService.getTemplate(templateId); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()) : + new Response().Ok().data(sr.getData()); } @ResponseBody @PostMapping("/templates/{memberId}") - public Response_Deprecated apiCreateTemplate(@RequestBody TemplateWrapper requestWrapper, @PathVariable("memberId")String memberId) { - try{ - TemplateWrapper createdTemplate = templateService.createTemplate(requestWrapper,memberId); - ResponseStatus responseStatus = ResponseStatus.CREATE_DONE; - if(createdTemplate == null){ - responseStatus = ResponseStatus.CREATE_FAIL; - } - return new ResponseDto(responseStatus,createdTemplate).toResponse(); - } - catch(NoSuchElementException e){ - ResponseStatus responseStatus = ResponseStatus.NOT_FOUND; - return new ResponseDto(responseStatus,null).toResponse(); - } - catch (RuntimeException e){ - ResponseStatus responseStatus = ResponseStatus.CREATE_FAIL; - return new ResponseDto(responseStatus,null).toResponse(); - } - } //template Create API + public Response apiCreateTemplate(@RequestBody TemplateWrapper requestWrapper, @PathVariable("memberId")String memberId) { + ServiceResult sr = templateService.createTemplate(requestWrapper,memberId); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()) : + new Response().Ok().data(sr.getData()); + } @PutMapping("/templates/{memberId}/template-id") - public Response_Deprecated apiTemplateUpdate(@PathVariable("memberId") String memberId, @RequestParam("value") String templateId, @RequestBody TemplateDto templateDto) { - TemplateDto updatedTemplate = templateService.templateUpdate(memberId,templateId, templateDto); - ResponseStatus responseStatus = ResponseStatus.OK; - if(updatedTemplate == null){ - responseStatus = ResponseStatus.NOT_FOUND; - } + public Response apiTemplateUpdate(@PathVariable("memberId") String memberId, @RequestParam("value") String templateId, @RequestBody TemplateDto templateDto) { + ServiceResult sr = templateService.templateUpdate(memberId,templateId, templateDto); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()) : + new Response().Ok().data(sr.getData()); + } - return new ResponseDto(responseStatus,updatedTemplate).toResponse(); - } //template Update API @DeleteMapping("/templates/{memberId}/template-id") - public Response_Deprecated apiTemplateDelete(@PathVariable("memberId") String memberId, @RequestParam("value") String templateId){ - TemplateDto deletedTemplate = templateService.templateDelete(memberId, templateId); - ResponseStatus responseStatus = ResponseStatus.OK; - if(deletedTemplate == null){ - responseStatus = ResponseStatus.NOT_FOUND; - } - - return new ResponseDto(responseStatus,deletedTemplate).toResponse(); - } //template Delete API + public Response apiTemplateDelete(@PathVariable("memberId") String memberId, @RequestParam("value") String templateId) { + ServiceResult sr = templateService.templateDelete(memberId, templateId); + return sr.isFailed() ? + new Response().BadRequest().message(sr.getMessage()) : + new Response().Ok().data(sr.getData()); + } }