Skip to content

Commit

Permalink
[feat] 신고 테이블 설계
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Sep 6, 2024
1 parent 5eb111d commit 0fc17f4
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class MissionPost extends BaseEntity {
@Builder.Default
private List<MissionPostComment> missionPostComments = new ArrayList<>();

@OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL)
@Builder.Default
private List<MissionPostReport> missionPostReports = new ArrayList<>();

@OnDelete(action = OnDeleteAction.CASCADE)
@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MissionPostCommentReport> missionPostCommentReports = new ArrayList<>();

public static MissionPostComment createMissionPostComment(String comment, MissionPost missionPost, User user){
MissionPostComment newMissionPostComment = MissionPostComment.builder()
.comment(comment)
Expand All @@ -47,4 +51,8 @@ public static MissionPostComment createMissionPostComment(String comment, Missio

return newMissionPostComment;
}

public void addReport(MissionPostCommentReport missionPostCommentReport){
this.missionPostCommentReports.add(missionPostCommentReport);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<MissionPostComment, Long> {
}

0 comments on commit 0fc17f4

Please sign in to comment.