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

Step09 #44

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Step09 #44

wants to merge 4 commits into from

Conversation

ydj515
Copy link
Member

@ydj515 ydj515 commented Jan 16, 2025

커밋 링크

filter, exception handler의 경우 이전 pr에 이미 작성되어있어서 링크만 첨부합니다.

  1. 대기열 토큰 검증 필터 추가 : 링크
  2. exception handler 추가 : 링크
  3. API 요청/응답 로깅을 위한 interceptor 추가 : 06d2b6c
  4. 기본 로그 레벨 지정 : d2bf4ba
  5. API response 공통 응답처리 : d6c59b9

리뷰 포인트(질문)

  • api 응답을 공통화 하는 과정에서 ResponseBodyAdvice을 override해서 controller에서는 responseentity가 아닌 dto만을 리턴하게 코드를 수정하였습니다. 공통응답을 만들어 낼때 ResponseBodyAdvice 를 override해서 사용하는 것이 괜찮은 방식인지 궁금합니다.
override fun beforeBodyWrite(
    @Nullable body: Any?,
    returnType: MethodParameter,
    selectedContentType: MediaType,
    selectedConverterType: Class<out HttpMessageConverter<*>>,
    request: ServerHttpRequest,
    response: ServerHttpResponse,
): Any? {
    return when (body) {
        is ResponseEntity<*> -> body // ResponseEntity 는 그대로 반환
        else -> ApiResponse.success(body) // 그 외 응답을 SuccessResponse 로 변환
    }
}
  • as-is controller
fun chargeBalance(
    @RequestHeader(RESERVATION_QUEUE_TOKEN) token: String,
    @RequestBody balanceRequest: BalanceChargeRequest,
): ResponseEntity<SuccessResponse<ChargeBalanceResult>> {
    val criteria = ChargeBalanceCriteria(Money(balanceRequest.amount), token)
    val result = balanceUsecase.chargeBalance(criteria)
    return ApiResponse.success(result)
}
  • to-be controller
fun chargeBalance(
    @RequestHeader(RESERVATION_QUEUE_TOKEN) token: String,
    @RequestBody balanceRequest: BalanceChargeRequest,
): BalanceChargeResponse {
    val criteria = ChargeBalanceCriteria(Money(balanceRequest.amount), token)
    val result = balanceUsecase.chargeBalance(criteria)
    return result.toBalanceChargeResponse()
}

Keep

꾸준히 하는 노력

Problem

천천히 시간에 쫓기지 않고 하기

Try

최대한 이것저것 예외 케이스 생각해보기

@ydj515 ydj515 added the enhancement New feature or request label Jan 16, 2025
@ydj515 ydj515 self-assigned this Jan 16, 2025
@ydj515 ydj515 added this to the 3. 프로젝트 고도화 milestone Jan 16, 2025
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

Successfully merging this pull request may close these issues.

1 participant