Skip to content

Commit

Permalink
#21 feat: 특정 인증서(pdf) 삭제시 필요한 dto 생성 및 로직 테스트 - 메타데이터 버그 존재
Browse files Browse the repository at this point in the history
  • Loading branch information
jinno321 committed Sep 22, 2024
1 parent f731ff8 commit d282017
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import web3.domain.wallet.Wallet;
import web3.s3Storage.dto.DeleteCertRequest;
import web3.s3Storage.dto.DeletePdfRequest;
import web3.s3Storage.service.S3StorageService;
import web3.service.wallet.WalletService;
Expand Down Expand Up @@ -64,12 +65,14 @@ public ResponseEntity<Void> deleteWallet(
}

@Operation(summary = "특정 인증서 삭제",description = "지갑에서 특정 인증서를 삭제합니다. 즉,S3 스토리지에 pdf 파일에서 특정 페이지를 삭제합니다.")
@DeleteMapping("/delete-onepdf")
@PatchMapping ("/delete-one")
public ResponseEntity<Void> deleteCertForPage(
@Parameter(description = "지울 지갑 ID",required = true)
@RequestBody Long walletId,
@Parameter(description = "지울 페이지 번호",required = true)
@RequestBody int page) throws IOException {
@Parameter(description = "walletId와 삭제할 page가 담긴 Dto",required = true)
@RequestBody DeleteCertRequest request
) throws IOException {
System.out.println("request = " + request);
Long walletId = request.getWalletId();
int page = request.getPage();
Wallet wallet = walletService.getWalletById(walletId).orElseThrow(()-> new EntityNotFoundException("Wallet does not exist"));
s3StorageService.deletePdfForPage(wallet,page);
return ResponseEntity.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package web3.s3Storage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
public class DeleteCertRequest {

private Long walletId;
private int page;

public void setWalletId(Long walletId) {
this.walletId = walletId;
}

public void setPage(int page) {
this.page = page;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.core.sync.RequestBody;
Expand Down Expand Up @@ -327,6 +328,7 @@ public void deletePdf(String urlToDelete) {
}
}

@Transactional
public void deletePdfForPage(Wallet wallet, int pageNumberToRemove) throws IOException {
String pdfUrl = wallet.getPdfUrl();
byte[] originalPdfBytes = getPdf(pdfUrl).readAllBytes();
Expand Down

0 comments on commit d282017

Please sign in to comment.