Skip to content

Commit

Permalink
Merge pull request #43 from Donut-DONationUTile/feature/donation/giver
Browse files Browse the repository at this point in the history
Chore: modify request dto
  • Loading branch information
Ganghee-Lee-0522 authored Feb 22, 2024
2 parents 3d4e91e + 91ab74e commit ed00ee7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DonateGiftRequestDto {
private Integer price;
private LocalDateTime dueDate;
private Store store;
private Boolean isRestored;

public Gift toEntity(Giver giver, Giftbox giftbox, String imageUrl, String store){
return Gift.builder()
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/zero/eight/donut/service/SerialDonationService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zero.eight.donut.service;


import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -139,8 +140,8 @@ public ApiResponse<?> donateGift(DonateGiftRequestDto requestDto) throws IOExcep
Giftbox defaultGiftbox = giftboxRepository.findById(0L)
.orElseThrow(()-> new ApiException(Error.GIFTBOX_NOT_FOUND_EXCEPTION));

//Send Image to AI
String imageUrl = sendImageToAI(requestDto.getGiftImage());
//Upload Image to Google Cloud Storage
String imageUrl = uploadImageToGCS(requestDto);

//CREATE Gift
Gift newGift = requestDto.toEntity(giver, defaultGiftbox, imageUrl, requestDto.getStore().toString());
Expand All @@ -152,6 +153,17 @@ public ApiResponse<?> donateGift(DonateGiftRequestDto requestDto) throws IOExcep
//기부 통계 업데이트
updateDonateInfo(requestDto);

/**
* !!!비동기 처리!!!
* 1. 받은 이미지 중 복구 실행해야 하는 것들 복구
* (복구에 성공했다면)
* -> 기존 imageUrl 객체 삭제
* -> newGift의 imageUrl 수정
**/
//Send Image to AI
// if(requestDto.getIsRestored())
// imageUrl = sendImageToAI(requestDto.getGiftImage());

return ApiResponse.success(Success.DONATE_GIFT_SUCCESS, Map.of("giftId", newGift.getId()));
}

Expand Down Expand Up @@ -223,6 +235,24 @@ private void updateDonateInfo(DonateGiftRequestDto requestDto){
donationInfo.getSum()+requestDto.getPrice().longValue(),
donationInfo.getCount()+1L);
}
private String uploadImageToGCS(DonateGiftRequestDto requestDto) throws IOException{
//이미지명 uuid 변환
String uuid = UUID.randomUUID().toString();
//이미지 형식 추출
String ext = requestDto.getGiftImage().getContentType();

// Google Cloud Storage 이미지 업로드
BlobInfo blobInfo = storage.create(
BlobInfo.newBuilder(BUCKET_NAME, uuid)
.setContentType(ext)
.build(),
requestDto.getGiftImage().getInputStream()
);
log.info("successfully upload image to gcs");

String imgUrl = "https://storage.googleapis.com/" + BUCKET_NAME + "/" + uuid;
return imgUrl;
}
private String sendImageToAI(MultipartFile giftImage){
WebClient webClient = WebClient.builder().baseUrl("http://34.64.144.108:8000").build();

Expand Down

0 comments on commit ed00ee7

Please sign in to comment.