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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 |
---|---|---|
@@ -1,19 +1,51 @@ | ||
package qna.domain; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Lob; | ||
import qna.NotFoundException; | ||
import qna.UnAuthorizedException; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
public class Answer { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private Long writerId; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@Column(nullable = false) | ||
private boolean deleted = false; | ||
|
||
private Long questionId; | ||
private LocalDateTime updatedAt; | ||
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. 생성, 수정 시각을 자동으로 관리하기 위해 Auditing 기능을 학습해서 적용해보시면 좋겠습니다. |
||
private Long writerId; | ||
|
||
@Lob | ||
private String contents; | ||
private boolean deleted = false; | ||
|
||
public Answer(User writer, Question question, String contents) { | ||
this(null, writer, question, contents); | ||
|
||
public Answer(Long id, LocalDateTime createdAt, boolean deleted, Long questionId, LocalDateTime updatedAt, | ||
Long writerId, String contents) { | ||
this.id = id; | ||
this.createdAt = createdAt; | ||
this.deleted = deleted; | ||
this.questionId = questionId; | ||
this.updatedAt = updatedAt; | ||
this.writerId = writerId; | ||
this.contents = contents; | ||
} | ||
|
||
public Answer(LocalDateTime createdAt, boolean deleted, Long questionId, LocalDateTime updatedAt, | ||
Long writerId, String contents) { | ||
this(null, createdAt, deleted, questionId, updatedAt, writerId, contents); | ||
} | ||
|
||
public Answer(Long id, User writer, Question question, String contents) { | ||
|
@@ -32,6 +64,9 @@ public Answer(Long id, User writer, Question question, String contents) { | |
this.contents = contents; | ||
} | ||
|
||
public Answer() { | ||
} | ||
|
||
public boolean isOwner(User writer) { | ||
return this.writerId.equals(writer.getId()); | ||
} | ||
|
@@ -40,46 +75,10 @@ public void toQuestion(Question question) { | |
this.questionId = question.getId(); | ||
} | ||
|
||
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 void setQuestionId(Long questionId) { | ||
this.questionId = questionId; | ||
} | ||
|
||
public String getContents() { | ||
return contents; | ||
} | ||
|
||
public void setContents(String contents) { | ||
this.contents = contents; | ||
} | ||
|
||
public boolean isDeleted() { | ||
return deleted; | ||
} | ||
|
||
public void setDeleted(boolean deleted) { | ||
this.deleted = deleted; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Answer{" + | ||
|
@@ -90,4 +89,16 @@ public String toString() { | |
", deleted=" + deleted + | ||
'}'; | ||
} | ||
|
||
public void setDeleted(boolean deleted) { | ||
this.deleted = deleted; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Long getWriterId() { | ||
return writerId; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package qna.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface DeleteHistoryRepository extends JpaRepository<DeleteHistory, Long> { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
package qna.domain; | ||
|
||
import java.time.LocalDateTime; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import qna.UnAuthorizedException; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 아래 제약 조건 추가를 위해서는 어떤 설정을 해줄 수 있을까요? alter table user
add constraint UK_a3imlf41l37utmxiquukk8ajc unique (user_id) |
||
private String userId; | ||
private String password; | ||
private String name; | ||
@Column(nullable = false) | ||
private LocalDateTime createdAt; | ||
@Column(length = 50) | ||
private String email; | ||
@Column(nullable = false, length = 20) | ||
private String name; | ||
@Column(nullable = false, length = 20) | ||
private String password; | ||
private LocalDateTime updatedAt; | ||
@Column(nullable = false, length = 20) | ||
private String userId; | ||
|
||
private User() { | ||
} | ||
|
||
public User(String userId, String password, String name, String email) { | ||
this(null, userId, password, name, email); | ||
public User() { | ||
} | ||
|
||
public User(Long id, String userId, String password, String name, String email) { | ||
|
@@ -66,42 +78,6 @@ public Long getId() { | |
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package subway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} | ||
|
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.
여러 엔티티에 동일하게 추가되는 필드가 있는데,
MappedSuperclass
또는Embeddable
을 학습해보시면 중복 코드 제거가 가능하겠네요.둘 중 무엇을 사용하면 좋을지, 각각 어떤 장단점이 있는지 고민해서 적용해보시면 좋겠습니다.