Skip to content

Commit

Permalink
Merge pull request #30 from pjhcsols/BE_J
Browse files Browse the repository at this point in the history
confirm merge
  • Loading branch information
jinno321 authored Oct 16, 2024
2 parents b743720 + 04c9d7a commit f4c3f41
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 175 deletions.
2 changes: 1 addition & 1 deletion web3-credential-server/build/resources/main/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ VALUES
INSERT INTO wallets (user_id, pdfUrl,privateKey, publicKey, address)
VALUES
(1, 'https://web3credentialbucket.s3.ap-northeast-2.amazonaws.com/ssa_1727764703278_ssa','privateKeyForUser1', 'publicKeyForUser1', 'addressForUser1'),
(2, 'https://web3credentialbucket.s3.ap-northeast-2.amazonaws.com/ssa_1727764703278_ssa','privateKeyForUser2', 'publicKeyForUser2', 'addressForUser2');
(2,null,'privateKeyForUser2', 'publicKeyForUser2', 'addressForUser2');
Binary file not shown.
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
@@ -0,0 +1,8 @@
package web3.exception.S3;

public class S3UploadException extends Exception{

public S3UploadException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import web3.domain.wallet.Wallet;
import web3.exception.S3.S3UploadException;
import web3.s3Storage.dto.CertDto;
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.List;
import java.util.Map;

@RestController
Expand All @@ -35,22 +38,18 @@ public S3StorageController(S3StorageService s3StorageService, WalletService wall
@Operation(summary = "μΈμ¦μ„œ(pdf) μ—…λ‘œλ“œ",description = "μΈμ¦μ„œλ₯Ό μ—…λ‘œλ“œν•©λ‹ˆλ‹€. 즉,s3 μŠ€ν† λ¦¬μ§€μ— pdf νŒŒμΌμ„ μ—…λ‘œλ“œ ν•©λ‹ˆλ‹€.")
@PostMapping("/upload-pdf")
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) {
@RequestParam("certName") String certName,
@RequestParam Map<String, String> certContents) throws IOException {
certContents.remove("walletId");
certContents.remove("file");
certContents.remove("certName");
//λ‚˜μ€‘μ— μž…λ ₯λΆ€λΆ„ λ°”κΎΈλŠ”κ±° κ³ λ €
Wallet wallet = walletService.getWalletById(walletId).orElseThrow(()-> new EntityNotFoundException("Wallet does not exist"));
try {
String pdfUrl = s3StorageService.uploadPdf(file, wallet,pdfInfo,pdfKey);
return ResponseEntity.ok(pdfUrl);
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to upload pdf: " + e.getMessage());
}
String pdfUrl = s3StorageService.uploadPdf(file, wallet,certName,certContents);
return ResponseEntity.ok(pdfUrl);

}


Expand All @@ -60,7 +59,6 @@ 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();
}
Expand All @@ -70,8 +68,7 @@ public ResponseEntity<Void> deleteWallet(
public ResponseEntity<Void> deleteCertForPage(
@Parameter(description = "walletId와 μ‚­μ œν•  pageκ°€ λ‹΄κΈ΄ Dto",required = true)
@RequestBody DeleteCertRequest request
) throws IOException {
System.out.println("request = " + request);
) throws IOException, S3UploadException {
Long walletId = request.getWalletId();
int page = request.getPage();
Wallet wallet = walletService.getWalletById(walletId).orElseThrow(()-> new EntityNotFoundException("Wallet does not exist"));
Expand All @@ -86,7 +83,6 @@ public ResponseEntity<HashMap<String,String>> getCertList(
@RequestParam("pdfUrl") String pdfUrl) {
HashMap<String, String> certList = s3StorageService.getCertList(pdfUrl);
HashMap<String, String> decodedMetadata = s3StorageService.decodeMetadata(certList);
//return ResponseEntity.ok().body(certList);
return ResponseEntity.ok().body(decodedMetadata);

}
Expand All @@ -113,16 +109,10 @@ public ResponseEntity<String> replacePdf(
@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"));
String pdfUrl = s3StorageService.replacePdfPage(wallet, page, file);
return ResponseEntity.ok(pdfUrl);
}catch(IOException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to replace pdf: " + e.getMessage());
}
@RequestParam("walletId") Long walletId) throws IOException {
Wallet wallet = walletService.getWalletById(walletId).orElseThrow(()-> new EntityNotFoundException("Wallet does not exist"));
String pdfUrl = s3StorageService.replacePdfPage(wallet, page, file);
return ResponseEntity.ok(pdfUrl);
}

@Operation(summary = "메타데이터 μ–»κΈ°",description = "μ‚¬μš©μžμ˜ λͺ¨λ“  λ©”νƒ€λ°μ΄ν„°μ˜ 정보듀을 κ°€μ Έμ˜΅λ‹ˆλ‹€.")
Expand All @@ -137,15 +127,16 @@ public ResponseEntity<String> getMetadata(
return ResponseEntity.ok().body(metadata);
}

@Operation(summary = "pdf keyκ°’ μ–»κΈ°",description = "μ‚¬μš©μžμ˜ pdfμ—μ„œ μ›ν•˜λŠ” νŽ˜μ΄μ§€μ˜ key값을 κ°€μ Έμ˜΅λ‹ˆλ‹€.")
@GetMapping("/get-pdfkey")
public ResponseEntity<String> getPdfKey(
@Operation(summary = "메타데이터 λ‚΄μš©λΆ€λΆ„ μ–»κΈ°",description = "μ‚¬μš©μžμ˜ μΈμ¦μ„œ λͺ©λ‘μ€‘ μ›ν•˜λŠ” μΈμ¦μ„œμ˜ λ‚΄μš©λ“€μ„ κ°€μ Έμ˜΅λ‹ˆλ‹€.")
@GetMapping("/get-content")
public ResponseEntity<List<Map.Entry<String, 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);
@RequestParam String certName) {

List<Map.Entry<String, String>> contentsForCertName = s3StorageService.getContentsForCertName(pdfUrl, certName);
return ResponseEntity.ok().body(contentsForCertName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package web3.s3Storage.dto;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.HashMap;

@Getter
@Setter
@RequiredArgsConstructor
public class CertDto {
private String certName;
private HashMap<String, String> certContents;

// Getters and Setters
}
Loading

0 comments on commit f4c3f41

Please sign in to comment.