Skip to content

Commit

Permalink
Merge pull request #68 from YAPP-Github/feature/MAFOO-168
Browse files Browse the repository at this point in the history
[MAFOO-168] feat: ์ด๋ฏธ์ง€ ํŒŒ์ผ ์—…๋กœ๋“œ API์— ๊ณต๊ฐœ ๊ถŒํ•œ ์„ค์ • ๋กœ์ง์„ ์ถ”๊ฐ€ํ–ˆ์–ด์š”
  • Loading branch information
gmkim20713 authored Oct 19, 2024
2 parents ee970bc + 0756372 commit 225de84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum ErrorCode {
PHOTO_DISPLAY_INDEX_IS_SAME("PE0004", "์˜ฎ๊ธฐ๋ ค๋Š” ๋Œ€์ƒ ์‚ฌ์ง„ ์ธ๋ฑ์Šค๊ฐ€ ๊ฐ™์Šต๋‹ˆ๋‹ค"),
PHOTO_DISPLAY_INDEX_NOT_VALID("PE0005", "์˜ฎ๊ธฐ๋ ค๋Š” ๋Œ€์ƒ ์‚ฌ์ง„ ์ธ๋ฑ์Šค๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค"),

PRE_SIGNED_URL_EXCEED_MAXIMUM("OE0005", "ํ•œ ๋ฒˆ์— ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” Pre-signed url ์ตœ๋Œ€์น˜๋ฅผ ์ดˆ๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค"),
PRE_SIGNED_URL_EXCEED_MAXIMUM("OE0001", "ํ•œ ๋ฒˆ์— ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” Pre-signed url ์ตœ๋Œ€์น˜๋ฅผ ์ดˆ๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค"),

;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Mono<String> uploadFile(byte[] fileByte) {

return "https://kr.object.ncloudstorage.com/" + bucketName + "/" + keyName;
} catch (Exception e) {
throw new RuntimeException(e);
throw new RuntimeException("Failed to upload image to object storage: ", e);
}
});
}
Expand All @@ -74,4 +74,14 @@ private URL generatePresignedUrl(String fileName, String memberId) {
.withExpiration(expiration));
}

public Mono<Void> setObjectPublicRead(String filePath) {
return Mono.fromRunnable(() -> {
try {
amazonS3Client.setObjectAcl(bucketName, filePath, CannedAccessControlList.PublicRead);
} catch (Exception e) {
throw new RuntimeException("Failed to set ACL to PublicRead for the file: " + filePath, e);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ public Mono<PhotoEntity> createNewPhotoByQrUrl(String qrUrl, String requestMembe
return qrService
.getFileFromQrUrl(qrUrl)
.flatMap(fileDto -> objectStorageService.uploadFile(fileDto.fileByte())
.flatMap(photoUrl -> {
this.createNewPhoto(photoUrl, fileDto.type(), requestMemberId);
PhotoEntity photoEntity = PhotoEntity.newPhoto(IdGenerator.generate(), photoUrl, fileDto.type(), requestMemberId);
return photoRepository.save(photoEntity);
})
.flatMap(photoUrl -> createNewPhoto(photoUrl, fileDto.type(), requestMemberId))
);
}

@Transactional
public Flux<PhotoEntity> createNewPhotoFileUrl(String[] fileUrls, String requestMemberId) {
return Flux.fromArray(fileUrls)
.flatMap(fileUrl ->
this.createNewPhoto(fileUrl, BrandType.EXTERNAL, requestMemberId)
.flatMap(fileUrl -> objectStorageService.setObjectPublicRead(fileUrl)
.then(createNewPhoto(fileUrl, BrandType.EXTERNAL, requestMemberId))
);
}

Expand Down

0 comments on commit 225de84

Please sign in to comment.