Skip to content

Commit

Permalink
[~] #65 TemplateController 메소드 반환 타입 Response로 통일하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
woody35545 committed Oct 12, 2023
1 parent a5e3e63 commit c3625d9
Showing 1 changed file with 42 additions and 58 deletions.
100 changes: 42 additions & 58 deletions src/main/java/com/kns/tenquest/controller/TemplateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,82 +30,64 @@ public class TemplateController {

@ResponseBody
@GetMapping("/templates")
public Response_Deprecated<TemplateDto> apiGetAllTemplates(){
ResponseStatus responseStatus = ResponseStatus.OK;
DtoList<TemplateDto> templateDtoList = templateService.getAllTemplates();
//return new ResponseDto<TemplateDto>(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<DtoList<TemplateDto>> apiGetAllMemberTemplates(@PathVariable("memberId")String memberId){
ResponseStatus responseStatus = ResponseStatus.OK;
DtoList<TemplateDto> allMemberTemplates = templateService.getAllTemplatesByMember(memberId);
return new ResponseDto<DtoList<TemplateDto>>(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<TemplateDocDto> apiGetAllTemplateDocs(){
ResponseStatus responseStatus = ResponseStatus.OK;
DtoList<TemplateDocDto> templateDocDtoList = templateDocService.getAllTemplateDocs();
//return new ResponseDto<TemplateDto>(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<TemplateWrapper> apiGetTemplate(@RequestParam("value") String templateId){
TemplateWrapper templateWrapper = templateService.getTemplate(templateId);
ResponseStatus responseStatus = ResponseStatus.OK;
if(templateWrapper == null){
responseStatus = ResponseStatus.NOT_FOUND;
}
return new ResponseDto<TemplateWrapper>(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<TemplateWrapper> 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<TemplateWrapper>(responseStatus,createdTemplate).toResponse();
}
catch(NoSuchElementException e){
ResponseStatus responseStatus = ResponseStatus.NOT_FOUND;
return new ResponseDto<TemplateWrapper>(responseStatus,null).toResponse();
}
catch (RuntimeException e){
ResponseStatus responseStatus = ResponseStatus.CREATE_FAIL;
return new ResponseDto<TemplateWrapper>(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<TemplateDto> 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<TemplateDto>(responseStatus,updatedTemplate).toResponse();
} //template Update API
@DeleteMapping("/templates/{memberId}/template-id")
public Response_Deprecated<TemplateDto> 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<TemplateDto>(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());
}
}

0 comments on commit c3625d9

Please sign in to comment.