From b50678dbeed6d89ed6d68eeee6224e122295e304 Mon Sep 17 00:00:00 2001 From: HyoBN Date: Thu, 25 Apr 2024 15:54:40 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Feat:=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/entity/Invitation/Invitation.java | 35 ++++++++++++ .../entity/Invitation/InvitationStatus.java | 6 ++ .../server/global/entity/User/User.java | 53 ++++++++++++++++++ .../server/global/entity/User/UserRole.java | 16 ++++++ .../server/global/entity/User/UserStatus.java | 5 ++ .../server/global/entity/comment/Comment.java | 26 +++++++++ .../entity/common/BaseDateTimeEntity.java | 25 +++++++++ .../server/global/entity/feed/Feed.java | 38 +++++++++++++ .../server/global/entity/feed/FeedImage.java | 23 ++++++++ .../server/global/entity/member/Member.java | 55 +++++++++++++++++++ .../entity/notification/Notification.java | 38 +++++++++++++ .../entity/notification/NotificationType.java | 5 ++ .../global/entity/reaction/Reaction.java | 30 ++++++++++ .../global/entity/reaction/ReactionType.java | 5 ++ .../global/entity/reaction/TargetType.java | 5 ++ .../global/entity/treeHouse/TreeHouse.java | 29 ++++++++++ 16 files changed, 394 insertions(+) create mode 100644 src/main/java/treehouse/server/global/entity/Invitation/Invitation.java create mode 100644 src/main/java/treehouse/server/global/entity/Invitation/InvitationStatus.java create mode 100644 src/main/java/treehouse/server/global/entity/User/User.java create mode 100644 src/main/java/treehouse/server/global/entity/User/UserRole.java create mode 100644 src/main/java/treehouse/server/global/entity/User/UserStatus.java create mode 100644 src/main/java/treehouse/server/global/entity/comment/Comment.java create mode 100644 src/main/java/treehouse/server/global/entity/common/BaseDateTimeEntity.java create mode 100644 src/main/java/treehouse/server/global/entity/feed/Feed.java create mode 100644 src/main/java/treehouse/server/global/entity/feed/FeedImage.java create mode 100644 src/main/java/treehouse/server/global/entity/member/Member.java create mode 100644 src/main/java/treehouse/server/global/entity/notification/Notification.java create mode 100644 src/main/java/treehouse/server/global/entity/notification/NotificationType.java create mode 100644 src/main/java/treehouse/server/global/entity/reaction/Reaction.java create mode 100644 src/main/java/treehouse/server/global/entity/reaction/ReactionType.java create mode 100644 src/main/java/treehouse/server/global/entity/reaction/TargetType.java create mode 100644 src/main/java/treehouse/server/global/entity/treeHouse/TreeHouse.java diff --git a/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java b/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java new file mode 100644 index 0000000..b44b702 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java @@ -0,0 +1,35 @@ +package treehouse.server.global.entity.Invitation; + + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.time.LocalDateTime; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Invitation extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String phone; + + @Setter + private InvitationStatus status; + + private LocalDateTime expiredAt; //초대장 만료일자 + + @JoinColumn(name = "senderId") + @ManyToOne(fetch = FetchType.LAZY) + private Member sender; + @JoinColumn(name = "treeId") + @ManyToOne(fetch = FetchType.LAZY) + private TreeHouse treeHouse; +} diff --git a/src/main/java/treehouse/server/global/entity/Invitation/InvitationStatus.java b/src/main/java/treehouse/server/global/entity/Invitation/InvitationStatus.java new file mode 100644 index 0000000..d13025e --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/Invitation/InvitationStatus.java @@ -0,0 +1,6 @@ +package treehouse.server.global.entity.Invitation; + +public enum InvitationStatus { + PENDING, ACCEPTED, REJECTED + //초대장의 상태 - 대기중, 수락, 거절 +} diff --git a/src/main/java/treehouse/server/global/entity/User/User.java b/src/main/java/treehouse/server/global/entity/User/User.java new file mode 100644 index 0000000..265c907 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/User/User.java @@ -0,0 +1,53 @@ +package treehouse.server.global.entity.User; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; + +import java.time.LocalDateTime; +import java.util.List; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "user") +public class User extends BaseDateTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column(unique = true) + private String phone; + private String name; //고유 문자열 아이디(인스타그램 st.) + private String bio; + + private String profileImageUrl; //프로필 이미지 + + private UserStatus status; + + @Enumerated(EnumType.STRING) + private UserRole role; + + // 활동량 및 초대장 개수 트리별로 적용되는 것 맞는지 확인하기 + @Builder.Default + private Double activeRate = 0.0; //활동량 + @Builder.Default + private Integer invitationCount = 3; //남아있는 초대장의 개수 + + // 탈퇴일자 필요한지 확인하기 + // 특정 트리의 탈퇴한 멤버를 Member Table 에 그대로 쌓을건지? + // db의 Member Table에 userId 필드 값은 그대로 두는지 or -1 등으로 갱신하는지 + // - 만약 특정 User가 특정 Tree에 들어간 적이 있는지 알아야 한다면 + private LocalDateTime inactivatedAt; //탈퇴일자 + + + @OneToMany(mappedBy = "user") + private List memberList; + +} \ No newline at end of file diff --git a/src/main/java/treehouse/server/global/entity/User/UserRole.java b/src/main/java/treehouse/server/global/entity/User/UserRole.java new file mode 100644 index 0000000..551842d --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/User/UserRole.java @@ -0,0 +1,16 @@ +package treehouse.server.global.entity.User; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum UserRole { + ROLE_GUEST("게스트"), + ROLE_USER("회원"), + ROLE_ADMIN("관리자"), + ADMIN("lagacy 관리자"), + USER("lagacy 회원"); + + private final String description; +} diff --git a/src/main/java/treehouse/server/global/entity/User/UserStatus.java b/src/main/java/treehouse/server/global/entity/User/UserStatus.java new file mode 100644 index 0000000..ff48265 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/User/UserStatus.java @@ -0,0 +1,5 @@ +package treehouse.server.global.entity.User; + +public enum UserStatus { + ACTIVE, INACTIVE, WITHDRAWAL +} diff --git a/src/main/java/treehouse/server/global/entity/comment/Comment.java b/src/main/java/treehouse/server/global/entity/comment/Comment.java new file mode 100644 index 0000000..bae18cc --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/comment/Comment.java @@ -0,0 +1,26 @@ +package treehouse.server.global.entity.comment; + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.feed.Feed; +import treehouse.server.global.entity.member.Member; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Comment extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @JoinColumn(name = "writerId") + @ManyToOne(fetch = FetchType.LAZY) + private Member writer; + + @JoinColumn(name = "feedId") + @ManyToOne(fetch = FetchType.LAZY) + private Feed feed; +} \ No newline at end of file diff --git a/src/main/java/treehouse/server/global/entity/common/BaseDateTimeEntity.java b/src/main/java/treehouse/server/global/entity/common/BaseDateTimeEntity.java new file mode 100644 index 0000000..a4cc6f9 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/common/BaseDateTimeEntity.java @@ -0,0 +1,25 @@ +package treehouse.server.global.entity.common; + + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@EntityListeners(AuditingEntityListener.class) +@MappedSuperclass +@Getter +public abstract class BaseDateTimeEntity { + + @Column(updatable = false) + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/src/main/java/treehouse/server/global/entity/feed/Feed.java b/src/main/java/treehouse/server/global/entity/feed/Feed.java new file mode 100644 index 0000000..aae4d0b --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/feed/Feed.java @@ -0,0 +1,38 @@ +package treehouse.server.global.entity.feed; + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.comment.Comment; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.util.Comparator; +import java.util.List; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Feed extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @JoinColumn(name = "writerId") + @ManyToOne(fetch = FetchType.LAZY) + private Member writer; + + @JoinColumn(name = "userId") + @ManyToOne(fetch = FetchType.LAZY) + private TreeHouse treeHouse; + + private String content; + + @OneToMany(mappedBy = "feed") + private List commentList; + + @OneToMany(mappedBy = "feed") + private List feedImageList; +} \ No newline at end of file diff --git a/src/main/java/treehouse/server/global/entity/feed/FeedImage.java b/src/main/java/treehouse/server/global/entity/feed/FeedImage.java new file mode 100644 index 0000000..cf245a8 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/feed/FeedImage.java @@ -0,0 +1,23 @@ +package treehouse.server.global.entity.feed; + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.common.BaseDateTimeEntity; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class FeedImage extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String imageUrl; + + @JoinColumn(name = "feedId") + @ManyToOne(fetch = FetchType.LAZY) + private Feed feed; + +} \ No newline at end of file diff --git a/src/main/java/treehouse/server/global/entity/member/Member.java b/src/main/java/treehouse/server/global/entity/member/Member.java new file mode 100644 index 0000000..bd5a84e --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/member/Member.java @@ -0,0 +1,55 @@ +package treehouse.server.global.entity.member; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import treehouse.server.global.entity.Invitation.Invitation; +import treehouse.server.global.entity.User.User; +import treehouse.server.global.entity.comment.Comment; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.notification.Notification; +import treehouse.server.global.entity.reaction.Reaction; +import treehouse.server.global.entity.treeHouse.TreeHouse; + +import java.util.List; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "member") +public class Member extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; //트리에서 사용할 닉네임 + + private String bio; //자기소개 + + private String profileImageUrl; //프로필 이미지(트리 별로 상이) + + @JoinColumn(name = "userId") + @ManyToOne(fetch = FetchType.LAZY) + private User user; + + @JoinColumn(name = "treeId") + @ManyToOne(fetch = FetchType.LAZY) + private TreeHouse treeHouse; + + @OneToMany(mappedBy = "receiver") + List notificationList; + + @OneToMany(mappedBy = "writer") + List commentList; + + @OneToMany(mappedBy = "sender") + List invitationList; + + @OneToMany(mappedBy = "member") + List reactionList; + + +} diff --git a/src/main/java/treehouse/server/global/entity/notification/Notification.java b/src/main/java/treehouse/server/global/entity/notification/Notification.java new file mode 100644 index 0000000..24e7dd5 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/notification/Notification.java @@ -0,0 +1,38 @@ +package treehouse.server.global.entity.notification; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; + +import java.time.LocalDateTime; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Notification extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + private String body; + private boolean readStatus; + + @JoinColumn(name = "senderId") + @ManyToOne(fetch = FetchType.LAZY) + private Member sender; + + @JoinColumn(name = "receiverId") + @ManyToOne(fetch = FetchType.LAZY) + private Member receiver; + + private Long targetId; + private LocalDateTime receivedTime; +} \ No newline at end of file diff --git a/src/main/java/treehouse/server/global/entity/notification/NotificationType.java b/src/main/java/treehouse/server/global/entity/notification/NotificationType.java new file mode 100644 index 0000000..1e25fc5 --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/notification/NotificationType.java @@ -0,0 +1,5 @@ +package treehouse.server.global.entity.notification; + +public enum NotificationType { + INVITATION, COMMENT, REACTION +} diff --git a/src/main/java/treehouse/server/global/entity/reaction/Reaction.java b/src/main/java/treehouse/server/global/entity/reaction/Reaction.java new file mode 100644 index 0000000..0133e0d --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/reaction/Reaction.java @@ -0,0 +1,30 @@ +package treehouse.server.global.entity.reaction; + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Reaction extends BaseDateTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @JoinColumn(name = "memberId") + @ManyToOne(fetch = FetchType.LAZY) + private Member member; + + @Enumerated(EnumType.STRING) + private ReactionType type; // 예: LIKE, DISLIKE 등 + + private Long targetId; // 반응 대상의 ID + + @Enumerated(EnumType.STRING) + private TargetType targetType; + +} diff --git a/src/main/java/treehouse/server/global/entity/reaction/ReactionType.java b/src/main/java/treehouse/server/global/entity/reaction/ReactionType.java new file mode 100644 index 0000000..79690ea --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/reaction/ReactionType.java @@ -0,0 +1,5 @@ +package treehouse.server.global.entity.reaction; + +public enum ReactionType { + LIKE, DISLIKE, SAD, ANGRY +} diff --git a/src/main/java/treehouse/server/global/entity/reaction/TargetType.java b/src/main/java/treehouse/server/global/entity/reaction/TargetType.java new file mode 100644 index 0000000..a927f2a --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/reaction/TargetType.java @@ -0,0 +1,5 @@ +package treehouse.server.global.entity.reaction; + +public enum TargetType { + POST, COMMENT, REPLY +} diff --git a/src/main/java/treehouse/server/global/entity/treeHouse/TreeHouse.java b/src/main/java/treehouse/server/global/entity/treeHouse/TreeHouse.java new file mode 100644 index 0000000..247520d --- /dev/null +++ b/src/main/java/treehouse/server/global/entity/treeHouse/TreeHouse.java @@ -0,0 +1,29 @@ +package treehouse.server.global.entity.treeHouse; + +import jakarta.persistence.*; +import lombok.*; +import treehouse.server.global.entity.Invitation.Invitation; +import treehouse.server.global.entity.common.BaseDateTimeEntity; +import treehouse.server.global.entity.member.Member; + +import java.util.List; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class TreeHouse extends BaseDateTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + @OneToMany(mappedBy = "treeHouse") + private List memberList; + + @OneToMany(mappedBy = "treeHouse") + private List invitationList; +}