Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Service
@RequiredArgsConstructor
Expand All @@ -36,11 +39,20 @@ public List<VisitResponseDTO.HourlyVisitorDTO> getHourlyVisits() {

RunReportResponse response = betaAnalyticsDataClient.runReport(request);

return response.getRowsList().stream()
.map(row -> new VisitResponseDTO.HourlyVisitorDTO(
row.getDimensionValues(0).getValue(),
Long.parseLong(row.getMetricValues(0).getValue())
))

Map<Integer, Long> hourMap = IntStream.range(0, 24)
.boxed()
.collect(Collectors.toMap(h -> h, h -> 0L));

response.getRowsList().forEach(row -> {
int hour = Integer.parseInt(row.getDimensionValues(0).getValue());
long count = Long.parseLong(row.getMetricValues(0).getValue());
hourMap.put(hour, count);
});

return hourMap.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> new VisitResponseDTO.HourlyVisitorDTO(e.getKey(), e.getValue()))
.toList();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cc/backend/image/entity/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Image {
// S3 객체 키 (예: "board/1.png") - 삭제나 조회 시 필요(객체 url에서 버킷 url 뺀 나머지 = filepath + 파일이름)
private String keyName;

// 정적인 컨텐츠 전용 URL (poster, notice, actor 이미지 전용)
// 정적인 컨텐츠 전용 URL (poster, notice, casting 이미지 전용)
private String imageUrl;

// 버킷 내 디렉토리 경로 (board, photoAlbum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,33 +132,50 @@ public PhotoAlbumResponseDTO.PerformerPhotoAlbumDTO getPhotoAlbumList(Long membe
//다음 커서 설정
List<PhotoAlbum> albums = albumPage.getContent();

// 대표 이미지 가져오기
// 사진첩 id 추출
List<Long> albumIds = albums.stream()
.map(PhotoAlbum::getId)
.toList();

Map<Long, Image> albumImageMap = imageRepository.findFirstByContentIds(albumIds, FilePath.photoAlbum)
.stream()
.collect(Collectors.toMap(Image::getContentId, Function.identity()));

// 대표 이미지 가져오기
Map<Long, Image> albumImageMap =
imageRepository.findFirstByContentIds(albumIds, FilePath.photoAlbum)
.stream()
.collect(Collectors.toMap(
Image::getContentId,
Function.identity(),
(a, b) -> a
));


Map<Long, ImageResponseDTO.ImageResultWithPresignedUrlDTO> imageDtoMap =
albumImageMap.isEmpty()
? Collections.emptyMap()
: imageService.getImages(
albumImageMap.values().stream().toList(),
memberId
)
.stream()
.collect(Collectors.toMap(
ImageResponseDTO.ImageResultWithPresignedUrlDTO::getContentId,
Function.identity(),
(a, b) -> a
));

// DTO 변환
List<PhotoAlbumResponseDTO.SinglePhotoAlbumDTO> singlePhotoAlbumDTOs = albums.stream()
.map(album -> {
Image coverImage = albumImageMap.get(album.getId());
return PhotoAlbumResponseDTO.SinglePhotoAlbumDTO.builder()
.photoAlbumId(album.getId())
.amateurShowName(album.getAmateurShow().getName())
.performerName(performer.getName())
.detailAddress(album.getAmateurShow().getDetailAddress())
.imageResultWithPresignedUrlDTO(
coverImage != null
? imageService.getImages(List.of(coverImage), memberId).get(0)
: null
)
.build();
})
.toList();
List<PhotoAlbumResponseDTO.SinglePhotoAlbumDTO> singlePhotoAlbumDTOs =
albums.stream()
.map(album -> PhotoAlbumResponseDTO.SinglePhotoAlbumDTO.builder()
.photoAlbumId(album.getId())
.amateurShowName(album.getAmateurShow().getName())
.performerName(performer.getName())
.detailAddress(album.getAmateurShow().getDetailAddress())
.imageResultWithPresignedUrlDTO(
imageDtoMap.get(album.getId())
)
.build()
)
.toList();

boolean hasNext = albumPage.hasNext();
Integer nextPage = hasNext ? page + 1 : null;
Expand Down
Loading