Skip to content

Commit

Permalink
Merge pull request #24 from pjhcsols/BE_J
Browse files Browse the repository at this point in the history
[BE<-BE_J] S3 CRUD ๊ธฐ๋Šฅ ๋ฆฌํŒฉํ† ๋ง ๋ณ‘ํ•ฉ
  • Loading branch information
pjhcsols authored Oct 1, 2024
2 parents 6b50098 + a81d51f commit 773bf40
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 86 deletions.
4 changes: 3 additions & 1 deletion web3-credential-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ dependencies {
testImplementation 'org.assertj:assertj-core:3.20.2'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'software.amazon.awssdk:s3:2.17.84' // ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” AWS SDK ๋ฒ„์ „์— ๋งž๊ฒŒ ๋ณ€๊ฒฝ
implementation 'software.amazon.awssdk:s3:2.17.84'
implementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.31'

//implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'



testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package web3.s3Storage.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -8,12 +10,14 @@
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;

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

@RestController
@RequestMapping("/api/wallets")
Expand All @@ -28,11 +32,17 @@ public S3StorageController(S3StorageService s3StorageService, WalletService wall
this.walletService = walletService;
}

@Operation(summary = "์ธ์ฆ์„œ(pdf) ์—…๋กœ๋“œ",description = "์ธ์ฆ์„œ๋ฅผ ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰,s3 ์Šคํ† ๋ฆฌ์ง€์— pdf ํŒŒ์ผ์„ ์—…๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping("/upload-pdf")
public ResponseEntity<String> uploadPdf(@RequestParam("file") MultipartFile file,
@RequestParam("walletId") Long walletId,
@RequestParam String pdfInfo,
@RequestParam String pdfKey) {
public ResponseEntity<String> uploadPdf(
@Parameter(description = "์—…๋กœ๋“œํ•  pdf ํŒŒ์ผ",required = true)
@RequestParam("file") MultipartFile file,
@Parameter(description = "์‚ฌ์šฉ์ž ์ง€๊ฐ‘ID",required = true)
@RequestParam("walletId") Long walletId,
@Parameter(description = "pdf ์ •๋ณด",required = true)
@RequestParam String pdfInfo,
@Parameter(description = "pdf ํ‚ค๊ฐ’",required = true)
@RequestParam String pdfKey) {
Wallet wallet = walletService.getWalletById(walletId).orElseThrow(()-> new EntityNotFoundException("Wallet does not exist"));
try {
String pdfUrl = s3StorageService.uploadPdf(file, wallet,pdfInfo,pdfKey);
Expand All @@ -44,25 +54,49 @@ public ResponseEntity<String> uploadPdf(@RequestParam("file") MultipartFile file
}


@Operation(summary = "๋ชจ๋“  ์ธ์ฆ์„œ ์‚ญ์ œ(์ง€๊ฐ‘ ์‚ญ์ œ)",description = "๋ชจ๋“  ์ธ์ฆ์„œ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰,s3 ์Šคํ† ๋ฆฌ์ง€์— pdf ํŒŒ์ผ์„ ๋ชจ๋‘ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.")
@DeleteMapping("/delete-pdf")
public ResponseEntity<Void> deletePdf(@RequestBody DeletePdfRequest request) {
public ResponseEntity<Void> deleteWallet(
@Parameter(description = "์ง€์šธ pdf ํŒŒ์ผ ๊ฒฝ๋กœ ๊ด€๋ จ Dto",required = true)
@RequestBody DeletePdfRequest request) {
String urlToDelete = request.getUrlToDelete();
System.out.println("urlToDelete = " + urlToDelete);
s3StorageService.deletePdf(urlToDelete);
return ResponseEntity.noContent().build();
}

@Operation(summary = "ํŠน์ • ์ธ์ฆ์„œ ์‚ญ์ œ",description = "์ง€๊ฐ‘์—์„œ ํŠน์ • ์ธ์ฆ์„œ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰,S3 ์Šคํ† ๋ฆฌ์ง€์— pdf ํŒŒ์ผ์—์„œ ํŠน์ • ํŽ˜์ด์ง€๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.")
@PatchMapping ("/delete-one")
public ResponseEntity<Void> deleteCertForPage(
@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();
}

@Operation(summary = "์ธ์ฆ์„œ ๋ฆฌ์ŠคํŠธ ์–ป๊ธฐ",description = "๊ฐœ์ธ์˜ ์ธ์ฆ์„œ๋“ค์„ ๋ชจ๋‘ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ํ˜•์‹ : (ํŽ˜์ด์ง€ - ์„ค๋ช…)")
@GetMapping("/certs")
public ResponseEntity<HashMap<String,String>> getCertList(@RequestParam("pdfUrl") String pdfUrl) {
public ResponseEntity<HashMap<String,String>> getCertList(
@Parameter(description = "pdf ํŒŒ์ผ ๊ฒฝ๋กœ",required = true)
@RequestParam("pdfUrl") String pdfUrl) {
HashMap<String, String> certList = s3StorageService.getCertList(pdfUrl);
return ResponseEntity.ok().body(certList);
HashMap<String, String> decodedMetadata = s3StorageService.decodeMetadata(certList);
//return ResponseEntity.ok().body(certList);
return ResponseEntity.ok().body(decodedMetadata);

}

@Operation(summary = "์ธ์ฆ์„œ ๋ฆฌ์ŠคํŠธ ์–ป๊ธฐ - pdf ํ˜•์‹",description = "๊ฐœ์ธ์˜ ์ธ์ฆ์„œ๋“ค์„ pdf์˜ ํ˜•์‹์œผ๋กœ ๋ชจ๋‘ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.")
@GetMapping("/get-pdf")
public ResponseEntity<byte[]> getPdf(@RequestParam("pdfUrl") String pdfUrl) {
public ResponseEntity<byte[]> getPdf(
@Parameter(description = "pdf ํŒŒ์ผ ๊ฒฝ๋กœ",required = true)
@RequestParam("pdfUrl") String pdfUrl) {
try {
System.out.println("pdfUrl = " + pdfUrl);
byte[] pdfData = s3StorageService.getPdf(pdfUrl).readAllBytes();
return ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(pdfData);
} catch (IOException e) {
Expand All @@ -71,10 +105,15 @@ public ResponseEntity<byte[]> getPdf(@RequestParam("pdfUrl") String pdfUrl) {
}
}

@Operation(summary = "pdf ๋Œ€์ฒดํ•˜๊ธฐ",description = "์›ํ•˜๋Š” ํŽ˜์ด์ง€๋ฅผ ์›ํ•˜๋Š” pdf๋กœ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping("/replace-pdf")
public ResponseEntity<String> replacePdf(@RequestParam("file") MultipartFile file,
@RequestParam("page") int page,
@RequestParam("walletId") Long walletId) {
public ResponseEntity<String> replacePdf(
@Parameter(description = "pdf ํŒŒ์ผ",required = true)
@RequestParam("file") MultipartFile file,
@Parameter(description = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ",required = true)
@RequestParam("page") int page,
@Parameter(description = "์‚ฌ์šฉ์ž ์ง€๊ฐ‘ID",required = true)
@RequestParam("walletId") Long walletId) {
try {
System.out.println("file = " + file);
Wallet wallet = walletService.getWalletById(walletId).orElseThrow(()-> new EntityNotFoundException("Wallet does not exist"));
Expand All @@ -86,16 +125,25 @@ public ResponseEntity<String> replacePdf(@RequestParam("file") MultipartFile fil
}
}

@Operation(summary = "๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์–ป๊ธฐ",description = "์‚ฌ์šฉ์ž์˜ ๋ชจ๋“  ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ์˜ ์ •๋ณด๋“ค์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.")
@GetMapping("/get-metadata")
public ResponseEntity<String> getMetadata(@RequestParam String pdfUrl,
@RequestParam int page) {
public ResponseEntity<String> getMetadata(
@Parameter(description = "pdf ํŒŒ์ผ ๊ฒฝ๋กœ",required = true)
@RequestParam String pdfUrl,
@Parameter(description = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ",required = true)
@RequestParam int page) {
String metadata = s3StorageService.getMetadataForPage(pdfUrl, page);

return ResponseEntity.ok().body(metadata);
}

@Operation(summary = "pdf key๊ฐ’ ์–ป๊ธฐ",description = "์‚ฌ์šฉ์ž์˜ pdf์—์„œ ์›ํ•˜๋Š” ํŽ˜์ด์ง€์˜ key๊ฐ’์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.")
@GetMapping("/get-pdfkey")
public ResponseEntity<String> getPdfKey(@RequestParam String pdfUrl,
@RequestParam int page) {
public ResponseEntity<String> getPdfKey(
@Parameter(description = "pdf ํŒŒ์ผ ๊ฒฝ๋กœ",required = true)
@RequestParam String pdfUrl,
@Parameter(description = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ",required = true)
@RequestParam int page) {
String metadata = s3StorageService.getPdfKeyForPage(pdfUrl, page);
return ResponseEntity.ok().body(metadata);
}
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;
}
}
Loading

0 comments on commit 773bf40

Please sign in to comment.