From 4420b2bafe31634a58817aee8182e5e805cc6060 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Thu, 4 Jul 2024 21:13:57 +0900 Subject: [PATCH] fix: change create new photo api for newly created brand column (#12) --- .../controller/dto/response/PhotoResponse.java | 5 +++++ .../java/kr/mafoo/photo/service/PhotoService.java | 12 +++++++----- .../java/kr/mafoo/photo/service/QrService.java | 14 +++++++++----- .../java/kr/mafoo/photo/service/dto/FileDto.java | 9 +++++++++ 4 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/dto/FileDto.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java index a70a1fa..3de86f7 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java @@ -1,6 +1,7 @@ package kr.mafoo.photo.controller.dto.response; import io.swagger.v3.oas.annotations.media.Schema; +import kr.mafoo.photo.domain.BrandType; import kr.mafoo.photo.domain.PhotoEntity; @Schema(description = "사진 응답") @@ -11,6 +12,9 @@ public record PhotoResponse( @Schema(description = "사진 URL", example = "photo_url") String photoUrl, + @Schema(description = "사진 브랜드", example = "LIFE_FOUR_CUTS") + BrandType brand, + @Schema(description = "앨범 ID", example = "test_album_id") String albumId ) { @@ -20,6 +24,7 @@ public static PhotoResponse fromEntity( return new PhotoResponse( entity.getPhotoId(), entity.getPhotoUrl(), + entity.getBrand(), entity.getAlbumId() ); } diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java index 541a7eb..b180b13 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -1,5 +1,6 @@ package kr.mafoo.photo.service; +import kr.mafoo.photo.domain.BrandType; import kr.mafoo.photo.domain.PhotoEntity; import kr.mafoo.photo.exception.AlbumNotFoundException; import kr.mafoo.photo.exception.PhotoNotFoundException; @@ -23,11 +24,12 @@ public class PhotoService { public Mono createNewPhoto(String qrUrl, String requestMemberId) { return qrService .getFileFromQrUrl(qrUrl) - .flatMap(objectStorageService::uploadFile) - .flatMap(photoUrl -> { - PhotoEntity photoEntity = PhotoEntity.newPhoto(IdGenerator.generate(), photoUrl, requestMemberId); - return photoRepository.save(photoEntity); - }); + .flatMap(fileDto -> objectStorageService.uploadFile(fileDto.fileByte()) + .flatMap(photoUrl -> { + PhotoEntity photoEntity = PhotoEntity.newPhoto(IdGenerator.generate(), photoUrl, fileDto.type(), requestMemberId); + return photoRepository.save(photoEntity); + }) + ); } public Flux findAllByAlbumId(String albumId, String requestMemberId) { diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java b/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java index a8ed5c7..6c1e099 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java @@ -4,6 +4,7 @@ import kr.mafoo.photo.exception.PhotoBrandNotExistsException; import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; import kr.mafoo.photo.exception.RedirectUriNotFoundException; +import kr.mafoo.photo.service.dto.FileDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -23,17 +24,20 @@ public class QrService { private final WebClient externalWebClient; - protected Mono getFileFromQrUrl(String qrUrl) { + public Mono getFileFromQrUrl(String qrUrl) { BrandType brandType = Optional.ofNullable(BrandType.matchBrandType(qrUrl)) .orElseThrow(PhotoBrandNotExistsException::new); return switch (brandType) { - case LIFE_FOUR_CUTS -> getLifeFourCutsFiles(qrUrl); - case PHOTOISM -> getPhotoismFiles(qrUrl); - case HARU_FILM -> getHaruFilmFiles(qrUrl); - case DONT_LOOK_UP -> getDontLookUpFiles(qrUrl); + case LIFE_FOUR_CUTS -> createFileDto(brandType, getLifeFourCutsFiles(qrUrl)); + case PHOTOISM -> createFileDto(brandType, getPhotoismFiles(qrUrl)); + case HARU_FILM -> createFileDto(brandType, getHaruFilmFiles(qrUrl)); + case DONT_LOOK_UP -> createFileDto(brandType, getDontLookUpFiles(qrUrl)); }; + } + private Mono createFileDto(BrandType brandType, Mono fileMono) { + return fileMono.map(file -> new FileDto(brandType, file)); } private Mono getLifeFourCutsFiles(String qrUrl) { diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/dto/FileDto.java b/photo-service/src/main/java/kr/mafoo/photo/service/dto/FileDto.java new file mode 100644 index 0000000..5dff696 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/dto/FileDto.java @@ -0,0 +1,9 @@ +package kr.mafoo.photo.service.dto; + +import kr.mafoo.photo.domain.BrandType; + +public record FileDto ( + BrandType type, + byte[] fileByte +) { +}