Skip to content

Commit

Permalink
#21 Delete : 불필요한 메소드 삭제 (uploadCert)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinno321 committed Oct 10, 2024
1 parent 165791f commit b06e2ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import web3.exception.wallet.WalletAlreadyExistsException;
import web3.exception.wallet.WalletPrivateKeyNotEqualsException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package web3.exception.S3;

import java.io.IOException;

public class GetFileException extends IOException {

public GetFileException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.*;
import web3.domain.wallet.Wallet;
import web3.exception.S3.GetFileException;
import web3.exception.S3.S3UploadException;
import web3.properties.S3Properties;
import web3.repository.wallet.WalletRepository;
Expand All @@ -38,7 +39,7 @@ public S3StorageService(S3Properties s3Properties, WalletRepository walletReposi
}

@Transactional
public String uploadPdf(MultipartFile file, Wallet wallet, String pdfInfo, String pdfKey) {
public String uploadPdf(MultipartFile file, Wallet wallet, String pdfInfo, String pdfKey) throws IOException {
String fileName;
byte[] result;
HashMap<String, String> metadata = new HashMap<>();
Expand Down Expand Up @@ -68,7 +69,7 @@ public String uploadPdf(MultipartFile file, Wallet wallet, String pdfInfo, Strin

log.info("metadata = {}", metadata);

uploadCert(fileName, metadata, result);
uploadToS3(fileName, metadata, result);

wallet.updatePdfUrl(getPdfUrl(fileName));
walletRepository.saveAndFlush(wallet);
Expand All @@ -87,20 +88,8 @@ private byte[] getBytes(String destination) {
}

// 파일 바이트 배열을 가져오는 메서드
private byte[] getFileBytes(MultipartFile file) {
try {
return file.getBytes();
} catch (IOException e) {
throw new RuntimeException("Failed to get file bytes: " + e.getMessage(), e);
}
}

private void uploadCert(String fileName, HashMap<String, String> metadata, byte[] result) {
try {
uploadToS3(fileName, metadata, result);
} catch (S3Exception e) {
throw new RuntimeException("Failed to upload pdf to S3: " + e.getMessage(), e);
}
private byte[] getFileBytes(MultipartFile file) throws IOException {
return file.getBytes();
}

private void uploadToS3(String fileName, HashMap<String, String> metadata, byte[] result) {
Expand Down Expand Up @@ -162,7 +151,8 @@ private byte[] createEmptyPdf(){
}

@Transactional
public String replacePdfPage(Wallet wallet, int pageNumberToRemove, MultipartFile newPdfFile) {
public String replacePdfPage(Wallet wallet, int pageNumberToRemove, MultipartFile newPdfFile) throws IOException{

// 원래 PDF 가져오기
String pdfUrl = wallet.getPdfUrl();
byte[] originalPdfBytes = getOriginalPdfBytes(pdfUrl);
Expand Down Expand Up @@ -193,7 +183,7 @@ public String replacePdfPage(Wallet wallet, int pageNumberToRemove, MultipartFil
HashMap<String, String> metadata = getPdfMetadata(fileName);

// 최종 PDF를 S3에 업로드
uploadCert(fileName, metadata, finalPdfBytes);
uploadToS3(fileName, metadata, finalPdfBytes);

try {
originalDocument.close(); // 리소스 닫기
Expand Down

0 comments on commit b06e2ff

Please sign in to comment.