Skip to content

Commit

Permalink
#21 Refactor: checkPageExist 메서드 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
jinno321 committed Sep 23, 2024
1 parent d282017 commit 6fa0c78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,15 @@ public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOExc
int pageIndexToRemove = pageNumberToRemove - 1;

// 페이지가 존재하는지 확인
if (pageIndexToRemove < 0 || pageIndexToRemove >= totalPages) {
throw new IllegalArgumentException("Page number out of range: " + pageNumberToRemove);
}
checkPageExist(pageIndexToRemove < 0, pageIndexToRemove >= totalPages, "Page number out of range: " + pageNumberToRemove);

byte[] frontPart = createPdfBytesPart(originalDocument, 0, pageIndexToRemove);
byte[] backPart = createPdfBytesPart(originalDocument, pageIndexToRemove + 1, originalDocument.getNumberOfPages());

// PDF 합치기
byte[] finalPdfBytes = mergePdfs(frontPart,backPart);
HashMap<String, String> metadata = getPdfMetadata(fileName);

log.info("metadata = {}",metadata);
metadata.remove("page-" + pageNumberToRemove);

// 최종 PDF를 S3에 업로드
Expand All @@ -366,6 +364,12 @@ public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOExc

}

private static void checkPageExist(boolean pageIndexToRemove, boolean pageIndexToRemove1, String pageNumberToRemove) {
if (pageIndexToRemove || pageIndexToRemove1) {
throw new IllegalArgumentException(pageNumberToRemove);
}
}

public ResponseInputStream<GetObjectResponse> getPdf(String pdfUrl) {
String key = extractKeyFromUrl(pdfUrl);
GetObjectRequest getObjectRequest = GetObjectRequest.builder()
Expand Down

0 comments on commit 6fa0c78

Please sign in to comment.