-
Notifications
You must be signed in to change notification settings - Fork 8
커뮤니티 엔티티 정의 #48
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
Merged
leesewon00
merged 4 commits into
solid-connection:main
from
leesewon00:feat/47-define-community-entity
Aug 2, 2024
Merged
커뮤니티 엔티티 정의 #48
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/solidconnection/entity/Board.java
This file contains hidden or 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 com.example.solidconnection.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class Board { | ||
|
|
||
| @Id | ||
| @Column(length = 20) | ||
| private String code; | ||
|
|
||
| @Column(nullable = false, length = 20) | ||
| private String koreanName; | ||
|
|
||
| @OneToMany(mappedBy = "board", cascade = CascadeType.ALL) | ||
| private List<Post> postList = new ArrayList<>(); | ||
| } | ||
|
|
||
42 changes: 42 additions & 0 deletions
42
src/main/java/com/example/solidconnection/entity/Comment.java
This file contains hidden or 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,42 @@ | ||
| package com.example.solidconnection.entity; | ||
|
|
||
| import com.example.solidconnection.entity.common.BaseEntity; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import jakarta.persistence.*; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class Comment extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(length = 255) | ||
| private String content; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "post_id") | ||
| private Post post; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "site_user_id") | ||
| private SiteUser siteUser; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "parent_id") | ||
| private Comment parentComment; | ||
|
|
||
| @OneToMany(mappedBy = "parentComment", cascade = CascadeType.ALL) | ||
| private List<Comment> commentList = new ArrayList<>(); | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/example/solidconnection/entity/Post.java
This file contains hidden or 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,54 @@ | ||
| package com.example.solidconnection.entity; | ||
|
|
||
| import com.example.solidconnection.entity.common.BaseEntity; | ||
| import com.example.solidconnection.entity.mapping.PostLike; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.type.PostCategory; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @ToString | ||
| public class Post extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(length = 255) | ||
| private String title; | ||
|
|
||
| @Column(length = 1000) | ||
| private String content; | ||
|
|
||
| private Boolean isQuestion; | ||
|
|
||
| private Long likeCount; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private PostCategory category; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "board_code") | ||
| private Board board; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "site_user_id") | ||
| private SiteUser siteUser; | ||
|
|
||
| @OneToMany(mappedBy = "post", cascade = CascadeType.ALL) | ||
| private List<Comment> commentList = new ArrayList<>(); | ||
|
|
||
| @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<PostImage> postImageList = new ArrayList<>(); | ||
|
|
||
| @OneToMany(mappedBy = "post", cascade = CascadeType.ALL) | ||
| private List<PostLike> postLikeList = new ArrayList<>(); | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/solidconnection/entity/PostImage.java
This file contains hidden or 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,25 @@ | ||
| package com.example.solidconnection.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class PostImage { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(length = 500) | ||
| private String url; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "post_id") | ||
| private Post post; | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/solidconnection/entity/common/BaseEntity.java
This file contains hidden or 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,26 @@ | ||
| package com.example.solidconnection.entity.common; | ||
|
|
||
| import jakarta.persistence.EntityListeners; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import lombok.Getter; | ||
| import org.hibernate.annotations.DynamicInsert; | ||
| import org.hibernate.annotations.DynamicUpdate; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
| import org.springframework.data.annotation.LastModifiedDate; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @MappedSuperclass | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| @Getter | ||
| @DynamicUpdate | ||
| @DynamicInsert | ||
| public abstract class BaseEntity { | ||
|
|
||
| @CreatedDate | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @LastModifiedDate | ||
| private LocalDateTime updatedAt; | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/solidconnection/entity/mapping/PostLike.java
This file contains hidden or 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,28 @@ | ||
| package com.example.solidconnection.entity.mapping; | ||
|
|
||
| import com.example.solidconnection.entity.Post; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import jakarta.persistence.*; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class PostLike { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "post_id") | ||
| private Post post; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "site_user_id") | ||
| private SiteUser siteUser; | ||
| } |
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/solidconnection/type/PostCategory.java
This file contains hidden or 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,5 @@ | ||
| package com.example.solidconnection.type; | ||
|
|
||
| public enum PostCategory { | ||
| 전체, 자유, 질문 | ||
| } |
This file contains hidden or 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
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.
💭 이것은 그냥 이전 코드에 대한 설명.. 반영하실 필요는 전혀 없습니다
빌더 패턴을 사용하셨네요! 지금 이전의 엔티티들을 보면 빌더 페턴을 사용하고 있지 않아서 이유를 말씀드려야 할 것 같아요.
저는 개인적으로 직접 생성자를 만들어주는 편이에요. 빌더 패턴은 인자를 명시적으로 전달할 수 있다는 점은 정말 편리하다고 생각하지만, 누락하는 인자가 있을 수 있다는 점이 치명적이라는 생각을 했어요. 그래서 이전 코드에서는 생성자를 만들어주었어요.
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.
해당부분은 인지하고 있습니다!
추가적인 생성자를 생성하지않고, 유연하게 대처할 수 있어서 주로 사용하였는데,
추후 리팩토링 단계에서 추가적인 생성자 사용을 고려해보도록 하겠습니다.