-
Notifications
You must be signed in to change notification settings - Fork 131
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단계 - 엔티티 매핑] 디투 미션 제출합니다 #61
Open
shb03323
wants to merge
31
commits into
woowacourse:shb03323
Choose a base branch
from
shb03323:step1
base: shb03323
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4cf81f7
feat: properties 설정
shb03323 75a7bad
feat: jpa config
shb03323 83ae245
feat: createdAt, updatedAt 객체 생성
shb03323 b120040
feat: 테이블 엔티티 생성
shb03323 dfdcc30
refactor: 레포지토리 패키지 분리
shb03323 22ae0f7
refactor: 설정파일을 yml로 변경
shb03323 becfbb7
test: User update 메서드 테스트 코드 작성
shb03323 e97691e
test: 질문과 답변에 대한 테스트 코드 작성
shb03323 6b9960a
refactor: 생성일자, 수정일자 entity 명 변경
shb03323 a5a37c3
refactor: equals and hashcode 재정의
shb03323 94b5d1d
refactor: 연관관계 매핑 수정
shb03323 e63ad95
refactor: application.properties 삭제
shb03323 e7b59be
test: 사용자 id 조회 테스트 작성
shb03323 c2322de
test: 삭제되지 않은 질문 조회 테스트 작성
shb03323 857df74
test: 삭제되지 않은 질문중에서 식별자로 조회 테스트 작성
shb03323 6aa5168
chore: 테스트 설정 파일에 sql 로깅 추가
shb03323 ea2793e
refactor: question 엔티티의 작성자를 변경하지 못하도록 설정
shb03323 112e461
refactor: 엔티티에 필요없는 세터 제거
shb03323 7f7ca56
test: repository fixture 파일 생성
shb03323 510c055
test: 삭제되지 않은 답변 중에서 질문을 식별자로 조회하는 테스트 작성
shb03323 a6f69f4
test: 질문 식별자로 삭제되지 않은 답변 조회 테스트 작성
shb03323 672844c
refactor: repository 테스트 패키지 구조 변경
shb03323 3ff066e
feat: Question equals & hashcode 재정의
shb03323 6a829f3
test: Question 테스트 변수명 수정
shb03323 fa203a4
test: Answer 엔티티 테스트 사용하지 않는 변수 제거
shb03323 099dda3
test: 답변의 식별자로 답변을 검색할 때, 삭제된 경우 검색 안되는 테스트 작성
shb03323 b5af277
test: 레포지터리 Fixture 작성
shb03323 19a9bea
test: Answer 레포지터리 테스트 Fixture 적용
shb03323 0b0de7d
refactor: 레포지토리 test 패키지 구조 변경
shb03323 9b8e2af
refactor: entity 외래키 제약 조건 이름 설정
shb03323 32ca40f
test: 모든 data jpa test를 RepositoryTestConfig 상속하도록 함
shb03323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package qna.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@EnableJpaAuditing | ||
public class JpaConfig { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,36 @@ | |
import qna.NotFoundException; | ||
import qna.UnAuthorizedException; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.ForeignKey; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.Lob; | ||
import javax.persistence.ManyToOne; | ||
import java.util.Objects; | ||
|
||
public class Answer { | ||
@Entity | ||
public class Answer extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private Long writerId; | ||
private Long questionId; | ||
@ManyToOne | ||
@JoinColumn(name = "writer_id", foreignKey = @ForeignKey(name = "fk_answer_writer")) | ||
private User writer; | ||
@ManyToOne | ||
@JoinColumn(name = "question_id", foreignKey = @ForeignKey(name = "fk_answer_to_question")) | ||
private Question question; | ||
@Lob | ||
private String contents; | ||
@Column | ||
private boolean deleted = false; | ||
|
||
protected Answer() {} | ||
|
||
public Answer(User writer, Question question, String contents) { | ||
this(null, writer, question, contents); | ||
} | ||
|
@@ -27,51 +48,35 @@ public Answer(Long id, User writer, Question question, String contents) { | |
throw new NotFoundException(); | ||
} | ||
|
||
this.writerId = writer.getId(); | ||
this.questionId = question.getId(); | ||
this.writer = writer; | ||
this.question = question; | ||
this.contents = contents; | ||
} | ||
|
||
public boolean isOwner(User writer) { | ||
return this.writerId.equals(writer.getId()); | ||
return this.writer.equals(writer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User객체의 equals 를 활용하셨군요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 꼼꼼하지 못했습니다. |
||
} | ||
|
||
public void toQuestion(Question question) { | ||
this.questionId = question.getId(); | ||
this.question = question; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getWriterId() { | ||
return writerId; | ||
} | ||
|
||
public void setWriterId(Long writerId) { | ||
this.writerId = writerId; | ||
} | ||
|
||
public Long getQuestionId() { | ||
return questionId; | ||
public User getWriter() { | ||
return writer; | ||
} | ||
|
||
public void setQuestionId(Long questionId) { | ||
this.questionId = questionId; | ||
public Question getQuestion() { | ||
return question; | ||
} | ||
|
||
public String getContents() { | ||
return contents; | ||
} | ||
|
||
public void setContents(String contents) { | ||
this.contents = contents; | ||
} | ||
|
||
public boolean isDeleted() { | ||
return deleted; | ||
} | ||
|
@@ -84,8 +89,8 @@ public void setDeleted(boolean deleted) { | |
public String toString() { | ||
return "Answer{" + | ||
"id=" + id + | ||
", writerId=" + writerId + | ||
", questionId=" + questionId + | ||
", writer.id=" + writer.getId() + | ||
", question.id=" + question.getId() + | ||
", contents='" + contents + '\'' + | ||
", deleted=" + deleted + | ||
'}'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package qna.domain; | ||
|
||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseEntity { | ||
|
||
@CreatedDate | ||
@Column(updatable = false) | ||
private LocalDateTime createdAt; | ||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
|
||
public LocalDateTime getCreatedAt() { | ||
return createdAt; | ||
} | ||
|
||
public LocalDateTime getUpdatedAt() { | ||
return updatedAt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
proxyBeanMethods = false
설정을 추가하신 이유가 궁금해요~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.
저도 궁금해요!
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.
proxyBeanMethods = false
를 주로 사용하고 있습니다.