Skip to content

Commit

Permalink
Merge pull request #133 from Na-o-man/feature/#132/download-all-photo…
Browse files Browse the repository at this point in the history
…-api

[FEAT] 특정 공유그룹 사진 전체 다운로드 API 구현
  • Loading branch information
bflykky authored Aug 23, 2024
2 parents 6d81152 + 938b042 commit 6eabd87
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ public ResultResponse<PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@Request
}

@GetMapping("/download/all")
@Operation(summary = "특정 공유그룹의 사진 전체 다운로드 API", description = "사용자가 속한 공유그룹의 전체 사진을 다운로드할 주소를 받는 API입니다. 해당 공유그룹에 속해있는 회원만 다운로드 요청할 수 있습니다.")
@Parameters(value = {
@Parameter(name = "shareGroupId", description = "다운로드할 사진이 있는 공유그룹의 아이디를 입력해주세요."),
})
public ResultResponse<PhotoDownloadUrlListInfo> getPhotoDownloadUrlListByShareGroup(@RequestParam Long shareGroupId,
@LoginMember Member member) {
PhotoResponse.PhotoDownloadUrlListInfo photoDownloadUrlList = photoService.getPhotoDownloadUrlListByShareGroup(shareGroupId, member);
return ResultResponse.of(DOWNLOAD_PHOTO, photoDownloadUrlList);
}

@GetMapping("/download/album")
@Operation(summary = "특정 앨범 사진 전체 다운로드 API", description = "선택한 앨범에 속한 사진을 다운로드할 주소를 받는 API입니다. 해당 공유그룹에 속해있는 회원만 다운로드 요청할 수 있습니다.")
@Parameters(value = {
@Parameter(name = "shareGroupId", description = "다운로드할 사진이 있는 공유그룹의 아이디를 입력해주세요."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

@Repository
public interface PhotoRepository extends JpaRepository<Photo, Long> {
List<Photo> findByIdInAndShareGroupId(List<Long> photoIdList, Long shareGroupId);

List<Photo> findByIdIn(List<Long> photoIdList);

List<Photo> findByShareGroupId(Long ShareGroupId);

List<Photo> findByIdInAndShareGroupId(List<Long> photoIdList, Long shareGroupId);

@Modifying
@Query("DELETE FROM Photo p WHERE p.id IN :photoIdList")
void deleteAllByPhotoIdList(@Param("photoIdList") List<Long> photoIdList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface PhotoService {

PhotoDownloadUrlListInfo getPhotoDownloadUrlList(List<Long> photoIdList, Long shareGroupId, Member member);

PhotoDownloadUrlListInfo getPhotoDownloadUrlListByShareGroup(Long shareGroupId, Member member);

PhotoDownloadUrlListInfo getPhotoDownloadUrlListByProfile(Long shareGroupId, Long profileId, Member member);

PhotoDownloadUrlListInfo getEtcPhotoDownloadUrlList(Long shareGroupId, Member member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,33 @@ public PhotoDownloadUrlListInfo getPhotoDownloadUrlList(List<Long> photoIdList,
return photoConverter.toPhotoDownloadUrlListInfo(photoUrlList);
}

@Override
public PhotoDownloadUrlListInfo getPhotoDownloadUrlListByShareGroup(Long shareGroupId, Member member) {
validateShareGroupAndProfile(shareGroupId, member);

List<PhotoEs> photoEsList = new ArrayList<>();
Pageable pageable = Pageable.ofSize(5000);
boolean isLastPage = false;

while (!isLastPage) {
Page<PhotoEs> photoEsPage = photoEsClientRepository.findPhotoEsByShareGroupId(shareGroupId, pageable);
photoEsList.addAll(photoEsPage.getContent());
isLastPage = photoEsPage.isLast();

// 다음 페이지로 이동
pageable = pageable.next();
}

List<String> photoUrlList = photoEsList.stream()
.map(PhotoEs::getUrl)
.collect(Collectors.toList());

// 사진 다운로드 이력 추가
photoEsClientRepository.addDownloadTag(photoUrlList, member.getId());

return photoConverter.toPhotoDownloadUrlListInfo(photoUrlList);
}

@Override
public PhotoDownloadUrlListInfo getPhotoDownloadUrlListByProfile(Long shareGroupId, Long profileId, Member member) {
validateShareGroupAndProfile(shareGroupId, member);
Expand Down

0 comments on commit 6eabd87

Please sign in to comment.