-
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
27 changed files
with
330 additions
and
20 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
28 changes: 28 additions & 0 deletions
28
Api/src/main/java/allchive/server/api/report/controller/ReportController.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,28 @@ | ||
package allchive.server.api.report.controller; | ||
|
||
|
||
import allchive.server.api.report.model.dto.request.CreateReportRequest; | ||
import allchive.server.api.report.service.CreateReportUseCase; | ||
import allchive.server.domain.domains.report.domain.enums.ReportObjectType; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/reports") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Tag(name = "7. [report]") | ||
public class ReportController { | ||
private final CreateReportUseCase createReportUseCase; | ||
|
||
@Operation(summary = "아카이빙, 컨텐츠를 신고합니다.") | ||
@PostMapping() | ||
public void createReport( | ||
@RequestParam("type") ReportObjectType type, | ||
@RequestBody CreateReportRequest createReportRequest) { | ||
createReportUseCase.execute(createReportRequest, type); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Api/src/main/java/allchive/server/api/report/model/dto/request/CreateReportRequest.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,20 @@ | ||
package allchive.server.api.report.model.dto.request; | ||
|
||
|
||
import allchive.server.core.annotation.ValidEnum; | ||
import allchive.server.domain.domains.report.domain.enums.ReportedType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CreateReportRequest { | ||
@Schema(defaultValue = "기타기타기타기타기타", description = "사유 ('기타'에만 해당)") | ||
private String reason; | ||
|
||
@Schema(defaultValue = "spam", description = "신고 종류") | ||
@ValidEnum(target = ReportedType.class) | ||
private ReportedType reportedType; | ||
|
||
@Schema(defaultValue = "1", description = "아카이빙, 컨텐츠 고유번호") | ||
private Long id; | ||
} |
31 changes: 31 additions & 0 deletions
31
Api/src/main/java/allchive/server/api/report/model/mapper/ReportMapper.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 allchive.server.api.report.model.mapper; | ||
|
||
|
||
import allchive.server.api.report.model.dto.request.CreateReportRequest; | ||
import allchive.server.core.annotation.Mapper; | ||
import allchive.server.domain.domains.report.domain.Report; | ||
import allchive.server.domain.domains.report.domain.enums.ReportObjectType; | ||
|
||
@Mapper | ||
public class ReportMapper { | ||
public Report toEntity(CreateReportRequest request, ReportObjectType type, Long userId) { | ||
Report report = null; | ||
switch (type) { | ||
case CONTENT -> report = Report.of( | ||
type, | ||
request.getReason(), | ||
request.getReportedType(), | ||
request.getId(), | ||
null, | ||
userId); | ||
case ARCHIVING -> report = Report.of( | ||
type, | ||
request.getReason(), | ||
request.getReportedType(), | ||
null, | ||
request.getId(), | ||
userId); | ||
} | ||
return report; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Api/src/main/java/allchive/server/api/report/service/CreateReportUseCase.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,37 @@ | ||
package allchive.server.api.report.service; | ||
|
||
|
||
import allchive.server.api.config.security.SecurityUtil; | ||
import allchive.server.api.report.model.dto.request.CreateReportRequest; | ||
import allchive.server.api.report.model.mapper.ReportMapper; | ||
import allchive.server.core.annotation.UseCase; | ||
import allchive.server.domain.domains.archiving.validator.ArchivingValidator; | ||
import allchive.server.domain.domains.content.validator.ContentValidator; | ||
import allchive.server.domain.domains.report.domain.Report; | ||
import allchive.server.domain.domains.report.domain.enums.ReportObjectType; | ||
import allchive.server.domain.domains.report.service.ReportDomainService; | ||
import allchive.server.domain.domains.report.validator.ReportValidator; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class CreateReportUseCase { | ||
private final ReportValidator reportValidator; | ||
private final ContentValidator contentValidator; | ||
private final ArchivingValidator archivingValidator; | ||
private final ReportMapper reportMapper; | ||
private final ReportDomainService reportDomainService; | ||
|
||
@Transactional | ||
public void execute(CreateReportRequest request, ReportObjectType type) { | ||
Long userId = SecurityUtil.getCurrentUserId(); | ||
reportValidator.validateNotDuplicateReport(userId, request.getId(), type); | ||
switch (type) { | ||
case CONTENT -> contentValidator.validateExistById(request.getId()); | ||
case ARCHIVING -> archivingValidator.validateExistById(request.getId()); | ||
} | ||
Report report = reportMapper.toEntity(request, type, userId); | ||
reportDomainService.save(report); | ||
} | ||
} |
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
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
8 changes: 5 additions & 3 deletions
8
Domain/src/main/java/allchive/server/domain/domains/report/exception/ReportErrorCode.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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
package allchive.server.domain.domains.report.exception; | ||
|
||
import static allchive.server.core.consts.AllchiveConst.BAD_REQUEST; | ||
|
||
import allchive.server.core.dto.ErrorReason; | ||
import allchive.server.core.error.BaseErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ReportErrorCode implements BaseErrorCode { | ||
DUPLICATED_REPORT_CONTENT(BAD_REQUEST, "REPORT_400_1", "이미 신고한 컨텐츠입니다."), | ||
DUPLICATED_REPORT_ARCHIVING(BAD_REQUEST, "REPORT_400_1", "이미 신고한 아카이빙입니다."), | ||
; | ||
private HttpStatus status; | ||
private int status; | ||
private String code; | ||
private String reason; | ||
|
||
@Override | ||
public ErrorReason getErrorReason() { | ||
return ErrorReason.of(status.value(), code, reason); | ||
return ErrorReason.of(status, code, reason); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...allchive/server/domain/domains/report/exception/exceptions/DuplicatedReportArchiving.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,14 @@ | ||
package allchive.server.domain.domains.report.exception.exceptions; | ||
|
||
|
||
import allchive.server.core.error.BaseErrorException; | ||
import allchive.server.domain.domains.report.exception.ReportErrorCode; | ||
|
||
public class DuplicatedReportArchiving extends BaseErrorException { | ||
|
||
public static final BaseErrorException EXCEPTION = new DuplicatedReportArchiving(); | ||
|
||
private DuplicatedReportArchiving() { | ||
super(ReportErrorCode.DUPLICATED_REPORT_ARCHIVING); | ||
} | ||
} |
Oops, something went wrong.