Skip to content

Commit

Permalink
feat: S3StroageController Swagger ์ž…๋ ฅ
Browse files Browse the repository at this point in the history
  • Loading branch information
jinno321 committed Sep 19, 2024
1 parent 6b50098 commit fe0e67d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
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 Down Expand Up @@ -28,11 +30,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,23 +52,32 @@ public ResponseEntity<String> uploadPdf(@RequestParam("file") MultipartFile file
}


@Operation(summary = "pdf ์—…๋กœ๋“œ",description = "s3 ์Šคํ† ๋ฆฌ์ง€์— pdf ํŒŒ์ผ์„ ์—…๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.")
@DeleteMapping("/delete-pdf")
public ResponseEntity<Void> deletePdf(@RequestBody DeletePdfRequest request) {
public ResponseEntity<Void> deletePdf(
@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 = "๊ฐœ์ธ์˜ ์ธ์ฆ์„œ๋“ค์„ ๋ชจ๋‘ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ํ˜•์‹ : (ํŽ˜์ด์ง€ - ์„ค๋ช…)")
@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);

}

@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();
Expand All @@ -71,10 +88,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 +108,24 @@ 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

0 comments on commit fe0e67d

Please sign in to comment.