@@ -281,32 +281,40 @@ public String deletePhotoAlbum(Long photoAlbumId, Long memberId) {
281281 }
282282
283283 @ Override
284- public PhotoAlbumResponseDTO .ScrollMemberPhotoAlbumDTO getAllRecentPhotoAlbumList (int page , int size ){
284+ public PhotoAlbumResponseDTO .ScrollMemberPhotoAlbumDTO getAllRecentPhotoAlbumList (Long memberId , int page , int size ){
285+
286+ //로그인 검사
287+ memberRepository .findById (memberId )
288+ .orElseThrow (() -> new GeneralException (ErrorStatus .MEMBER_NOT_AUTHORIZED ));
285289
286290 // 최근 생성한 순서대로 photoAlbum 가져오기
287291 Pageable pageable = PageRequest .of (page , size , Sort .by (Sort .Direction .DESC , "createdAt" ));
288- Page <PhotoAlbum > albumPage = photoAlbumRepository .findAll (pageable ); // 또는 커스텀 쿼리 사용 가능
292+ Page <PhotoAlbum > albumPage = photoAlbumRepository .findAll (pageable );
289293 List <PhotoAlbum > albums = albumPage .getContent (); //Page 벗기기
290294
291- // 3. N+1 방지: 대표 이미지 조회
295+ // N+1 방지: 대표 이미지 조회
292296 List <Long > albumIds = albums .stream ()
293297 .map (PhotoAlbum ::getId )
294298 .toList ();
295299
296- Map <Long , Image > albumImageMap = imageRepository .findFirstByContentIds (albumIds , FilePath .photoAlbum )
297- .stream ()
298- .collect (Collectors .toMap (Image ::getContentId , Function .identity ()));
300+ List <Image > images = imageRepository .findFirstByContentIds (albumIds , FilePath .photoAlbum );
299301
302+ // 1. images 전체를 한 번에 imageService에 넘김 -> 사진첩 개수만큼의 presignedUrl 발급을 한번에
303+ List <ImageResponseDTO .ImageResultWithPresignedUrlDTO > imageDTOs = imageService .getImages (images , memberId );
304+
305+ // 2. DTO를 contentId 기준으로 Map으로 변환 -> 각 사진첩 dto에 발급받은 url 뿌려줌
306+ Map <Long , ImageResponseDTO .ImageResultWithPresignedUrlDTO > albumImageMap = imageDTOs .stream ()
307+ .collect (Collectors .toMap (ImageResponseDTO .ImageResultWithPresignedUrlDTO ::getContentId , Function .identity ()));
300308 //DTO 변환
301309 List <PhotoAlbumResponseDTO .MemberPhotoAlbumDTO > dtoList = albums .stream ()
302310 .map (album -> {
303- Image coverImage = albumImageMap .get (album .getId ());
311+ ImageResponseDTO . ImageResultWithPresignedUrlDTO coverImageDTO = albumImageMap .get (album .getId ());
304312 return PhotoAlbumResponseDTO .MemberPhotoAlbumDTO .builder ()
305313 .photoAlbumId (album .getId ())
306314 .memberId (album .getAmateurShow ().getMember ().getId ())
307315 .performerName (album .getAmateurShow ().getMember ().getName ())
308316 .amateurShowName (album .getAmateurShow ().getName ())
309- .imageUrl (coverImage != null ? coverImage . getImageUrl () : null )
317+ .imageUrl (coverImageDTO != null ? coverImageDTO . getPresignedUrl () : null )
310318 .build ();
311319 })
312320 .toList ();
0 commit comments