Skip to content

Commit

Permalink
Merge pull request #101 from Na-o-man/feat/#97/photo-nobody-download
Browse files Browse the repository at this point in the history
[FEAT] 아무도 인식되지 않은 사진 전체 다운로드 API 구현
  • Loading branch information
bflykky authored Aug 12, 2024
2 parents 544154e + 15d33a2 commit fc1fd85
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public ResultResponse<PagedPhotoInfo> getEtcPhotoListByShareGroup(@RequestParam

@GetMapping("/download")
@Operation(summary = "사진 다운로드 API", description = "여러장의 사진을 다운로드할 주소를 받는 API입니다. 해당 공유그룹에 속해있는 회원만 다운로드 요청할 수 있습니다.")
@Parameters(value = {
@Parameter(name = "photoIdList", description = "다운로드할 사진의 아이디를 입력해주세요."),
@Parameter(name = "shareGroupId", description = "다운로드할 사진이 있는 공유그룹의 아이디를 입력해주세요.")
})
public ResultResponse<PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@RequestParam List<Long> photoIdList,
@RequestParam Long shareGroupId,
@LoginMember Member member) {
Expand All @@ -133,11 +137,26 @@ public ResultResponse<PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@Request

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

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

@DeleteMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public interface PhotoService {

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

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

PhotoDownloadUrlListInfo getEtcPhotoDownloadUrlList(Long shareGroupId, Member member);

List<Photo> deletePhotoList(PhotoRequest.PhotoDeletedRequest request, Member member);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public PhotoDownloadUrlListInfo getPhotoDownloadUrlList(List<Long> photoIdList,
}

@Override
public PhotoDownloadUrlListInfo getPhotoEsDownloadUrlList(Long shareGroupId, Long profileId, Member member) {
public PhotoDownloadUrlListInfo getPhotoDownloadUrlListByProfile(Long shareGroupId, Long profileId, Member member) {
validateShareGroupAndProfile(shareGroupId, member);
Long memberId = shareGroupService.findProfile(profileId).getMember().getId();

Expand All @@ -234,6 +234,30 @@ public PhotoDownloadUrlListInfo getPhotoEsDownloadUrlList(Long shareGroupId, Lon
return photoConverter.toPhotoDownloadUrlListInfo(photUrlList);
}

@Override
public PhotoDownloadUrlListInfo getEtcPhotoDownloadUrlList(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.findPhotoEsByShareGroupIdAndNotFaceTag(shareGroupId, pageable);
photoEsList.addAll(photoEsPage.getContent());
isLastPage = photoEsPage.isLast();

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

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

return photoConverter.toPhotoDownloadUrlListInfo(photUrlList);
}

@Override
@Transactional
public List<Photo> deletePhotoList(PhotoRequest.PhotoDeletedRequest request, Member member) {
Expand Down

0 comments on commit fc1fd85

Please sign in to comment.