From 0d226dba51f6a0b4c13910889b82a363bf3d8852 Mon Sep 17 00:00:00 2001 From: Suyoung Oh Date: Sun, 19 Feb 2023 15:21:44 +0900 Subject: [PATCH] =?UTF-8?q?Add=20:=20Entity=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EC=9E=AC=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/hearts/ClinicHeart.java | 30 +++++++++++++++++++ .../domain/hearts/PostHeart.java | 30 +++++++++++++++++++ .../domain/posts/ClinicPost.java | 30 +++++++++++++++++++ .../domain/posts/Feeling.java | 7 +++++ .../posts/{Posts.java => FeelingPost.java} | 19 +++++++----- .../domain/posts/Feelings.java | 10 ------- .../domain/user/User.java | 9 ++++-- .../repository/PostsRepository.java | 12 ++++---- .../repository/UserRepository.java | 1 - 9 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/ClinicHeart.java create mode 100644 src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/PostHeart.java create mode 100644 src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/ClinicPost.java create mode 100644 src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feeling.java rename src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/{Posts.java => FeelingPost.java} (55%) delete mode 100644 src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feelings.java diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/ClinicHeart.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/ClinicHeart.java new file mode 100644 index 0000000..4247372 --- /dev/null +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/ClinicHeart.java @@ -0,0 +1,30 @@ +package com.gdschanyang.todayfeelingbackend2.domain.hearts; + +import com.gdschanyang.todayfeelingbackend2.domain.posts.ClinicPost; +import com.gdschanyang.todayfeelingbackend2.domain.user.User; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@NoArgsConstructor +@Entity +public class ClinicHeart { + // 공감한 유저, 공감한 클리닉 글 + @Id + private Long id; + + // ClinicHeart : User = 1 : n 매핑 + @OneToMany + @JoinColumn(name = "CLINIC_HEART_USER") + private List users = new ArrayList(); + + // ClinicHeart : ClinicPost = 1 : n 매핑 + @OneToMany + @JoinColumn(name = "CLINIC_HEART_POST") + private List ClinicPosts = new ArrayList(); + +} diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/PostHeart.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/PostHeart.java new file mode 100644 index 0000000..95e34a2 --- /dev/null +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/hearts/PostHeart.java @@ -0,0 +1,30 @@ +package com.gdschanyang.todayfeelingbackend2.domain.hearts; + +import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; +import com.gdschanyang.todayfeelingbackend2.domain.user.User; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@NoArgsConstructor +@Entity +public class PostHeart { + // 공감한 유저, 공감한 감정글 + @Id + private Long id; + + // PostHeart : User = 1 : n 매핑 + @OneToMany + @JoinColumn(name = "FEELING_HEART_USER") + private List users = new ArrayList(); + + // PostHeart : FeelingPost = 1 : n 매핑 + @OneToMany + @JoinColumn(name = "FEELING_HEART_POST") + private List feelingPosts = new ArrayList(); + +} diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/ClinicPost.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/ClinicPost.java new file mode 100644 index 0000000..e2f48e4 --- /dev/null +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/ClinicPost.java @@ -0,0 +1,30 @@ +package com.gdschanyang.todayfeelingbackend2.domain.posts; + +import com.gdschanyang.todayfeelingbackend2.domain.user.User; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@NoArgsConstructor +@Entity +public class ClinicPost { + // 제목, 글, 글 쓴 사람 + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(length = 500, nullable = false) + private String title; + + // 글 작성은 필수 + @Column(columnDefinition = "TEXT", nullable = false) + private String content; + + // User 와 ClinicPost 1:1 매핑 + @OneToOne + @JoinColumn(name = "USER_ID") + private User user; + +} diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feeling.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feeling.java new file mode 100644 index 0000000..8064464 --- /dev/null +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feeling.java @@ -0,0 +1,7 @@ +package com.gdschanyang.todayfeelingbackend2.domain.posts; + + +public enum Feeling { + POSITIVE, + NEGATIVE +} diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Posts.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/FeelingPost.java similarity index 55% rename from src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Posts.java rename to src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/FeelingPost.java index 5ba706b..d5cafb9 100644 --- a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Posts.java +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/FeelingPost.java @@ -1,6 +1,7 @@ package com.gdschanyang.todayfeelingbackend2.domain.posts; +import com.gdschanyang.todayfeelingbackend2.domain.user.User; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,22 +10,26 @@ @Getter @NoArgsConstructor @Entity -public class Posts { - +public class FeelingPost { + // 감정, 글, 글 쓴 사람, 삭제 여부 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) - private Feelings feelings; - - @Column(length = 500, nullable = false) - private String title; + private Feeling feeling; // 글 작성은 선택적 @Column(columnDefinition = "TEXT") private String content; + // User 와 FeelingPost 1:1 매핑 + @OneToOne + @JoinColumn(name = "USER_ID") + private User user; + + // 삭제 여부 1:삭제 0:삭제X @Column(nullable = false) - private String author; + private boolean delFlag; + } diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feelings.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feelings.java deleted file mode 100644 index 3f8098b..0000000 --- a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/posts/Feelings.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.gdschanyang.todayfeelingbackend2.domain.posts; - - -public enum Feelings { - SAD, // 슬픔, 우울 - ANGRY, // 화남 - HAPPY, // 행복함, 기쁨 - PROUD // 뿌듯함 - -} diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/user/User.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/user/User.java index ecbd324..186d070 100644 --- a/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/user/User.java +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/domain/user/User.java @@ -13,10 +13,15 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "USER_ID") private Long id; - @Column(nullable = false) - private String name; + // 본명 + @Column(name = "USER_REALNAME", nullable = false) + private String realName; + // 닉네임으로 대나무숲과 클릭닉 센터에서 활동 + @Column(name = "USER_NICKNAME", nullable = false) + private String nickName; } diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/PostsRepository.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/PostsRepository.java index 7305362..50e6225 100644 --- a/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/PostsRepository.java +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/PostsRepository.java @@ -1,18 +1,16 @@ package com.gdschanyang.todayfeelingbackend2.repository; -import com.gdschanyang.todayfeelingbackend2.domain.posts.Posts; -import com.gdschanyang.todayfeelingbackend2.domain.user.User; +import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; import java.util.Optional; -public interface PostsRepository extends JpaRepository { +public interface PostsRepository extends JpaRepository { - Posts save(Posts posts); + FeelingPost save(FeelingPost posts); - Optional findById(Long id); - Optional findByAuthor(String name); + Optional findById(Long id); - List findAll(); + List findAll(); } diff --git a/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/UserRepository.java b/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/UserRepository.java index 321060c..504e7a2 100644 --- a/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/UserRepository.java +++ b/src/main/java/com/gdschanyang/todayfeelingbackend2/repository/UserRepository.java @@ -11,7 +11,6 @@ public interface UserRepository extends JpaRepository { User save(User user); Optional findById(Long id); - Optional findByName(String name); List findAll();