Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Service 추가 및 예외 처리 #25

Open
geesuee opened this issue Oct 12, 2021 · 0 comments
Open

[ENHANCEMENT] Service 추가 및 예외 처리 #25

geesuee opened this issue Oct 12, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@geesuee
Copy link
Contributor

geesuee commented Oct 12, 2021

💥 2021/10/13 AM 02:13 기준 Jee 브랜치에 push 된 것 pull하시면 안됩니다!!!!!!!!!!

개선 전 상황

Service 없이 Controller만 존재하여
요청/응답과 함께 Repository 접근도 Controller에서 이루어지는 상황이었습니다.
더불어 로직을 나누지 않고 진행하여 사이사이 예외 처리를 하는 구간도 없었습니다.


개선 내용

먼저 완성된 Teacher, Student, Course, Review 객체별 Service 클래스를 추가하였습니다.
image
이미지 출처 : Spring 서비스 구조

  • 위 이미지와 같은 구조로 동작할 수 있도록 기존 Controller - Repository 사이에 Service 를 추가하고,
  • Service 단에서 (필요한 경우) 예외처리를 할 수 있도록 Exception을 throw, Controller에서 try-catch로 예외를 처리하도록 수정하였습니다.

의문점 및 논의가 필요한 사항

현재 두 가지 버전의 수정본이 있습니다.

  1. 위 이미지처럼 ControllerService 사이의 데이터 전달도 ResponseDTO로 이루어지는 버전
  2. ControllerService 사이에 데이터 전달은 단일 parameter 값 혹은 Entity 객체로 이루어지는 버전

이렇게 써놓으니까 당연히 1번으로 해야하는 것 아닌가 싶은데
제가 기존에 만들어 놓은 ResponDTO는 아래와 같은 구조입니다.
image
이는 Controller에서 응답 결과를 전송할 때,
성공 여부와 함께 (검색의 경우) 검색한 객체를 반환하기 위해 설계된 구조입니다.


그런데 이 ResponseDTO를 Controller - Service 간에도 사용하게 되면

  • 두 계층 간 DTO로 데이터를 전달 받아 안정적이라는 장점은 있지만
  • 불필요한 boolean 값을 계속하여 양측으로 전달하게 된다는 단점이 있습니다.

    Controller의 최종 응답 결과 전송이라는 기존 설계 의도에 따르면,
    해당 boolean 값이 요청 성공, 실패에 따라 달라질 수 있지만
    Controller - Service 간의 데이터 전송의 관점에서 해당 boolean 값은 늘 true로 설정하여 전송하기 때문에,
    예외처리로 사용하는 것도 아니고..영 의미없는 데이터가 됩니다.


Spring Boot Controller / Service 간 어떤 방식으로 데이터를 주고 받는지 참고 자료 찾으시면 공유 부탁드립니당..😥

@geesuee geesuee added the enhancement New feature or request label Oct 12, 2021
@geesuee geesuee self-assigned this Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant