Skip to content

Commit

Permalink
[CHORE] S3service 기능을 S3Handler로 위임
Browse files Browse the repository at this point in the history
  • Loading branch information
paragon0107 committed Nov 29, 2024
1 parent e768fa0 commit 70aad94
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.tiki.server.external.message.SuccessMessage.PRESIGNED_URL_GET_SUCCESS;
import static com.tiki.server.external.message.SuccessMessage.S3_FILE_DELETE_SUCCESS;

import com.tiki.server.external.service.S3Service;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -17,7 +18,6 @@
import com.tiki.server.external.controller.docs.S3ControllerDocs;
import com.tiki.server.external.dto.request.S3DeleteRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;
import com.tiki.server.external.util.S3Service;

import lombok.RequiredArgsConstructor;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/tiki/server/external/service/S3Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tiki.server.external.service;

import com.tiki.server.external.dto.request.S3DeleteRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;
import com.tiki.server.external.util.S3Handler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class S3Service {

private final S3Handler s3Handler;

public PreSignedUrlResponse getUploadPreSignedUrl(String fileFormat) {
return s3Handler.getUploadPreSignedUrl(fileFormat);
}

public void deleteFile(S3DeleteRequest request) {
s3Handler.deleteFile(request.fileName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@Component
@RequiredArgsConstructor
public class S3Service {
public class S3Handler {

private final AWSConfig awsConfig;

Expand All @@ -46,12 +46,12 @@ public PreSignedUrlResponse getUploadPreSignedUrl(String fileFormat) {
}
}

public void deleteFile(S3DeleteRequest request) {
public void deleteFile(String request) {
try {
S3Client s3Client = awsConfig.getS3Client();
s3Client.deleteObject((DeleteObjectRequest.Builder builder) ->
builder.bucket(bucket)
.key(request.fileName())
.key(request)
.build()
);
} catch (RuntimeException e) {
Expand Down

0 comments on commit 70aad94

Please sign in to comment.