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

[feat] 컨트롤러 API 공통 응답 처리 #50

Merged
merged 10 commits into from
Aug 14, 2024

Conversation

june-777
Copy link
Member

💡 다음 이슈를 해결했어요.

Issue Link - #32

APIResponseAdvice 에서 컨트롤러의 responseDTO 를 APIResponse 로 응답하도록 공통 로직을 처리

  • supports 메서드에서 해당 어드바이스가 처리해도 되는지 확인

    • api 이기 때문에, MappingJackson2HttpMessageConverter 컨버터가 아니면 무시
    • ResponseEntity 인 경우 무시
    • ProblemDetail 인 경우 무시
  • beforeBodyWrite 에서 공통 로직을 수행

    • @httpstatus 로 상태코드를 명시했다면, 해당 상태코드를 가져옴
    • response 에 상태코드를 명시했다면, 해당 상태코드를 가져옴
    • API 공통 응답 명세인 APIResponse 객체를 반환

🔔 notice:

  • APIResponse의 생성자 접근제어자를 public으로 변경했습니다.
  • APIResponseUtils의 경우 현재 사용되지 않는 상황입니다. 혹시 몰라서 코드는 남겨두었습니다.

💡 이슈를 처리하면서 추가된 코드가 있어요.

기존 API 컨트롤러의 반환 타입 변경 및 @httpstatus 명시

[refactor] 구매자 회원가입 컨트롤러 반환타입 변경
[refactor] 계좌 충전 컨트롤러 반환타입 변경
[refactor] 점주 회원가입 컨트롤러 반환타입 변경


✅ 셀프 체크리스트

  • 내 코드를 스스로 검토했습니다.
  • 필요한 테스트를 추가했습니다.
  • 모든 테스트를 통과합니다.
  • 브랜치 전략에 맞는 브랜치에 PR을 올리고 있습니다.
  • 커밋 메세지를 컨벤션에 맞추었습니다.
  • wiki를 수정했습니다.

supports 메서드가 true 일때만, 해당 Advice가 동작
1. 컨버터 타입이 MappingJackson2HttpMessageConverter 이
2. 파라미터타입이 ResponseEntity가 아니고
3. 파라미터타입이 ProblemDetail가 아닐때
- HttpStatus를 가져오는 기능
- body 가 null이면 No content 를 body로 갖는 APIResponse 응답
- body 가 이미 APIResponse이면 바로 응답
- HttpStatus와 body로 APIResponse 객체를 응답
- APIResponseAdvice 가 APIResponse 객체를 생성해서 반환해야 함
- 컨트롤러는 responseDTO를 반환
- 응답 공통 처리는 Advice에서 수행
- @ResponseStatus 로 상태 코드 명시
- 컨트롤러는 responseDTO를 반환
- 응답 공통 처리는 Advice에서 수행
- @ResponseStatus 로 상태 코드 명시
- 컨트롤러는 responseDTO를 반환
- 응답 공통 처리는 Advice에서 수행
- @ResponseStatus 로 상태 코드 명시
@june-777 june-777 added the ✨ Feature 기능 개발 label Aug 14, 2024
@june-777 june-777 self-assigned this Aug 14, 2024
@june-777 june-777 added this to the 프로토타입 만들기 milestone Aug 14, 2024
@june-777 june-777 added the ⚙ Setting 개발 환경 세팅 label Aug 14, 2024
Copy link
Member

@Dr-KoKo Dr-KoKo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APIUtils에 @Deprecated 붙이면 좋겠습니다!

@june-777 june-777 changed the title [공통] 컨트롤러 API 공통 응답 처리 [feat] 컨트롤러 API 공통 응답 처리 Aug 14, 2024
@june-777
Copy link
Member Author

APIUtils에 @Deprecated 붙이면 좋겠습니다!

8540ad5 반영 완료했습니다!

Copy link
Member

@kimhyun5u kimhyun5u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Copy link
Member

@Dr-KoKo Dr-KoKo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다!

@june-777 june-777 merged commit 8fbc5af into main Aug 14, 2024
1 check passed
@june-777 june-777 deleted the feature/32_june-777_컨트롤러API공통응답 branch August 14, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 개발 ⚙ Setting 개발 환경 세팅
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[공통] 컨트롤러 반환 타입 ResponseDTO, ResponseBodyAdvice에서 공통 처리
3 participants