diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java index 218ad79..262403a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java @@ -40,6 +40,9 @@ public class MissionPost extends BaseEntity { @Builder.Default private List missionPostComments = new ArrayList<>(); + @OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL) + @Builder.Default + private List missionPostReports = new ArrayList<>(); @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @@ -66,4 +69,8 @@ public void addLike(MissionPostLike missionPostLike) { public void addComment(MissionPostComment missionPostComment) { missionPostComments.add(missionPostComment); } + + public void addReport(MissionPostReport missionPostReport){ + this.missionPostReports.add(missionPostReport); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java index 585cf26..d8a3a5a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java @@ -3,14 +3,14 @@ import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.global.common.BaseEntity; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.SuperBuilder; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; +import java.util.ArrayList; +import java.util.List; + @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Getter @@ -35,6 +35,10 @@ public class MissionPostComment extends BaseEntity { @JoinColumn(name = "user_id") private User user; + @OneToMany(mappedBy = "missionPostComment", cascade = CascadeType.ALL) + @Builder.Default + private List missionPostCommentReports = new ArrayList<>(); + public static MissionPostComment createMissionPostComment(String comment, MissionPost missionPost, User user){ MissionPostComment newMissionPostComment = MissionPostComment.builder() .comment(comment) @@ -47,4 +51,8 @@ public static MissionPostComment createMissionPostComment(String comment, Missio return newMissionPostComment; } + + public void addReport(MissionPostCommentReport missionPostCommentReport){ + this.missionPostCommentReports.add(missionPostCommentReport); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java new file mode 100644 index 0000000..1423d1c --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java @@ -0,0 +1,43 @@ +package com.modernfarmer.farmusspring.domain.farmclub.entity; + +import com.modernfarmer.farmusspring.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@SuperBuilder +@Entity(name = "mission_post_comment_report") +public class MissionPostCommentReport { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_post_comment_report_id") + private Long id; + + @OnDelete(action = OnDeleteAction.CASCADE) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_post_comment_id") + private MissionPostComment missionPostComment; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + public static MissionPostCommentReport createMissionPostCommentReport(MissionPostComment missionPostComment, User user){ + MissionPostCommentReport report = MissionPostCommentReport.builder() + .missionPostComment(missionPostComment) + .user(user) + .build(); + + missionPostComment.addReport(report); + return report; + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java new file mode 100644 index 0000000..3558ac1 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java @@ -0,0 +1,43 @@ +package com.modernfarmer.farmusspring.domain.farmclub.entity; + +import com.modernfarmer.farmusspring.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@SuperBuilder +@Entity(name = "mission_post_report") +public class MissionPostReport { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_post_report_id") + private Long id; + + @OnDelete(action = OnDeleteAction.CASCADE) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_post_id") + private MissionPost missionPost; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + public static MissionPostReport createMissionPostReport(MissionPost missionPost, User user){ + MissionPostReport report = MissionPostReport.builder() + .missionPost(missionPost) + .user(user) + .build(); + + missionPost.addReport(report); + return report; + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostCommentRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostCommentRepository.java new file mode 100644 index 0000000..93d204a --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostCommentRepository.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPostComment; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MissionPostCommentRepository extends JpaRepository { +}