diff --git a/Api/src/main/java/allchive/server/api/image/controller/ImageController.java b/Api/src/main/java/allchive/server/api/image/controller/ImageController.java index 8077a4d4..d643c3e4 100644 --- a/Api/src/main/java/allchive/server/api/image/controller/ImageController.java +++ b/Api/src/main/java/allchive/server/api/image/controller/ImageController.java @@ -4,7 +4,7 @@ import allchive.server.api.config.security.SecurityUtil; import allchive.server.api.image.model.dto.response.ImageUrlResponse; import allchive.server.infrastructure.s3.PresignedType; -import allchive.server.infrastructure.s3.S3PresignedUrlService; +import allchive.server.infrastructure.s3.service.S3PresignedUrlService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; diff --git a/Api/src/main/java/allchive/server/api/recycle/service/ClearDeletedObjectUseCase.java b/Api/src/main/java/allchive/server/api/recycle/service/ClearDeletedObjectUseCase.java index 453ecc90..85097dbe 100644 --- a/Api/src/main/java/allchive/server/api/recycle/service/ClearDeletedObjectUseCase.java +++ b/Api/src/main/java/allchive/server/api/recycle/service/ClearDeletedObjectUseCase.java @@ -8,12 +8,15 @@ import allchive.server.domain.domains.archiving.validator.ArchivingValidator; import allchive.server.domain.domains.content.adaptor.ContentAdaptor; import allchive.server.domain.domains.content.domain.Content; +import allchive.server.domain.domains.content.domain.enums.ContentType; import allchive.server.domain.domains.content.service.ContentDomainService; import allchive.server.domain.domains.content.service.ContentTagGroupDomainService; import allchive.server.domain.domains.content.validator.ContentValidator; import allchive.server.domain.domains.recycle.service.RecycleDomainService; import allchive.server.domain.domains.recycle.validator.RecycleValidator; +import allchive.server.domain.domains.report.service.ReportDomainService; import allchive.server.domain.domains.user.service.ScrapDomainService; +import allchive.server.infrastructure.s3.service.S3DeleteObjectService; import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; @@ -31,15 +34,36 @@ public class ClearDeletedObjectUseCase { private final ArchivingDomainService archivingDomainService; private final ContentDomainService contentDomainService; private final RecycleDomainService recycleDomainService; + private final ReportDomainService reportDomainService; + private final S3DeleteObjectService s3DeleteObjectService; - // TODO: report 지우기 @Transactional public void execute(ClearDeletedObjectRequest request) { Long userId = SecurityUtil.getCurrentUserId(); - recycleValidator.validateExist(request.getArchivingIds(), request.getContentIds(), userId); - archivingValidator.verifyUserInIdList(userId, request.getArchivingIds()); - contentValidator.verifyUserInIdList(userId, request.getContentIds()); + validateExecution(userId, request); List contents = contentAdaptor.findAllByArchivingIds(request.getArchivingIds()); + List contentsId = getContentsId(contents, request); + scrapDomainService.deleteAllByArchivingIdIn(request.getArchivingIds()); + contentTagGroupDomainService.deleteByContentIn(contents); + contentDomainService.deleteAllById(contentsId); + archivingDomainService.deleteAllById(request.getArchivingIds()); + recycleDomainService.deleteAllByUserIdAndArchivingIdInOrUserIdAndContentIdIn( + request.getArchivingIds(), request.getContentIds(), userId); + reportDomainService.deleteAllByArchivingIdInOrContentIdIn( + request.getArchivingIds(), request.getContentIds()); + deleteS3Object(contents); + } + + private void deleteS3Object(List contents) { + List imageKeys = + contents.stream() + .filter(content -> content.getContentType().equals(ContentType.IMAGE)) + .map(Content::getImageUrl) + .toList(); + s3DeleteObjectService.deleteS3Object(imageKeys); + } + + private List getContentsId(List contents, ClearDeletedObjectRequest request) { List contentsId = contents.stream().map(Content::getId).toList(); if (!request.getContentIds().isEmpty()) { if (contentsId.isEmpty()) { @@ -47,11 +71,12 @@ public void execute(ClearDeletedObjectRequest request) { } contentsId.addAll(request.getContentIds()); } - scrapDomainService.deleteAllByArchivingIdIn(request.getArchivingIds()); - contentTagGroupDomainService.deleteByContentIn(contents); - contentDomainService.deleteAllById(contentsId); - archivingDomainService.deleteAllById(request.getArchivingIds()); - recycleDomainService.deleteAllByUserIdAndArchivingIdOrUserIdAndContentId( - request.getArchivingIds(), request.getContentIds(), userId); + return contentsId; + } + + private void validateExecution(Long userId, ClearDeletedObjectRequest request) { + recycleValidator.validateExist(request.getArchivingIds(), request.getContentIds(), userId); + archivingValidator.verifyUserInIdList(userId, request.getArchivingIds()); + contentValidator.verifyUserInIdList(userId, request.getContentIds()); } } diff --git a/Api/src/main/java/allchive/server/api/recycle/service/ClearOldDeletedObjectUseCase.java b/Api/src/main/java/allchive/server/api/recycle/service/ClearOldDeletedObjectUseCase.java index 4e9ffea5..c673c9aa 100644 --- a/Api/src/main/java/allchive/server/api/recycle/service/ClearOldDeletedObjectUseCase.java +++ b/Api/src/main/java/allchive/server/api/recycle/service/ClearOldDeletedObjectUseCase.java @@ -5,13 +5,16 @@ import allchive.server.domain.domains.archiving.service.ArchivingDomainService; import allchive.server.domain.domains.content.adaptor.ContentAdaptor; import allchive.server.domain.domains.content.domain.Content; +import allchive.server.domain.domains.content.domain.enums.ContentType; import allchive.server.domain.domains.content.service.ContentDomainService; import allchive.server.domain.domains.content.service.ContentTagGroupDomainService; import allchive.server.domain.domains.recycle.adaptor.RecycleAdaptor; import allchive.server.domain.domains.recycle.domain.Recycle; import allchive.server.domain.domains.recycle.domain.enums.RecycleType; import allchive.server.domain.domains.recycle.service.RecycleDomainService; +import allchive.server.domain.domains.report.service.ReportDomainService; import allchive.server.domain.domains.user.service.ScrapDomainService; +import allchive.server.infrastructure.s3.service.S3DeleteObjectService; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -31,21 +34,46 @@ public class ClearOldDeletedObjectUseCase { private final ArchivingDomainService archivingDomainService; private final ContentDomainService contentDomainService; private final RecycleDomainService recycleDomainService; + private final ReportDomainService reportDomainService; + private final S3DeleteObjectService s3DeleteObjectService; /** 삭제 후 30일 지난 항목 제거 스케쥴러 매일 02:30에 수행 */ - // TODO: s3 asset 삭제 @Scheduled(cron = "0 30 2 * * *") @Transactional public void executeSchedule() { log.info("scheduler on"); LocalDateTime deleteStandard = LocalDateTime.now().minusDays(30); List recycles = recycleAdaptor.findAllByDeletedAtBefore(deleteStandard); + List archivingIds = getArchivingIds(recycles); + List contents = contentAdaptor.findAllByArchivingIds(archivingIds); + List contentIds = getContentsId(recycles, contents); + scrapDomainService.deleteAllByArchivingIdIn(archivingIds); + contentTagGroupDomainService.deleteByContentIn(contents); + contentDomainService.deleteAllById(contentIds); + archivingDomainService.deleteAllById(archivingIds); + recycleDomainService.deleteAll(recycles); + reportDomainService.deleteAllByArchivingIdInOrContentIdIn(archivingIds, contentIds); + deleteS3Object(contents); + log.info("scheduler off"); + } - List archivingIds = - recycles.stream() - .filter(recycle -> recycle.getRecycleType().equals(RecycleType.ARCHIVING)) - .map(Recycle::getArchivingId) + private void deleteS3Object(List contents) { + List imageKeys = + contents.stream() + .filter(content -> content.getContentType().equals(ContentType.IMAGE)) + .map(Content::getImageUrl) .toList(); + s3DeleteObjectService.deleteS3Object(imageKeys); + } + + private List getArchivingIds(List recycles) { + return recycles.stream() + .filter(recycle -> recycle.getRecycleType().equals(RecycleType.ARCHIVING)) + .map(Recycle::getArchivingId) + .toList(); + } + + private List getContentsId(List recycles, List contents) { List contentIds = recycles.stream() .filter(recycle -> recycle.getRecycleType().equals(RecycleType.CONTENT)) @@ -55,16 +83,9 @@ public void executeSchedule() { if (contentIds.isEmpty()) { contentIds = new ArrayList<>(); } - List contents = contentAdaptor.findAllByArchivingIds(archivingIds); for (Content content : contents) { contentIds.add(content.getId()); } - - scrapDomainService.deleteAllByArchivingIdIn(archivingIds); - contentTagGroupDomainService.deleteByContentIn(contents); - contentDomainService.deleteAllById(contentIds); - archivingDomainService.deleteAllById(archivingIds); - recycleDomainService.deleteAll(recycles); - log.info("scheduler off"); + return contentIds; } } diff --git a/Api/src/main/java/allchive/server/api/recycle/service/GetDeletedObjectUseCase.java b/Api/src/main/java/allchive/server/api/recycle/service/GetDeletedObjectUseCase.java index 733b5dff..f966f56f 100644 --- a/Api/src/main/java/allchive/server/api/recycle/service/GetDeletedObjectUseCase.java +++ b/Api/src/main/java/allchive/server/api/recycle/service/GetDeletedObjectUseCase.java @@ -31,21 +31,29 @@ public class GetDeletedObjectUseCase { public DeletedObjectResponse execute() { Long userId = SecurityUtil.getCurrentUserId(); List recycles = recycleAdaptor.findAllByUserId(userId); + List archivings = getArchivings(recycles); + List contents = getContents(recycles); + List contentTagGroups = + contentTagGroupAdaptor.queryContentTagGroupByContentIn(contents); + return recycleMapper.toDeletedObjectResponse( + archivings, userId, contents, contentTagGroups); + } + + private List getArchivings(List recycles) { List archivingIds = recycles.stream() .filter(recycle -> recycle.getRecycleType().equals(RecycleType.ARCHIVING)) .map(Recycle::getArchivingId) .toList(); + return archivingAdaptor.findAllByIdIn(archivingIds); + } + + private List getContents(List recycles) { List contentIds = recycles.stream() .filter(recycle -> recycle.getRecycleType().equals(RecycleType.CONTENT)) .map(Recycle::getContentId) .toList(); - List archivings = archivingAdaptor.findAllByIdIn(archivingIds); - List contents = contentAdaptor.findAllByIdIn(contentIds); - List contentTagGroups = - contentTagGroupAdaptor.queryContentTagGroupByContentIn(contents); - return recycleMapper.toDeletedObjectResponse( - archivings, userId, contents, contentTagGroups); + return contentAdaptor.findAllByIdIn(contentIds); } } diff --git a/Api/src/main/java/allchive/server/api/recycle/service/RestoreDeletedObjectUseCase.java b/Api/src/main/java/allchive/server/api/recycle/service/RestoreDeletedObjectUseCase.java index aa77aa15..8bbe8218 100644 --- a/Api/src/main/java/allchive/server/api/recycle/service/RestoreDeletedObjectUseCase.java +++ b/Api/src/main/java/allchive/server/api/recycle/service/RestoreDeletedObjectUseCase.java @@ -26,12 +26,16 @@ public class RestoreDeletedObjectUseCase { @Transactional public void execute(RestoreDeletedObjectRequest request) { Long userId = SecurityUtil.getCurrentUserId(); + validateExecution(request, userId); + archivingDomainService.restoreByIdIn(request.getArchivingIds()); + contentDomainService.restoreByIdIn(request.getContentIds()); + recycleDomainService.deleteAllByUserIdAndArchivingIdInOrUserIdAndContentIdIn( + request.getArchivingIds(), request.getContentIds(), userId); + } + + private void validateExecution(RestoreDeletedObjectRequest request, Long userId) { recycleValidator.validateExist(request.getArchivingIds(), request.getContentIds(), userId); archivingValidator.validateExistInIdList(request.getArchivingIds()); contentValidator.validateExistInIdList(request.getContentIds()); - archivingDomainService.restoreInIdList(request.getArchivingIds()); - contentDomainService.restoreInIdList(request.getContentIds()); - recycleDomainService.deleteAllByUserIdAndArchivingIdOrUserIdAndContentId( - request.getArchivingIds(), request.getContentIds(), userId); } } diff --git a/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java b/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java index 1ade62da..027c58ae 100644 --- a/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java +++ b/Core/src/main/java/allchive/server/core/error/GlobalErrorCode.java @@ -26,6 +26,9 @@ public enum GlobalErrorCode implements BaseErrorCode { EXPIRED_TOKEN(UNAUTHORIZED, "AUTH_401_3", "만료된 엑세스 토큰입니다"), EXPIRED_REFRESH_TOKEN(UNAUTHORIZED, "AUTH_403_1", "인증 시간이 만료되었습니다. 재 로그인 해주세요."), + /** s3 오류 */ + S3_OBJECT_NOT_FOUND(BAD_REQUEST, "S3_500_1", "s3 객체가 존재하지 않습니다."), + /** Feign Client 오류 */ OTHER_SERVER_BAD_REQUEST(BAD_REQUEST, "FEIGN_400_1", "Other server bad request"), OTHER_SERVER_UNAUTHORIZED(BAD_REQUEST, "FEIGN_400_2", "Other server unauthorized"), diff --git a/Core/src/main/java/allchive/server/core/error/exception/S3ObjectNotFoundException.java b/Core/src/main/java/allchive/server/core/error/exception/S3ObjectNotFoundException.java new file mode 100644 index 00000000..9dd31860 --- /dev/null +++ b/Core/src/main/java/allchive/server/core/error/exception/S3ObjectNotFoundException.java @@ -0,0 +1,14 @@ +package allchive.server.core.error.exception; + + +import allchive.server.core.error.BaseErrorException; +import allchive.server.core.error.GlobalErrorCode; + +public class S3ObjectNotFoundException extends BaseErrorException { + + public static final BaseErrorException EXCEPTION = new S3ObjectNotFoundException(); + + private S3ObjectNotFoundException() { + super(GlobalErrorCode.S3_OBJECT_NOT_FOUND); + } +} diff --git a/Domain/src/main/java/allchive/server/domain/domains/archiving/service/ArchivingDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/archiving/service/ArchivingDomainService.java index f45bea0b..e55eaf9e 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/archiving/service/ArchivingDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/archiving/service/ArchivingDomainService.java @@ -50,7 +50,7 @@ public void softDeleteById(Long archivingId) { archivingAdaptor.save(archiving); } - public void restoreInIdList(List archivingIds) { + public void restoreByIdIn(List archivingIds) { List archivings = archivingAdaptor.findAllByIdIn(archivingIds); archivings.forEach(Archiving::restore); archivingAdaptor.saveAll(archivings); diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java index 47c902ed..b8e639ab 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java @@ -23,7 +23,7 @@ public void softDeleteById(Long contentId) { save(content); } - public void restoreInIdList(List contentIds) { + public void restoreByIdIn(List contentIds) { List contentList = contentAdaptor.findAllByIdIn(contentIds); contentList.forEach(Content::restore); contentAdaptor.saveAll(contentList); diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java index b2055e21..3a1a585a 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java @@ -17,9 +17,9 @@ public void save(Recycle recycle) { recycleRepository.save(recycle); } - public List queryRecycleByUserIdInArchivingIdListAndContentIdList( + public List queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn( List archivingIds, List contentIds, Long userId) { - return recycleRepository.queryRecycleByUserIdInArchivingIdListAndContentIdList( + return recycleRepository.queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn( archivingIds, contentIds, userId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepository.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepository.java index 59d537b8..b52c9e50 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepository.java @@ -5,6 +5,6 @@ import java.util.List; public interface RecycleCustomRepository { - List queryRecycleByUserIdInArchivingIdListAndContentIdList( + List queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn( List archivingIds, List contentIds, Long userId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepositoryImpl.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepositoryImpl.java index 682ce446..4c6a0cff 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepositoryImpl.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleCustomRepositoryImpl.java @@ -15,7 +15,7 @@ public class RecycleCustomRepositoryImpl implements RecycleCustomRepository { private final JPAQueryFactory queryFactory; @Override - public List queryRecycleByUserIdInArchivingIdListAndContentIdList( + public List queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn( List archivingIds, List contentIds, Long userId) { return queryFactory .selectFrom(recycle) diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java index 9763eae5..318089de 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java @@ -16,10 +16,10 @@ public void save(Recycle recycle) { recycleAdaptor.save(recycle); } - public void deleteAllByUserIdAndArchivingIdOrUserIdAndContentId( + public void deleteAllByUserIdAndArchivingIdInOrUserIdAndContentIdIn( List archivingIds, List contentIds, Long userId) { List recycleList = - recycleAdaptor.queryRecycleByUserIdInArchivingIdListAndContentIdList( + recycleAdaptor.queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn( archivingIds, contentIds, userId); recycleAdaptor.deleteAll(recycleList); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/validator/RecycleValidator.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/validator/RecycleValidator.java index 18c7e55e..385cd26a 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/validator/RecycleValidator.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/validator/RecycleValidator.java @@ -17,7 +17,7 @@ public class RecycleValidator { public void validateExist(List archivingIds, List contentIds, Long userId) { List recycleList = - recycleAdaptor.queryRecycleByUserIdInArchivingIdListAndContentIdList( + recycleAdaptor.queryRecycleByUserIdAndArchivingIdInOrUserIdAndContentIdIn( archivingIds, contentIds, userId); Long archivingCnt = recycleList.stream() diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java index 16284ef0..6bab700e 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java @@ -4,6 +4,7 @@ import allchive.server.core.annotation.Adaptor; import allchive.server.domain.domains.report.domain.Report; import allchive.server.domain.domains.report.repository.ReportRepository; +import java.util.List; import lombok.RequiredArgsConstructor; @Adaptor @@ -26,4 +27,9 @@ public Boolean queryReportExistByUserIdAndArchivingId(Long userId, Long archivin public void deleteAllByReportedUserId(Long userId) { reportRepository.deleteAllByReportedUserId(userId); } + + public void deleteAllByArchivingIdInOrContentIdIn( + List archivingIds, List contentIds) { + reportRepository.queryDeleteAllByArchivingIdInOrContentIdIn(archivingIds, contentIds); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepository.java b/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepository.java index 8c7a1f08..51df9782 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepository.java @@ -1,7 +1,12 @@ package allchive.server.domain.domains.report.repository; + +import java.util.List; + public interface ReportCustomRepository { Boolean queryReportExistByUserIdAndContentId(Long userId, Long contentId); Boolean queryReportExistByUserIdAndArchivingId(Long userId, Long archivingId); + + void queryDeleteAllByArchivingIdInOrContentIdIn(List archivingIds, List contentIds); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepositoryImpl.java b/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepositoryImpl.java index d1ea0a1c..706de473 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepositoryImpl.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportCustomRepositoryImpl.java @@ -4,6 +4,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -32,6 +33,12 @@ public Boolean queryReportExistByUserIdAndArchivingId(Long userId, Long archivin return fetchOne != null; } + @Override + public void queryDeleteAllByArchivingIdInOrContentIdIn( + List archivingIds, List contentIds) { + queryFactory.delete(report).where(archivingIdInOrContentIdIn(archivingIds, contentIds)); + } + private BooleanExpression userIdEq(Long userId) { return report.userId.eq(userId); } @@ -43,4 +50,9 @@ private BooleanExpression contentIdEq(Long contentId) { private BooleanExpression archivingIdEq(Long archivingId) { return report.archivingId.eq(archivingId); } + + private BooleanExpression archivingIdInOrContentIdIn( + List archivingIds, List contentIds) { + return report.archivingId.in(archivingIds).or(report.contentId.in(contentIds)); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java index 00a0e4ad..957f59e9 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java @@ -4,6 +4,7 @@ import allchive.server.core.annotation.DomainService; import allchive.server.domain.domains.report.adaptor.ReportAdaptor; import allchive.server.domain.domains.report.domain.Report; +import java.util.List; import lombok.RequiredArgsConstructor; @DomainService @@ -18,4 +19,9 @@ public void save(Report report) { public void deleteAllByReportedUserId(Long userId) { reportAdaptor.deleteAllByReportedUserId(userId); } + + public void deleteAllByArchivingIdInOrContentIdIn( + List archivingIds, List contentIds) { + reportAdaptor.deleteAllByArchivingIdInOrContentIdIn(archivingIds, contentIds); + } } diff --git a/Infrastructure/src/main/java/allchive/server/infrastructure/s3/service/S3DeleteObjectService.java b/Infrastructure/src/main/java/allchive/server/infrastructure/s3/service/S3DeleteObjectService.java new file mode 100644 index 00000000..c8a2c15d --- /dev/null +++ b/Infrastructure/src/main/java/allchive/server/infrastructure/s3/service/S3DeleteObjectService.java @@ -0,0 +1,32 @@ +package allchive.server.infrastructure.s3.service; + + +import allchive.server.core.error.exception.S3ObjectNotFoundException; +import com.amazonaws.services.s3.AmazonS3; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class S3DeleteObjectService { + private final AmazonS3 amazonS3; + + @Value("${aws.s3.bucket}") + private String bucket; + + public void deleteS3Object(List keys) { + keys.forEach( + key -> { + validateExistObject(key); + amazonS3.deleteObject(bucket, key); + }); + } + + private void validateExistObject(String key) { + if (!amazonS3.doesObjectExist(bucket, key)) { + throw S3ObjectNotFoundException.EXCEPTION; + } + } +} diff --git a/Infrastructure/src/main/java/allchive/server/infrastructure/s3/S3PresignedUrlService.java b/Infrastructure/src/main/java/allchive/server/infrastructure/s3/service/S3PresignedUrlService.java similarity index 93% rename from Infrastructure/src/main/java/allchive/server/infrastructure/s3/S3PresignedUrlService.java rename to Infrastructure/src/main/java/allchive/server/infrastructure/s3/service/S3PresignedUrlService.java index 78211363..c8f1186a 100644 --- a/Infrastructure/src/main/java/allchive/server/infrastructure/s3/S3PresignedUrlService.java +++ b/Infrastructure/src/main/java/allchive/server/infrastructure/s3/service/S3PresignedUrlService.java @@ -1,7 +1,9 @@ -package allchive.server.infrastructure.s3; +package allchive.server.infrastructure.s3.service; import allchive.server.core.error.exception.InternalServerError; +import allchive.server.infrastructure.s3.ImageUrlDto; +import allchive.server.infrastructure.s3.PresignedType; import com.amazonaws.HttpMethod; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.Headers;