From a4ab7a66b9915e29a6a4d460cebab374e5521bb6 Mon Sep 17 00:00:00 2001 From: Sanghoon Jeong <67852689+wjdtkdgns@users.noreply.github.com> Date: Tue, 1 Aug 2023 22:23:09 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EC=95=84=EC=B9=B4=EC=9D=B4=EB=B9=99=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=9E=A9=20=EC=95=88=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0=20(#77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [fix] scrap validation 수정 #76 * [fix] enum value 대문자로 변경 #76 --- .../service/UpdateArchivingScrapUseCase.java | 4 +++- .../model/dto/request/CreateContentRequest.java | 2 +- .../model/dto/request/UpdateContentRequest.java | 2 +- .../model/dto/request/CreateReportRequest.java | 2 +- .../content/domain/enums/ContentType.java | 4 ++-- .../recycle/domain/enums/RecycleType.java | 4 ++-- .../report/domain/enums/ReportObjectType.java | 4 ++-- .../report/domain/enums/ReportedType.java | 16 ++++++++-------- .../domains/user/adaptor/ScrapAdaptor.java | 4 ++++ .../domains/user/repository/ScrapRepository.java | 2 ++ .../domains/user/validator/ScrapValidator.java | 12 ++++++------ 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java b/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java index 9ff7468b..88ba1f21 100644 --- a/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java +++ b/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java @@ -40,8 +40,10 @@ public void execute(Long archivingId, Boolean cancel) { private void validateExecution(Long archivingId, Long userId, Boolean cancel) { archivingValidator.validateExistById(archivingId); archivingValidator.validateDeleteStatus(archivingId, userId); - if (!cancel) { + if (cancel) { scrapValidator.validateExistScrap(userId, archivingId); + } else { + scrapValidator.validateNotExistScrap(userId, archivingId); } } } diff --git a/Api/src/main/java/allchive/server/api/content/model/dto/request/CreateContentRequest.java b/Api/src/main/java/allchive/server/api/content/model/dto/request/CreateContentRequest.java index ead4b71f..00eddb9b 100644 --- a/Api/src/main/java/allchive/server/api/content/model/dto/request/CreateContentRequest.java +++ b/Api/src/main/java/allchive/server/api/content/model/dto/request/CreateContentRequest.java @@ -9,7 +9,7 @@ @Getter public class CreateContentRequest { - @Schema(defaultValue = "image", description = "컨텐츠 타입") + @Schema(defaultValue = "IMAGE", description = "컨텐츠 타입") @ValidEnum(target = ContentType.class) private ContentType contentType; diff --git a/Api/src/main/java/allchive/server/api/content/model/dto/request/UpdateContentRequest.java b/Api/src/main/java/allchive/server/api/content/model/dto/request/UpdateContentRequest.java index 0298614e..9d29def3 100644 --- a/Api/src/main/java/allchive/server/api/content/model/dto/request/UpdateContentRequest.java +++ b/Api/src/main/java/allchive/server/api/content/model/dto/request/UpdateContentRequest.java @@ -9,7 +9,7 @@ @Getter public class UpdateContentRequest { - @Schema(defaultValue = "image", description = "컨텐츠 타입") + @Schema(defaultValue = "IMAGE", description = "컨텐츠 타입") @ValidEnum(target = ContentType.class) private ContentType contentType; diff --git a/Api/src/main/java/allchive/server/api/report/model/dto/request/CreateReportRequest.java b/Api/src/main/java/allchive/server/api/report/model/dto/request/CreateReportRequest.java index de3d048f..a6f91ac0 100644 --- a/Api/src/main/java/allchive/server/api/report/model/dto/request/CreateReportRequest.java +++ b/Api/src/main/java/allchive/server/api/report/model/dto/request/CreateReportRequest.java @@ -11,7 +11,7 @@ public class CreateReportRequest { @Schema(defaultValue = "기타기타기타기타기타", description = "사유 ('기타'에만 해당)") private String reason; - @Schema(defaultValue = "spam", description = "신고 종류") + @Schema(defaultValue = "SPAM", description = "신고 종류") @ValidEnum(target = ReportedType.class) private ReportedType reportedType; diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/domain/enums/ContentType.java b/Domain/src/main/java/allchive/server/domain/domains/content/domain/enums/ContentType.java index fbec1562..8cb6ebb8 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/domain/enums/ContentType.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/domain/enums/ContentType.java @@ -11,8 +11,8 @@ @Getter @AllArgsConstructor public enum ContentType { - IMAGE("image"), - LINK("link"); + IMAGE("IMAGE"), + LINK("LINK"); @JsonValue private String value; diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/domain/enums/RecycleType.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/domain/enums/RecycleType.java index 4b978a54..16ecaad8 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/domain/enums/RecycleType.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/domain/enums/RecycleType.java @@ -11,8 +11,8 @@ @Getter @AllArgsConstructor public enum RecycleType { - CONTENT("content"), - ARCHIVING("archiving"); + CONTENT("CONTENT"), + ARCHIVING("ARCHIVING"); @JsonValue private String value; diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportObjectType.java b/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportObjectType.java index 5c90c3c7..46d895a3 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportObjectType.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportObjectType.java @@ -11,8 +11,8 @@ @Getter @AllArgsConstructor public enum ReportObjectType { - CONTENT("content"), - ARCHIVING("archiving"); + CONTENT("CONTENT"), + ARCHIVING("ARCHIVING"); @JsonValue private String value; diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportedType.java b/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportedType.java index ad0f8cc4..abe43c72 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportedType.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/domain/enums/ReportedType.java @@ -11,14 +11,14 @@ @Getter @AllArgsConstructor public enum ReportedType { - SPAM("spam"), // 스팸이에요 - OBSCENE("obscene"), // 음란성 컨텐츠를 담고있어요 - PERSONAL_INFO("personalInfo"), // 개인정보를 노출하고 있어요 - INTELLECTUAL_PROPERTY("intellectualProperty"), // 지식재산권을 침해해요 - VIOLENCE("violence"), // 혐오/폭력 컨텐츠를 담고 있어요 - ILLEGAL_INFO("illegalInformation"), // 불법 정보를 포함하고 있어요 - FRAUD("fraud"), // 사기 또는 피싱성 링크를 포함하고 있어요 - ETC("etc"); // 기타 + SPAM("SPAM"), // 스팸이에요 + OBSCENE("OBSCENE"), // 음란성 컨텐츠를 담고있어요 + PERSONAL_INFO("PERSONAL_INFO"), // 개인정보를 노출하고 있어요 + INTELLECTUAL_PROPERTY("INTELLECTUAL_PROPERTY"), // 지식재산권을 침해해요 + VIOLENCE("VIOLENCE"), // 혐오/폭력 컨텐츠를 담고 있어요 + ILLEGAL_INFO("ILLEGAL_INFO"), // 불법 정보를 포함하고 있어요 + FRAUD("FRAUD"), // 사기 또는 피싱성 링크를 포함하고 있어요 + ETC("ETC"); // 기타 @JsonValue private String value; diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java index 533d97eb..2534f4eb 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java @@ -39,4 +39,8 @@ public void deleteAllByArchivingIdIn(List archivingIds) { public void deleteAllByUser(User user) { scrapRepository.deleteAllByUser(user); } + + public boolean existsByUserAndArchivingId(User user, Long archivingId) { + return scrapRepository.existsByUserAndArchivingId(user, archivingId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java b/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java index 4ccfba30..7600377c 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java @@ -15,4 +15,6 @@ public interface ScrapRepository extends JpaRepository { void deleteAllByArchivingIdIn(List archivingId); void deleteAllByUser(User user); + + boolean existsByUserAndArchivingId(User user, Long archivingId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/validator/ScrapValidator.java b/Domain/src/main/java/allchive/server/domain/domains/user/validator/ScrapValidator.java index 153ee1e7..1ab5a89f 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/validator/ScrapValidator.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/validator/ScrapValidator.java @@ -16,13 +16,13 @@ public class ScrapValidator { public void validateExistScrap(Long userId, Long archivingId) { User user = userAdaptor.findById(userId); - if (isScrapExist(user, archivingId)) { - throw AlreadyExistScrapException.EXCEPTION; - } + scrapAdaptor.findByUserAndArchivingId(user, archivingId); } - private Boolean isScrapExist(User user, Long archivingId) { - scrapAdaptor.findByUserAndArchivingId(user, archivingId); - return Boolean.TRUE; + public void validateNotExistScrap(Long userId, Long archivingId) { + User user = userAdaptor.findById(userId); + if (scrapAdaptor.existsByUserAndArchivingId(user, archivingId)) { + throw AlreadyExistScrapException.EXCEPTION; + } } }