From ae6d603bcf5acf51bc5e074ae7877506b1668114 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Wed, 31 Jul 2024 02:21:48 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photo/controller/PhotoController.java | 24 +++++++++++--- .../photo/converter/PhotoConverter.java | 31 +++++++++++++++++++ .../domain/photo/dto/PhotoResponse.java | 25 +++++++++++++++ .../photo/repository/PhotoRepository.java | 4 +++ .../domain/photo/service/PhotoService.java | 5 +++ .../photo/service/PhotoServiceImpl.java | 13 ++++++++ .../global/result/code/PhotoResultCode.java | 3 +- 7 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index 2210e97..7959b97 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -3,18 +3,26 @@ import com.umc.naoman.domain.photo.converter.PhotoConverter; import com.umc.naoman.domain.photo.dto.PhotoRequest; import com.umc.naoman.domain.photo.dto.PhotoResponse; +import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.domain.photo.service.PhotoService; import com.umc.naoman.global.result.ResultResponse; -import com.umc.naoman.global.result.code.PhotoResultCode; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import static com.umc.naoman.global.result.code.PhotoResultCode.*; + @RestController @RequiredArgsConstructor @RequestMapping("/photos") @@ -26,12 +34,20 @@ public class PhotoController { @PostMapping("/preSignedUrl") public ResultResponse getPreSignedUrlList(@Valid @RequestBody PhotoRequest.PreSignedUrlRequest request) { List preSignedUrlList = photoService.getPreSignedUrlList(request); - return ResultResponse.of(PhotoResultCode.CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); + return ResultResponse.of(CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); } @PostMapping("/upload") - public ResultResponse upload(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) { + public ResultResponse uploadPhotoList(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) { PhotoResponse.PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request); - return ResultResponse.of(PhotoResultCode.UPLOAD_PHOTO, photoUploadInfo); + return ResultResponse.of(UPLOAD_PHOTO, photoUploadInfo); + } + + @GetMapping("/all") + public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, + @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { + Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); + return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } + } diff --git a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java index 565989e..86a661f 100644 --- a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java +++ b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java @@ -3,6 +3,7 @@ import com.umc.naoman.domain.photo.dto.PhotoResponse; import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.domain.shareGroup.entity.ShareGroup; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Component; import java.util.List; @@ -40,4 +41,34 @@ public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) .shareGroup(shareGroup) .build(); } + + public PhotoResponse.PhotoListInfo toPhotoListInfo(Page photoList) { + List photoInfoList = photoList.stream() + .map(this::toPhotoInfo) + .collect(Collectors.toList()); + + return PhotoResponse.PhotoListInfo.builder() + .isLast(photoList.isLast()) + .isFirst(photoList.isFirst()) + .totalPage(photoList.getTotalPages()) + .totalElements(photoList.getTotalElements()) + .listSize(photoInfoList.size()) + .photoInfoList(photoInfoList) + .build(); + } + + public PhotoResponse.PhotoInfo toPhotoInfo(Photo photo) { + return PhotoResponse.PhotoInfo.builder() + .photoUrl(photo.getUrl()) + .photoName(photo.getName()) + .resizedPhotoName(convertExtension(photo.getName())) + .uploadTime(photo.getCreatedAt()) + .build(); + } + + // HEIC에서 JPG로 확장자를 변환하는 메서드 + private String convertExtension(String photoUrl) { + return photoUrl.replace(".HEIC", ".jpg"); + } + } diff --git a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java index 1191c26..bd14bf0 100644 --- a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java +++ b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; import java.util.List; public abstract class PhotoResponse { @@ -35,4 +36,28 @@ public static class PhotoUploadInfo { private Long shareGroupId; private int uploadCount; } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PhotoListInfo { + private List photoInfoList; + Integer listSize; + Integer totalPage; + Long totalElements; + Boolean isFirst; + Boolean isLast; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PhotoInfo { + private String photoUrl; + private String photoName; + private String resizedPhotoName; + private LocalDateTime uploadTime; + } } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index 259dd1d..34cd494 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -1,9 +1,13 @@ package com.umc.naoman.domain.photo.repository; import com.umc.naoman.domain.photo.entity.Photo; +import com.umc.naoman.domain.shareGroup.entity.ShareGroup; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface PhotoRepository extends JpaRepository { + Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index 93cf4b1..f2e684b 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -2,6 +2,9 @@ import com.umc.naoman.domain.photo.dto.PhotoRequest; import com.umc.naoman.domain.photo.dto.PhotoResponse; +import com.umc.naoman.domain.photo.entity.Photo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; @@ -10,4 +13,6 @@ public interface PhotoService { List getPreSignedUrlList(PhotoRequest.PreSignedUrlRequest request); PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); + + Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 0362097..3c412fc 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -17,6 +17,8 @@ import com.umc.naoman.global.error.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,6 +76,17 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq return new PhotoResponse.PhotoUploadInfo(shareGroup.getId(), uploadCount); } + @Override + @Transactional(readOnly = true) + public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { + ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); + if (shareGroup == null) { + throw new BusinessException(SHARE_GROUP_NOT_FOUND); + } + + return photoRepository.findAllByShareGroup(shareGroup, pageable); + } + private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { String fileName = createPath(originalFilename); diff --git a/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java b/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java index f4568c2..44bf274 100644 --- a/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java +++ b/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java @@ -9,7 +9,8 @@ @RequiredArgsConstructor public enum PhotoResultCode implements ResultCode { CREATE_PRESIGNED_URL(200, "SP000", "성공적으로 Presigned URL을 요청하였습니다."), - UPLOAD_PHOTO(200, "SP000", "성공적으로 이미지를 업로드하였습니다.") + UPLOAD_PHOTO(200, "SP000", "성공적으로 이미지를 업로드하였습니다."), + RETRIEVE_PHOTO(200, "SP000", "성공적으로 이미지를 조회하였습니다.") ; private final int status; From 45de0f324b0a0bb496559061c52c9475b70cdec2 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Wed, 31 Jul 2024 02:21:48 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photo/controller/PhotoController.java | 24 +++++++++++--- .../photo/converter/PhotoConverter.java | 31 +++++++++++++++++++ .../domain/photo/dto/PhotoResponse.java | 25 +++++++++++++++ .../photo/repository/PhotoRepository.java | 4 +++ .../domain/photo/service/PhotoService.java | 5 +++ .../photo/service/PhotoServiceImpl.java | 13 ++++++++ .../global/result/code/PhotoResultCode.java | 3 +- 7 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index 2210e97..7959b97 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -3,18 +3,26 @@ import com.umc.naoman.domain.photo.converter.PhotoConverter; import com.umc.naoman.domain.photo.dto.PhotoRequest; import com.umc.naoman.domain.photo.dto.PhotoResponse; +import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.domain.photo.service.PhotoService; import com.umc.naoman.global.result.ResultResponse; -import com.umc.naoman.global.result.code.PhotoResultCode; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import static com.umc.naoman.global.result.code.PhotoResultCode.*; + @RestController @RequiredArgsConstructor @RequestMapping("/photos") @@ -26,12 +34,20 @@ public class PhotoController { @PostMapping("/preSignedUrl") public ResultResponse getPreSignedUrlList(@Valid @RequestBody PhotoRequest.PreSignedUrlRequest request) { List preSignedUrlList = photoService.getPreSignedUrlList(request); - return ResultResponse.of(PhotoResultCode.CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); + return ResultResponse.of(CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); } @PostMapping("/upload") - public ResultResponse upload(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) { + public ResultResponse uploadPhotoList(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) { PhotoResponse.PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request); - return ResultResponse.of(PhotoResultCode.UPLOAD_PHOTO, photoUploadInfo); + return ResultResponse.of(UPLOAD_PHOTO, photoUploadInfo); + } + + @GetMapping("/all") + public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, + @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { + Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); + return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } + } diff --git a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java index 565989e..86a661f 100644 --- a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java +++ b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java @@ -3,6 +3,7 @@ import com.umc.naoman.domain.photo.dto.PhotoResponse; import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.domain.shareGroup.entity.ShareGroup; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Component; import java.util.List; @@ -40,4 +41,34 @@ public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) .shareGroup(shareGroup) .build(); } + + public PhotoResponse.PhotoListInfo toPhotoListInfo(Page photoList) { + List photoInfoList = photoList.stream() + .map(this::toPhotoInfo) + .collect(Collectors.toList()); + + return PhotoResponse.PhotoListInfo.builder() + .isLast(photoList.isLast()) + .isFirst(photoList.isFirst()) + .totalPage(photoList.getTotalPages()) + .totalElements(photoList.getTotalElements()) + .listSize(photoInfoList.size()) + .photoInfoList(photoInfoList) + .build(); + } + + public PhotoResponse.PhotoInfo toPhotoInfo(Photo photo) { + return PhotoResponse.PhotoInfo.builder() + .photoUrl(photo.getUrl()) + .photoName(photo.getName()) + .resizedPhotoName(convertExtension(photo.getName())) + .uploadTime(photo.getCreatedAt()) + .build(); + } + + // HEIC에서 JPG로 확장자를 변환하는 메서드 + private String convertExtension(String photoUrl) { + return photoUrl.replace(".HEIC", ".jpg"); + } + } diff --git a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java index 1191c26..bd14bf0 100644 --- a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java +++ b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; import java.util.List; public abstract class PhotoResponse { @@ -35,4 +36,28 @@ public static class PhotoUploadInfo { private Long shareGroupId; private int uploadCount; } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PhotoListInfo { + private List photoInfoList; + Integer listSize; + Integer totalPage; + Long totalElements; + Boolean isFirst; + Boolean isLast; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PhotoInfo { + private String photoUrl; + private String photoName; + private String resizedPhotoName; + private LocalDateTime uploadTime; + } } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index 259dd1d..34cd494 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -1,9 +1,13 @@ package com.umc.naoman.domain.photo.repository; import com.umc.naoman.domain.photo.entity.Photo; +import com.umc.naoman.domain.shareGroup.entity.ShareGroup; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface PhotoRepository extends JpaRepository { + Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index 93cf4b1..f2e684b 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -2,6 +2,9 @@ import com.umc.naoman.domain.photo.dto.PhotoRequest; import com.umc.naoman.domain.photo.dto.PhotoResponse; +import com.umc.naoman.domain.photo.entity.Photo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; @@ -10,4 +13,6 @@ public interface PhotoService { List getPreSignedUrlList(PhotoRequest.PreSignedUrlRequest request); PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); + + Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 0362097..3c412fc 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -17,6 +17,8 @@ import com.umc.naoman.global.error.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,6 +76,17 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq return new PhotoResponse.PhotoUploadInfo(shareGroup.getId(), uploadCount); } + @Override + @Transactional(readOnly = true) + public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { + ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); + if (shareGroup == null) { + throw new BusinessException(SHARE_GROUP_NOT_FOUND); + } + + return photoRepository.findAllByShareGroup(shareGroup, pageable); + } + private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { String fileName = createPath(originalFilename); diff --git a/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java b/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java index f4568c2..44bf274 100644 --- a/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java +++ b/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java @@ -9,7 +9,8 @@ @RequiredArgsConstructor public enum PhotoResultCode implements ResultCode { CREATE_PRESIGNED_URL(200, "SP000", "성공적으로 Presigned URL을 요청하였습니다."), - UPLOAD_PHOTO(200, "SP000", "성공적으로 이미지를 업로드하였습니다.") + UPLOAD_PHOTO(200, "SP000", "성공적으로 이미지를 업로드하였습니다."), + RETRIEVE_PHOTO(200, "SP000", "성공적으로 이미지를 조회하였습니다.") ; private final int status; From 135b1ba4cbf802395f11ec972f7de47efc2ff897 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:49:23 +0900 Subject: [PATCH 3/9] =?UTF-8?q?refact=20:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naoman/domain/photo/controller/PhotoController.java | 6 +++--- .../umc/naoman/domain/photo/converter/PhotoConverter.java | 7 +++---- .../com/umc/naoman/domain/photo/dto/PhotoResponse.java | 5 ++--- .../naoman/domain/photo/repository/PhotoRepository.java | 3 +-- .../com/umc/naoman/domain/photo/service/PhotoService.java | 2 +- .../umc/naoman/domain/photo/service/PhotoServiceImpl.java | 4 ++-- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index 7959b97..dfa7ae6 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -44,9 +44,9 @@ public ResultResponse uploadPhotoList(@Valid @Req } @GetMapping("/all") - public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, - @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { - Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); + public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, + @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { + Page allPhotoListByShareGroup = photoService.getAllPhotoList(shareGroupId, pageable); return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } diff --git a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java index 86a661f..3a22467 100644 --- a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java +++ b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java @@ -42,17 +42,16 @@ public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) .build(); } - public PhotoResponse.PhotoListInfo toPhotoListInfo(Page photoList) { + public PhotoResponse.PagedPhotoInfo toPhotoListInfo(Page photoList) { List photoInfoList = photoList.stream() .map(this::toPhotoInfo) .collect(Collectors.toList()); - return PhotoResponse.PhotoListInfo.builder() + return PhotoResponse.PagedPhotoInfo.builder() .isLast(photoList.isLast()) .isFirst(photoList.isFirst()) .totalPage(photoList.getTotalPages()) .totalElements(photoList.getTotalElements()) - .listSize(photoInfoList.size()) .photoInfoList(photoInfoList) .build(); } @@ -62,7 +61,7 @@ public PhotoResponse.PhotoInfo toPhotoInfo(Photo photo) { .photoUrl(photo.getUrl()) .photoName(photo.getName()) .resizedPhotoName(convertExtension(photo.getName())) - .uploadTime(photo.getCreatedAt()) + .createdAt(photo.getCreatedAt()) .build(); } diff --git a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java index bd14bf0..9d6de77 100644 --- a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java +++ b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java @@ -41,9 +41,8 @@ public static class PhotoUploadInfo { @Builder @AllArgsConstructor @NoArgsConstructor - public static class PhotoListInfo { + public static class PagedPhotoInfo { private List photoInfoList; - Integer listSize; Integer totalPage; Long totalElements; Boolean isFirst; @@ -58,6 +57,6 @@ public static class PhotoInfo { private String photoUrl; private String photoName; private String resizedPhotoName; - private LocalDateTime uploadTime; + private LocalDateTime createdAt; } } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index 34cd494..d04f83a 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -1,7 +1,6 @@ package com.umc.naoman.domain.photo.repository; import com.umc.naoman.domain.photo.entity.Photo; -import com.umc.naoman.domain.shareGroup.entity.ShareGroup; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,5 +8,5 @@ @Repository public interface PhotoRepository extends JpaRepository { - Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); + Page findAllByShareGroupId(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index f2e684b..e6b3f48 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -14,5 +14,5 @@ public interface PhotoService { PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); - Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); + Page getAllPhotoList(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 3c412fc..4ff5bf5 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -78,13 +78,13 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq @Override @Transactional(readOnly = true) - public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { + public Page getAllPhotoList(Long shareGroupId, Pageable pageable) { ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); if (shareGroup == null) { throw new BusinessException(SHARE_GROUP_NOT_FOUND); } - return photoRepository.findAllByShareGroup(shareGroup, pageable); + return photoRepository.findAllByShareGroupId(shareGroupId, pageable); } private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { From 1b8627acf66ccb3060b4f0d33a1f8fb7b3793512 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:04:48 +0900 Subject: [PATCH 4/9] =?UTF-8?q?refact=20:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naoman/domain/photo/service/PhotoServiceImpl.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 4ff5bf5..ebdf018 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -29,7 +29,6 @@ import java.util.stream.Collectors; import static com.umc.naoman.global.error.code.S3ErrorCode.PHOTO_NOT_FOUND_S3; -import static com.umc.naoman.global.error.code.ShareGroupErrorCode.SHARE_GROUP_NOT_FOUND; @Service @RequiredArgsConstructor @@ -60,10 +59,6 @@ public List getPreSignedUrlList(PhotoRequest.Pre @Transactional public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request) { ShareGroup shareGroup = shareGroupService.findShareGroup(request.getShareGroupId()); - if (shareGroup == null) { - throw new BusinessException(SHARE_GROUP_NOT_FOUND); - } - int uploadCount = 0; for (String photoUrl : request.getPhotoUrlList()) { @@ -80,11 +75,7 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq @Transactional(readOnly = true) public Page getAllPhotoList(Long shareGroupId, Pageable pageable) { ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); - if (shareGroup == null) { - throw new BusinessException(SHARE_GROUP_NOT_FOUND); - } - - return photoRepository.findAllByShareGroupId(shareGroupId, pageable); + return photoRepository.findAllByShareGroupId(shareGroup.getId(), pageable); } private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { From 5f146bba6aa8ae9b192df7720d0a9c2c3ecf3a7a Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Wed, 31 Jul 2024 02:21:48 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photo/controller/PhotoController.java | 24 +++++++++++--- .../photo/converter/PhotoConverter.java | 31 +++++++++++++++++++ .../domain/photo/dto/PhotoResponse.java | 25 +++++++++++++++ .../photo/repository/PhotoRepository.java | 4 +++ .../domain/photo/service/PhotoService.java | 5 +++ .../photo/service/PhotoServiceImpl.java | 13 ++++++++ .../global/result/code/PhotoResultCode.java | 3 +- 7 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index 2210e97..7959b97 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -3,18 +3,26 @@ import com.umc.naoman.domain.photo.converter.PhotoConverter; import com.umc.naoman.domain.photo.dto.PhotoRequest; import com.umc.naoman.domain.photo.dto.PhotoResponse; +import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.domain.photo.service.PhotoService; import com.umc.naoman.global.result.ResultResponse; -import com.umc.naoman.global.result.code.PhotoResultCode; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import static com.umc.naoman.global.result.code.PhotoResultCode.*; + @RestController @RequiredArgsConstructor @RequestMapping("/photos") @@ -26,12 +34,20 @@ public class PhotoController { @PostMapping("/preSignedUrl") public ResultResponse getPreSignedUrlList(@Valid @RequestBody PhotoRequest.PreSignedUrlRequest request) { List preSignedUrlList = photoService.getPreSignedUrlList(request); - return ResultResponse.of(PhotoResultCode.CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); + return ResultResponse.of(CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList)); } @PostMapping("/upload") - public ResultResponse upload(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) { + public ResultResponse uploadPhotoList(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) { PhotoResponse.PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request); - return ResultResponse.of(PhotoResultCode.UPLOAD_PHOTO, photoUploadInfo); + return ResultResponse.of(UPLOAD_PHOTO, photoUploadInfo); + } + + @GetMapping("/all") + public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, + @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { + Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); + return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } + } diff --git a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java index 565989e..86a661f 100644 --- a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java +++ b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java @@ -3,6 +3,7 @@ import com.umc.naoman.domain.photo.dto.PhotoResponse; import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.domain.shareGroup.entity.ShareGroup; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Component; import java.util.List; @@ -40,4 +41,34 @@ public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) .shareGroup(shareGroup) .build(); } + + public PhotoResponse.PhotoListInfo toPhotoListInfo(Page photoList) { + List photoInfoList = photoList.stream() + .map(this::toPhotoInfo) + .collect(Collectors.toList()); + + return PhotoResponse.PhotoListInfo.builder() + .isLast(photoList.isLast()) + .isFirst(photoList.isFirst()) + .totalPage(photoList.getTotalPages()) + .totalElements(photoList.getTotalElements()) + .listSize(photoInfoList.size()) + .photoInfoList(photoInfoList) + .build(); + } + + public PhotoResponse.PhotoInfo toPhotoInfo(Photo photo) { + return PhotoResponse.PhotoInfo.builder() + .photoUrl(photo.getUrl()) + .photoName(photo.getName()) + .resizedPhotoName(convertExtension(photo.getName())) + .uploadTime(photo.getCreatedAt()) + .build(); + } + + // HEIC에서 JPG로 확장자를 변환하는 메서드 + private String convertExtension(String photoUrl) { + return photoUrl.replace(".HEIC", ".jpg"); + } + } diff --git a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java index 1191c26..bd14bf0 100644 --- a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java +++ b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; import java.util.List; public abstract class PhotoResponse { @@ -35,4 +36,28 @@ public static class PhotoUploadInfo { private Long shareGroupId; private int uploadCount; } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PhotoListInfo { + private List photoInfoList; + Integer listSize; + Integer totalPage; + Long totalElements; + Boolean isFirst; + Boolean isLast; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PhotoInfo { + private String photoUrl; + private String photoName; + private String resizedPhotoName; + private LocalDateTime uploadTime; + } } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index 259dd1d..34cd494 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -1,9 +1,13 @@ package com.umc.naoman.domain.photo.repository; import com.umc.naoman.domain.photo.entity.Photo; +import com.umc.naoman.domain.shareGroup.entity.ShareGroup; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface PhotoRepository extends JpaRepository { + Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index 93cf4b1..f2e684b 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -2,6 +2,9 @@ import com.umc.naoman.domain.photo.dto.PhotoRequest; import com.umc.naoman.domain.photo.dto.PhotoResponse; +import com.umc.naoman.domain.photo.entity.Photo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import java.util.List; @@ -10,4 +13,6 @@ public interface PhotoService { List getPreSignedUrlList(PhotoRequest.PreSignedUrlRequest request); PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); + + Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 0362097..3c412fc 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -17,6 +17,8 @@ import com.umc.naoman.global.error.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,6 +76,17 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq return new PhotoResponse.PhotoUploadInfo(shareGroup.getId(), uploadCount); } + @Override + @Transactional(readOnly = true) + public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { + ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); + if (shareGroup == null) { + throw new BusinessException(SHARE_GROUP_NOT_FOUND); + } + + return photoRepository.findAllByShareGroup(shareGroup, pageable); + } + private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { String fileName = createPath(originalFilename); diff --git a/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java b/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java index f4568c2..44bf274 100644 --- a/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java +++ b/src/main/java/com/umc/naoman/global/result/code/PhotoResultCode.java @@ -9,7 +9,8 @@ @RequiredArgsConstructor public enum PhotoResultCode implements ResultCode { CREATE_PRESIGNED_URL(200, "SP000", "성공적으로 Presigned URL을 요청하였습니다."), - UPLOAD_PHOTO(200, "SP000", "성공적으로 이미지를 업로드하였습니다.") + UPLOAD_PHOTO(200, "SP000", "성공적으로 이미지를 업로드하였습니다."), + RETRIEVE_PHOTO(200, "SP000", "성공적으로 이미지를 조회하였습니다.") ; private final int status; From 34223d186cd6f8653ca16ebb8aec532c06021af2 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:49:23 +0900 Subject: [PATCH 6/9] =?UTF-8?q?refact=20:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naoman/domain/photo/controller/PhotoController.java | 6 +++--- .../umc/naoman/domain/photo/converter/PhotoConverter.java | 7 +++---- .../com/umc/naoman/domain/photo/dto/PhotoResponse.java | 5 ++--- .../naoman/domain/photo/repository/PhotoRepository.java | 3 +-- .../com/umc/naoman/domain/photo/service/PhotoService.java | 2 +- .../umc/naoman/domain/photo/service/PhotoServiceImpl.java | 4 ++-- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index 7959b97..dfa7ae6 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -44,9 +44,9 @@ public ResultResponse uploadPhotoList(@Valid @Req } @GetMapping("/all") - public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, - @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { - Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); + public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, + @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { + Page allPhotoListByShareGroup = photoService.getAllPhotoList(shareGroupId, pageable); return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } diff --git a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java index 86a661f..3a22467 100644 --- a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java +++ b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java @@ -42,17 +42,16 @@ public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) .build(); } - public PhotoResponse.PhotoListInfo toPhotoListInfo(Page photoList) { + public PhotoResponse.PagedPhotoInfo toPhotoListInfo(Page photoList) { List photoInfoList = photoList.stream() .map(this::toPhotoInfo) .collect(Collectors.toList()); - return PhotoResponse.PhotoListInfo.builder() + return PhotoResponse.PagedPhotoInfo.builder() .isLast(photoList.isLast()) .isFirst(photoList.isFirst()) .totalPage(photoList.getTotalPages()) .totalElements(photoList.getTotalElements()) - .listSize(photoInfoList.size()) .photoInfoList(photoInfoList) .build(); } @@ -62,7 +61,7 @@ public PhotoResponse.PhotoInfo toPhotoInfo(Photo photo) { .photoUrl(photo.getUrl()) .photoName(photo.getName()) .resizedPhotoName(convertExtension(photo.getName())) - .uploadTime(photo.getCreatedAt()) + .createdAt(photo.getCreatedAt()) .build(); } diff --git a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java index bd14bf0..9d6de77 100644 --- a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java +++ b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java @@ -41,9 +41,8 @@ public static class PhotoUploadInfo { @Builder @AllArgsConstructor @NoArgsConstructor - public static class PhotoListInfo { + public static class PagedPhotoInfo { private List photoInfoList; - Integer listSize; Integer totalPage; Long totalElements; Boolean isFirst; @@ -58,6 +57,6 @@ public static class PhotoInfo { private String photoUrl; private String photoName; private String resizedPhotoName; - private LocalDateTime uploadTime; + private LocalDateTime createdAt; } } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index 34cd494..d04f83a 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -1,7 +1,6 @@ package com.umc.naoman.domain.photo.repository; import com.umc.naoman.domain.photo.entity.Photo; -import com.umc.naoman.domain.shareGroup.entity.ShareGroup; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,5 +8,5 @@ @Repository public interface PhotoRepository extends JpaRepository { - Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); + Page findAllByShareGroupId(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index f2e684b..e6b3f48 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -14,5 +14,5 @@ public interface PhotoService { PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); - Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); + Page getAllPhotoList(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 3c412fc..4ff5bf5 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -78,13 +78,13 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq @Override @Transactional(readOnly = true) - public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { + public Page getAllPhotoList(Long shareGroupId, Pageable pageable) { ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); if (shareGroup == null) { throw new BusinessException(SHARE_GROUP_NOT_FOUND); } - return photoRepository.findAllByShareGroup(shareGroup, pageable); + return photoRepository.findAllByShareGroupId(shareGroupId, pageable); } private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { From 8d249bf82b530deb94c62aa91570d011b7736b12 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Wed, 31 Jul 2024 02:21:48 +0900 Subject: [PATCH 7/9] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naoman/domain/photo/controller/PhotoController.java | 6 +++--- .../umc/naoman/domain/photo/converter/PhotoConverter.java | 7 ++++--- .../com/umc/naoman/domain/photo/dto/PhotoResponse.java | 5 +++-- .../naoman/domain/photo/repository/PhotoRepository.java | 3 ++- .../com/umc/naoman/domain/photo/service/PhotoService.java | 2 +- .../umc/naoman/domain/photo/service/PhotoServiceImpl.java | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index dfa7ae6..7959b97 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -44,9 +44,9 @@ public ResultResponse uploadPhotoList(@Valid @Req } @GetMapping("/all") - public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, - @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { - Page allPhotoListByShareGroup = photoService.getAllPhotoList(shareGroupId, pageable); + public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, + @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { + Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } diff --git a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java index 3a22467..86a661f 100644 --- a/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java +++ b/src/main/java/com/umc/naoman/domain/photo/converter/PhotoConverter.java @@ -42,16 +42,17 @@ public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) .build(); } - public PhotoResponse.PagedPhotoInfo toPhotoListInfo(Page photoList) { + public PhotoResponse.PhotoListInfo toPhotoListInfo(Page photoList) { List photoInfoList = photoList.stream() .map(this::toPhotoInfo) .collect(Collectors.toList()); - return PhotoResponse.PagedPhotoInfo.builder() + return PhotoResponse.PhotoListInfo.builder() .isLast(photoList.isLast()) .isFirst(photoList.isFirst()) .totalPage(photoList.getTotalPages()) .totalElements(photoList.getTotalElements()) + .listSize(photoInfoList.size()) .photoInfoList(photoInfoList) .build(); } @@ -61,7 +62,7 @@ public PhotoResponse.PhotoInfo toPhotoInfo(Photo photo) { .photoUrl(photo.getUrl()) .photoName(photo.getName()) .resizedPhotoName(convertExtension(photo.getName())) - .createdAt(photo.getCreatedAt()) + .uploadTime(photo.getCreatedAt()) .build(); } diff --git a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java index 9d6de77..bd14bf0 100644 --- a/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java +++ b/src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java @@ -41,8 +41,9 @@ public static class PhotoUploadInfo { @Builder @AllArgsConstructor @NoArgsConstructor - public static class PagedPhotoInfo { + public static class PhotoListInfo { private List photoInfoList; + Integer listSize; Integer totalPage; Long totalElements; Boolean isFirst; @@ -57,6 +58,6 @@ public static class PhotoInfo { private String photoUrl; private String photoName; private String resizedPhotoName; - private LocalDateTime createdAt; + private LocalDateTime uploadTime; } } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index d04f83a..34cd494 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -1,6 +1,7 @@ package com.umc.naoman.domain.photo.repository; import com.umc.naoman.domain.photo.entity.Photo; +import com.umc.naoman.domain.shareGroup.entity.ShareGroup; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,5 +9,5 @@ @Repository public interface PhotoRepository extends JpaRepository { - Page findAllByShareGroupId(Long shareGroupId, Pageable pageable); + Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index e6b3f48..f2e684b 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -14,5 +14,5 @@ public interface PhotoService { PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); - Page getAllPhotoList(Long shareGroupId, Pageable pageable); + Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 4ff5bf5..3c412fc 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -78,13 +78,13 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq @Override @Transactional(readOnly = true) - public Page getAllPhotoList(Long shareGroupId, Pageable pageable) { + public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); if (shareGroup == null) { throw new BusinessException(SHARE_GROUP_NOT_FOUND); } - return photoRepository.findAllByShareGroupId(shareGroupId, pageable); + return photoRepository.findAllByShareGroup(shareGroup, pageable); } private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { From d2b6219399c6945038416765d10cf35f643eeab6 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:04:48 +0900 Subject: [PATCH 8/9] =?UTF-8?q?refact=20:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/photo/service/PhotoServiceImpl.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 3c412fc..ebdf018 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -29,7 +29,6 @@ import java.util.stream.Collectors; import static com.umc.naoman.global.error.code.S3ErrorCode.PHOTO_NOT_FOUND_S3; -import static com.umc.naoman.global.error.code.ShareGroupErrorCode.SHARE_GROUP_NOT_FOUND; @Service @RequiredArgsConstructor @@ -60,10 +59,6 @@ public List getPreSignedUrlList(PhotoRequest.Pre @Transactional public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request) { ShareGroup shareGroup = shareGroupService.findShareGroup(request.getShareGroupId()); - if (shareGroup == null) { - throw new BusinessException(SHARE_GROUP_NOT_FOUND); - } - int uploadCount = 0; for (String photoUrl : request.getPhotoUrlList()) { @@ -78,13 +73,9 @@ public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadReq @Override @Transactional(readOnly = true) - public Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable) { + public Page getAllPhotoList(Long shareGroupId, Pageable pageable) { ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); - if (shareGroup == null) { - throw new BusinessException(SHARE_GROUP_NOT_FOUND); - } - - return photoRepository.findAllByShareGroup(shareGroup, pageable); + return photoRepository.findAllByShareGroupId(shareGroup.getId(), pageable); } private PhotoResponse.PreSignedUrlInfo getPreSignedUrl(String originalFilename) { From fd03043351518c8de5deaf595b43d54a8379aee0 Mon Sep 17 00:00:00 2001 From: Donghoon Jeong <112836685+jjeongdong@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:52:51 +0900 Subject: [PATCH 9/9] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=82=AC=EC=A7=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/naoman/domain/photo/controller/PhotoController.java | 2 +- .../com/umc/naoman/domain/photo/repository/PhotoRepository.java | 2 +- .../java/com/umc/naoman/domain/photo/service/PhotoService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java index 7959b97..c96ed53 100644 --- a/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java +++ b/src/main/java/com/umc/naoman/domain/photo/controller/PhotoController.java @@ -46,7 +46,7 @@ public ResultResponse uploadPhotoList(@Valid @Req @GetMapping("/all") public ResultResponse getAllPhotoListByShareGroup(@RequestParam Long shareGroupId, @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { - Page allPhotoListByShareGroup = photoService.getAllPhotoListByShareGroup(shareGroupId, pageable); + Page allPhotoListByShareGroup = photoService.getAllPhotoList(shareGroupId, pageable); return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPhotoListInfo(allPhotoListByShareGroup)); } diff --git a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java index 34cd494..2e5899d 100644 --- a/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/repository/PhotoRepository.java @@ -9,5 +9,5 @@ @Repository public interface PhotoRepository extends JpaRepository { - Page findAllByShareGroup(ShareGroup shareGroup, Pageable pageable); + Page findAllByShareGroupId(Long shareGroupId, Pageable pageable); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index f2e684b..e6b3f48 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -14,5 +14,5 @@ public interface PhotoService { PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request); - Page getAllPhotoListByShareGroup(Long shareGroupId, Pageable pageable); + Page getAllPhotoList(Long shareGroupId, Pageable pageable); }