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

Commit

Permalink
생성자를 사용해 DI 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Feb 14, 2024
1 parent 44a957a commit febfbff
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/main/java/com/example/daemawiki/infra/s3/S3Service.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.example.daemawiki.infra.s3;

import com.example.daemawiki.domain.file.dto.DeleteFileRequest;
import com.example.daemawiki.infra.s3.model.FileDetail;
import com.example.daemawiki.infra.s3.model.FileResponse;
import com.example.daemawiki.infra.s3.model.type.FileType;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.MediaType;
Expand All @@ -13,19 +11,24 @@
import reactor.core.publisher.Mono;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.model.*;
import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.CompletedPart;
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.UploadPartRequest;

import java.util.Collections;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class S3Service {
private final S3AsyncClient s3AsyncClient;

public S3Service(S3AsyncClient s3AsyncClient) {
this.s3AsyncClient = s3AsyncClient;
}

@Value("${cloud.aws.s3.bucket}")
private String bucket;

public Mono<FileResponse> uploadObject(FilePart filePart, String fileType) {
String filename = filePart.filename();
Map<String, String> metadata = Map.of("filename", filename);
Expand Down Expand Up @@ -90,14 +93,4 @@ private Mono<FileResponse> createFileResponse(String fileName, MediaType mediaTy
.build());
}

public Mono<Void> deleteObject(DeleteFileRequest request) {
return Mono.just(DeleteObjectRequest.builder()
.bucket(bucket)
.key(request.fileName())
.build())
.map(s3AsyncClient::deleteObject)
.flatMap(Mono::fromFuture)
.then();
}

}

0 comments on commit febfbff

Please sign in to comment.