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

[토닉] 1단계: 엔티티 매핑 #3

Merged
merged 3 commits into from Jul 11, 2022

Conversation

tonic523
Copy link

@tonic523 tonic523 commented Jul 7, 2022

요구 사항

  • QnA 서비스를 만들어가면서 JPA로 실제 도메인 모델을 어떻게 구성하고 객체와 테이블을 어떻게 매핑해야 하는지 알아본다.
  • 아래의 DDL(Data Definition Language)을 보고 유추하여 엔티티 클래스와 리포지토리 클래스를 작성해 본다.
  • @DataJpaTest를 사용하여 학습 테스트를 해 본다.

Copy link

@seokhongkim seokhongkim left a 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;

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;

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;

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);

Choose a reason for hiding this comment

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

actualexpected 가 동일하다는 테스트로 1. 테이블에 저장되었다는 것, 2. id 로 조회가 가능하다는 것에 대한 검증이 될 수 있을까요?

import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DataJpaTest
public class AnswerRepositoryTest {

Choose a reason for hiding this comment

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

AnswerRepository, QuestionRepository, DeleteHistoryRepository 에 있는 여러 메소드에 대해 학습 테스트를 조금 더 작성해보시면 학습하는데 도움이 될 것 같아요 :)

@seokhongkim seokhongkim merged commit 19a33fa into woowacourse:tonic523 Jul 11, 2022
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.

None yet

2 participants