Skip to content

Conversation

@Gongmeda
Copy link
Member

@Gongmeda Gongmeda commented Nov 21, 2023

구현 내용

  • Controller 보완
    • produce, consume 설정
    • 메소드에서 ReponseEntity 응답하도록 수정
    • API Version 처리
  • paging 처리
  • TaskRepository.findByUuidOrNull 로 메소드명 변경
  • Execption Handler 구현
  • db 기반 todo-list 구현 (Spring Data Jpa + H2 연동)
  • bulk-create api 만들기 (JdbcTemplate 사용)

비고

  • 제 Execption Handler 구현 방식에 대한 의견이 궁금합니다
  • TODO
    • request DTO validation 처리
    • bulk 연산 chunk 단위로 나눠 처리하기
    • H2 -> MySQL 연동
    • 단위 테스트 코드 작성

@Gongmeda Gongmeda self-assigned this Nov 21, 2023
Copy link
Member

@DongGeon0908 DongGeon0908 left a comment

Choose a reason for hiding this comment

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

runtime에서 발생하는 exception을 별도로 핸들링히는 건 어ㄸ애요?

import java.util.UUID

data class Task(
val uuid: UUID,
Copy link
Member

Choose a reason for hiding this comment

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

여기서 바로, UUID.generate 히는 방법도 있을 것 같아요


import org.slf4j.LoggerFactory

inline fun<reified T> T.logger() = LoggerFactory.getLogger(T::class.java)!! No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

mu.KotlinLogging.logger

요 라이브러리를 찾아보시고 적용하시면 될 것 같아요

}

@Transactional
override fun saveInBatch(tasks: List<Task>): Int {
Copy link
Member

Choose a reason for hiding this comment

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

실패하면 어떻게 될까요??
너무 많은 요창을 한번에 처리하면 부하가 발생할 것 같아요

fun findByUuid(uuid: UUID): TaskEntity?

@Query("select t from TaskEntity t order by t.createdAt asc")
fun findAllOrderByCreatedAtAsc(pageable: org.springframework.data.domain.Pageable): org.springframework.data.domain.Page<TaskEntity>
Copy link
Member

Choose a reason for hiding this comment

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

jpa에서 해당 쿼리는 자동 생성 가능할건데, 네이티브 쿼리를 쓰신 이유가 궁금해요

Copy link
Member Author

Choose a reason for hiding this comment

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

저도 자동 생성되는 걸로 알고 메소드명을 저렇게 지은건데 빈 생성 오류가 나더라구요... 네이밍 스키마 잘 지킨 것 같은데 왜 그러는지 모르겠습니다ㅠ

Copy link
Member

Choose a reason for hiding this comment

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

@Gongmeda
repository에 선언하지 말고, 자동 생성된 findAll(Pageable pageable) 쓰는 건 어때요?
sort 내용은 Pageable에 담을 수 있을 것 같아요.

}

@ExceptionHandler(Exception::class)
fun handleException(e: Exception): ResponseEntity<Any> {
Copy link
Member

Choose a reason for hiding this comment

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

모든 exception이 여기서 처리되는 걸까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

넵 맞습니다. 실제 서버를 배포한다면 예상치 못한 오류라 하더라도 사용자에게 전달되는 메시지를 제한할 필요가 있다고 생각해서, 이를 적용하기 편하게 핸들러는 하나로 처리해놨습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

위에서 말씀하신 "runtime에서 발생하는 exception을 별도로 핸들링"하는건 RuntimeException과 이를 상속받는 예외들에 대한 전용 핸들러를 만드는걸 제안하시는건가요? (@ExceptionHandler(RuntimeException::class))

Copy link
Member

Choose a reason for hiding this comment

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

넵넵 예를 들어

BusinessException : RuntimeException 요렇게 만들고,
앞으로 우리 비즈니스에서 발생하는 RuntimeException은 해당 BusinessException을 통해 핸들링하는거죵!

BusinessException을 핸들링하는 로직도 있고, Exception을 핸들링하는 로직도 있으면 좋을 것 같아요.
물론, Exception 핸들링도 우리가 정의한 포맷으로 response되도록요.

return ResponseEntity.status(errorCode.status).body(errorCode.message)
}

throw e
Copy link
Member

Choose a reason for hiding this comment

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

이러면 500에러가 발생하고, 에러 반환값도 달라질 것 같네요

Copy link
Member Author

Choose a reason for hiding this comment

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

반환값 통일은 아직 안했습니다ㅠ 추가하겠습니다

Copy link
Member

Choose a reason for hiding this comment

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

넹넹!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants