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

[Refactor] Interceptor를 활용해 서버 응답 포멧 통일 #141

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

yangchef1
Copy link
Collaborator

@yangchef1 yangchef1 commented Nov 25, 2024

관련 이슈 번호

close #136

작업 내용

  • ResponseStatus, ResponseMessage 어노테이션 구현
  • ResponseInterceptor 구현 및 등록
  • 기존 BaseResponse 활용 부분 ResponseMessage 어노테이션으로 변경

고민과 학습내용

어노테이션

  • @ResponseStatus - 성공 했을 때 대부분 200인 경우가 많아 200을 디폴트로 설정했습니다.
    • 따라서, 어노테이션을 사용하지 않았을 경우 기본적으로 200이 반환됩니다.
  • @ResponseStatus - 마찬가지로 사용하지 않았을 경우 '요청이 성공적으로 처리되었습니다.' 라는 메시지가 반환됩니다.

사용 예시

@Get()
@ResponseStatus(200) // 따로 명시하지 않아도 기본적으로 200이 반환됩니다.
@ResponseMessage('태스크 목록이 정상적으로 조회되었습니다.')
async getAll(@AuthUser() user: Account, @Query('projectId') projectId: number) {
  return await this.taskService.getAll(user.id, projectId);
}

추가 변경 사항

  • HttpLoggingInterceptor의 위치를 common/interceptor/ 로 옮겼습니다. (Interceptor끼리 모아두기 위함)
  • 현재 dev에 존재하던 API들은 모두 BaseResponse 대신, 어노테이션을 사용하도록 변경해놨습니다.

스크린샷

변경 이후에도 이전과 동일한 포멧으로 응답하는 것을 확인했습니다.

image

@yangchef1 yangchef1 added Refactor 기능 추가, 오류 수정이 아닌 변경 BE 서버 작업 labels Nov 25, 2024
@yangchef1 yangchef1 self-assigned this Nov 25, 2024
Copy link
Collaborator

@PMtHk PMtHk left a comment

Choose a reason for hiding this comment

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

확실히 데코레이터 패턴을 적용하니, 간결해지고 가독성이 좋아진 것 같아요!

}

@Post()
@ResponseMessage('프로젝트 생성이 성공했습니다.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

🟡
생성은 201 Created 가 더 적절할 것 같습니다!

@yangchef1 yangchef1 merged commit 8fae8f2 into dev Nov 25, 2024
1 check passed
@yangchef1 yangchef1 deleted the refactor/#136 branch December 3, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 서버 작업 Refactor 기능 추가, 오류 수정이 아닌 변경
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interceptor를 활용해 서버 응답 포멧 통일
3 participants