Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
delete file 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Feb 15, 2024
1 parent d420f61 commit 3fbdca5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<Void> deleteById(String id) {
return fileRepository.deleteById(UUID.fromString(id));
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}")
Expand All @@ -25,7 +28,7 @@ public Mono<Void> deleteObject(DeleteFileRequest request) {
.build())
.map(s3AsyncClient::deleteObject)
.flatMap(Mono::fromFuture)
.then();
.flatMap(deleteObjectResponse -> deleteFile.deleteById(request.key()));
}

}

0 comments on commit 3fbdca5

Please sign in to comment.