From 3fbdca5c787887e4ac3f35a69555c44b835303d7 Mon Sep 17 00:00:00 2001 From: 101 Date: Thu, 15 Feb 2024 13:51:32 +0900 Subject: [PATCH] =?UTF-8?q?delete=20file=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/model/component/DeleteFile.java | 21 +++++++++++++++++++ .../infra/s3/service/S3DeleteObject.java | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/daemawiki/domain/file/model/component/DeleteFile.java diff --git a/src/main/java/com/example/daemawiki/domain/file/model/component/DeleteFile.java b/src/main/java/com/example/daemawiki/domain/file/model/component/DeleteFile.java new file mode 100644 index 00000000..43321f18 --- /dev/null +++ b/src/main/java/com/example/daemawiki/domain/file/model/component/DeleteFile.java @@ -0,0 +1,21 @@ +package com.example.daemawiki.domain.file.model.component; + +import com.example.daemawiki.domain.file.repository.FileRepository; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +import java.util.UUID; + +@Component +public class DeleteFile { + private final FileRepository fileRepository; + + public DeleteFile(FileRepository fileRepository) { + this.fileRepository = fileRepository; + } + + public Mono deleteById(String id) { + return fileRepository.deleteById(UUID.fromString(id)); + } + +} diff --git a/src/main/java/com/example/daemawiki/infra/s3/service/S3DeleteObject.java b/src/main/java/com/example/daemawiki/infra/s3/service/S3DeleteObject.java index 8a9fbde4..01c3ad4f 100644 --- a/src/main/java/com/example/daemawiki/infra/s3/service/S3DeleteObject.java +++ b/src/main/java/com/example/daemawiki/infra/s3/service/S3DeleteObject.java @@ -1,6 +1,7 @@ package com.example.daemawiki.infra.s3.service; import com.example.daemawiki.domain.file.dto.DeleteFileRequest; +import com.example.daemawiki.domain.file.model.component.DeleteFile; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -10,9 +11,11 @@ @Service public class S3DeleteObject { private final S3AsyncClient s3AsyncClient; + private final DeleteFile deleteFile; - public S3DeleteObject(S3AsyncClient s3AsyncClient) { + public S3DeleteObject(S3AsyncClient s3AsyncClient, DeleteFile deleteFile) { this.s3AsyncClient = s3AsyncClient; + this.deleteFile = deleteFile; } @Value("${cloud.aws.s3.bucket}") @@ -25,7 +28,7 @@ public Mono deleteObject(DeleteFileRequest request) { .build()) .map(s3AsyncClient::deleteObject) .flatMap(Mono::fromFuture) - .then(); + .flatMap(deleteObjectResponse -> deleteFile.deleteById(request.key())); } }