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
[토닉] 1단계: 엔티티 매핑 #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
토닉, JPA 1단계 미션 잘 진행해주셨습니다. 👍
2단계를 빠르게 해보실 수 있도록 1단계 PR은 머지하도록 하겠습니다.
2단계 진행하시면서 아직 작성하지 않은 학습 테스트 추가와 함께, 1단계에서 남긴 코멘트도 참고해주세요.
2단계 미션에서 뵙겠습니다. 😀
private Long writerId; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime createdAt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여러 엔티티에 동일하게 추가되는 필드가 있는데, MappedSuperclass
또는 Embeddable
을 학습해보시면 중복 코드 제거가 가능하겠네요.
둘 중 무엇을 사용하면 좋을지, 각각 어떤 장단점이 있는지 고민해서 적용해보시면 좋겠습니다.
private Long questionId; | ||
private LocalDateTime updatedAt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성, 수정 시각을 자동으로 관리하기 위해 Auditing 기능을 학습해서 적용해보시면 좋겠습니다.
public class User { | ||
public static final GuestUser GUEST_USER = new GuestUser(); | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아래 제약 조건 추가를 위해서는 어떤 설정을 해줄 수 있을까요?
alter table user
add constraint UK_a3imlf41l37utmxiquukk8ajc unique (user_id)
Answer expected = new Answer(LocalDateTime.now(), false, 1L, LocalDateTime.now(), | ||
1L, "contents"); | ||
Answer actual = answerRepository.save(expected); | ||
assertThat(actual).isEqualTo(expected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actual
과 expected
가 동일하다는 테스트로 1. 테이블에 저장되었다는 것, 2. id 로 조회가 가능하다는 것에 대한 검증이 될 수 있을까요?
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
@DataJpaTest | ||
public class AnswerRepositoryTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnswerRepository
, QuestionRepository
, DeleteHistoryRepository
에 있는 여러 메소드에 대해 학습 테스트를 조금 더 작성해보시면 학습하는데 도움이 될 것 같아요 :)
요구 사항