-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from woowacourse-teams/feature/192-report-com…
…plete #192 신고 도메인 구현하기
- Loading branch information
Showing
32 changed files
with
430 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,4 @@ | ||
export const REPORT_TARGET = { | ||
COMMENT: 'COMMENT', | ||
ARTICLE: 'ARTICLE' | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
58 changes: 58 additions & 0 deletions
58
src/main/java/com/saebyeok/saebyeok/domain/report/Report.java
This file contains 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,58 @@ | ||
package com.saebyeok.saebyeok.domain.report; | ||
|
||
import com.saebyeok.saebyeok.domain.Member; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.OnDelete; | ||
import org.hibernate.annotations.OnDeleteAction; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
public class Report { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "REPORT_ID") | ||
private Long id; | ||
|
||
private String content; | ||
private Long targetContentId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private ReportTarget reportTarget; | ||
|
||
@OnDelete(action = OnDeleteAction.CASCADE) | ||
@JoinColumn(name = "MEMBER_ID", nullable = false) | ||
@ManyToOne | ||
private Member member; | ||
|
||
@OnDelete(action = OnDeleteAction.CASCADE) | ||
@JoinColumn(name = "REPORT_CATEGORY_ID", nullable = false) | ||
@ManyToOne | ||
private ReportCategory reportCategory; | ||
|
||
@CreatedDate | ||
private LocalDateTime createdDate; | ||
|
||
private Boolean isFinished = Boolean.FALSE; | ||
|
||
public Report(String content, Member member, ReportTarget reportTarget, Long targetContentId, ReportCategory reportCategory) { | ||
this.content = content; | ||
this.member = member; | ||
this.reportTarget = reportTarget; | ||
this.targetContentId = targetContentId; | ||
this.reportCategory = reportCategory; | ||
} | ||
|
||
public void finish() { | ||
this.isFinished = true; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/saebyeok/saebyeok/domain/report/ReportRepository.java
This file contains 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,6 @@ | ||
package com.saebyeok.saebyeok.domain.report; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/saebyeok/saebyeok/domain/report/ReportTarget.java
This file contains 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.saebyeok.saebyeok.domain.report; | ||
|
||
import com.saebyeok.saebyeok.exception.ReportTargetNotFoundException; | ||
import lombok.Getter; | ||
|
||
import java.util.Arrays; | ||
|
||
@Getter | ||
public enum ReportTarget { | ||
ARTICLE("ARTICLE"), | ||
COMMENT("COMMENT"); | ||
|
||
private final String name; | ||
|
||
ReportTarget(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static ReportTarget findReportTarget(String typeValue) { | ||
return Arrays.stream(ReportTarget.values()). | ||
filter(reportTarget -> reportTarget.name().equals(typeValue)). | ||
findAny(). | ||
orElseThrow(() -> new ReportTargetNotFoundException(typeValue)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/saebyeok/saebyeok/dto/report/ReportCreateRequest.java
This file contains 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,31 @@ | ||
package com.saebyeok.saebyeok.dto.report; | ||
|
||
import com.saebyeok.saebyeok.domain.Member; | ||
import com.saebyeok.saebyeok.domain.report.Report; | ||
import com.saebyeok.saebyeok.domain.report.ReportCategory; | ||
import com.saebyeok.saebyeok.domain.report.ReportTarget; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReportCreateRequest { | ||
private String content; | ||
|
||
@NotNull(message = "신고할 게시물을 반드시 선택해 주셔야 해요.") | ||
private Long targetContentId; | ||
|
||
@NotNull(message = "신고 분류는 반드시 선택해 주셔야 해요.") | ||
private Long reportCategoryId; | ||
|
||
@NotNull(message = "신고할 게시물의 종류는 반드시 선택해 주셔야 해요.") | ||
private String reportTarget; | ||
|
||
public Report toReport(Member member, ReportCategory reportCategory) { | ||
return new Report(content, member, ReportTarget.findReportTarget(this.reportTarget), targetContentId, reportCategory); | ||
} | ||
} |
Oops, something went wrong.