-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.guzzing.studay_server; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.util.Assert; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Report { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name="report_id") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long postId; | ||
|
||
@Column(nullable = false) | ||
private Long reporterId; | ||
|
||
@Column | ||
private String contents; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private ReportItem item; | ||
|
||
public Report(Long postId, Long reporterId, String contents, ReportItem item) { | ||
Assert.notNull(postId,"게시글 Id는 null이 들어올 수 없습니다."); | ||
Assert.notNull(reporterId,"신고자의 Id는 null이 들어올 수 없습니다"); | ||
Assert.notNull(item,"신고항목은 null이 들어올 수 없습니다."); | ||
|
||
this.postId = postId; | ||
this.reporterId = reporterId; | ||
this.contents = contents; | ||
this.item = item; | ||
} | ||
|
||
} |
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,33 @@ | ||
package org.guzzing.studay_server; | ||
|
||
import org.springframework.data.crossstore.ChangeSetPersister; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ReportItem { | ||
FAKED_SALE("허위 매물", 5), | ||
SPAMMING("도배글", 1), | ||
SWEAR_WORD("욕설", 3), | ||
SENSATIONAL("선정성", 5), | ||
PERSONAL_INFORMATION_EXPOSURE("개인정보노출", 2), | ||
COMMENTS("기타사항",1); | ||
|
||
private final String description; | ||
private final int score; | ||
|
||
ReportItem(String description, int score) { | ||
this.description = description; | ||
this.score = score; | ||
} | ||
|
||
public int getScore() { | ||
return score; | ||
} | ||
|
||
public static ReportItem find(String reportItem) throws ChangeSetPersister.NotFoundException { | ||
return Arrays.stream(ReportItem.values()).filter(r->r.equals(reportItem)). | ||
findFirst().orElseThrow(()-> new ChangeSetPersister.NotFoundException()); | ||
} | ||
|
||
} | ||
|
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,50 @@ | ||
package org.guzzing.studay_server; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ReportTest { | ||
|
||
@Test | ||
@DisplayName("!!필수로 들어가야 하는 게시글 id가 들어가지 않은 경우 예외를 던진다. 롤루") | ||
public void createReport_nullPostId_throwIllegalArgumentException() { | ||
//given | ||
Long postId = null; | ||
Long reporterId = 2L; | ||
String contents = "This is a report."; | ||
ReportItem item = ReportItem.FAKED_SALE; | ||
|
||
//when_then | ||
assertThrows(IllegalArgumentException.class,()->new Report(postId, reporterId, contents, item)); | ||
} | ||
|
||
@Test | ||
@DisplayName("필수로 들어가야 하는 신고자 id가 들어가지 않는 경우 예외를 던진다.") | ||
public void createReport_nullReporterId_throwIllegalArgumentException() { | ||
//given | ||
Long postId = 1L; | ||
Long reporterId = 2L; | ||
String contents = "This is a report."; | ||
ReportItem item = ReportItem.FAKED_SALE; | ||
|
||
//when_then | ||
assertThrows(IllegalArgumentException.class,()->new Report(postId, reporterId, contents, item)); | ||
} | ||
|
||
@Test | ||
@DisplayName("필수로 들어가야 하는 신고 항목이 들어가지 않은 경우 예외를 던진다.") | ||
public void createReport_nullItem_throwIllegalArgumentException() { | ||
//given | ||
Long postId = 1L; | ||
Long reporterId = 2L; | ||
String contents = "This is a report."; | ||
ReportItem item = null; | ||
|
||
//when_then | ||
assertThrows(IllegalArgumentException.class,()->new Report(postId, reporterId, contents, item)); | ||
} | ||
} | ||
|
||
|
13 changes: 0 additions & 13 deletions
13
src/test/java/org/guzzing/studay_server/StudayServerApplicationTests.java
This file was deleted.
Oops, something went wrong.