diff --git a/src/main/java/com/daon/onjung/account/application/service/ReadStoreDetailService.java b/src/main/java/com/daon/onjung/account/application/service/ReadStoreDetailService.java index 7bbdc6f..34942cb 100644 --- a/src/main/java/com/daon/onjung/account/application/service/ReadStoreDetailService.java +++ b/src/main/java/com/daon/onjung/account/application/service/ReadStoreDetailService.java @@ -69,7 +69,7 @@ public ReadStoreDetailResponseDto execute(Long id) { totalShareCount ); - List storeHistories = storeHistoryRepository.findByStoreOrderByActionDateDesc(store); + List storeHistories = storeHistoryRepository.findByStoreSortedByActionDate(store); // 그룹화: actionDate를 기준으로 그룹화 Map> groupedByYearMonth = storeHistories.stream() @@ -79,11 +79,13 @@ public ReadStoreDetailResponseDto execute(Long id) { List storeHistoryDtos = groupedByYearMonth.entrySet().stream() - .sorted(Map.Entry.comparingByKey()) + .sorted((e1, e2) -> e2.getKey().compareTo(e1.getKey())) // 키(yearMonth)를 기준으로 내림차순 정렬 .map(entry -> { String yearMonth = entry.getKey(); + + // 그룹화된 리스트를 actionDate 기준으로 내림차순 정렬 List infos = entry.getValue().stream() - .sorted(Comparator.comparing(StoreHistory::getActionDate)) // 그룹 안에서 시간순 정렬 + .sorted((sh1, sh2) -> sh2.getActionDate().compareTo(sh1.getActionDate())) // actionDate 기준 정렬 .map(ReadStoreDetailResponseDto.StoreHistoryDto::fromEntity) // StoreHistory -> StoreHistoryDto 변환 .flatMap(dto -> dto.getStoreHistoryInfo().stream()) // StoreHistoryInfo만 추출 .toList(); @@ -95,6 +97,7 @@ public ReadStoreDetailResponseDto execute(Long id) { }) .toList(); + return ReadStoreDetailResponseDto.fromEntity(storeInfoDto, eventInfoDto, onjungInfoDto, storeHistoryDtos); } diff --git a/src/main/java/com/daon/onjung/account/repository/mysql/StoreHistoryRepository.java b/src/main/java/com/daon/onjung/account/repository/mysql/StoreHistoryRepository.java index 7215959..451793d 100644 --- a/src/main/java/com/daon/onjung/account/repository/mysql/StoreHistoryRepository.java +++ b/src/main/java/com/daon/onjung/account/repository/mysql/StoreHistoryRepository.java @@ -2,12 +2,15 @@ import com.daon.onjung.account.domain.Store; import com.daon.onjung.account.domain.StoreHistory; +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface StoreHistoryRepository extends JpaRepository { - List findByStoreOrderByActionDateDesc(Store store); + @Query("SELECT sh FROM StoreHistory sh WHERE sh.store = :store ORDER BY sh.actionDate DESC") + List findByStoreSortedByActionDate(@Param("store") Store store); } diff --git a/src/main/java/com/daon/onjung/event/application/service/ReadOnjungEventOverviewService.java b/src/main/java/com/daon/onjung/event/application/service/ReadOnjungEventOverviewService.java index 0b91918..640e6c9 100644 --- a/src/main/java/com/daon/onjung/event/application/service/ReadOnjungEventOverviewService.java +++ b/src/main/java/com/daon/onjung/event/application/service/ReadOnjungEventOverviewService.java @@ -1,7 +1,6 @@ package com.daon.onjung.event.application.service; import com.daon.onjung.account.domain.User; -import com.daon.onjung.account.repository.mysql.StoreRepository; import com.daon.onjung.account.repository.mysql.UserRepository; import com.daon.onjung.core.exception.error.ErrorCode; import com.daon.onjung.core.exception.type.CommonException; @@ -64,64 +63,64 @@ public ReadOnjungEventOverviewResponseDto execute( Onjung onjung = onjungService.createOnjung(donations, receipts, shares); - List sortedOnjungByCreatedAtDesc = onjungService.sortOnjungByCreatedAtDesc(onjung); + List sortedOnjungByCreatedAtDesc = onjungService.sortOnjungByCreatedAt(onjung); List eventDtos = sortedOnjungByCreatedAtDesc.stream() .map(entity -> { if (entity instanceof Donation donation) { - // donation 날짜가 포함된 이벤트 가져오기 + // donation 날짜가 포함된 이벤트 가져오기 Event event = eventRepository.findTopEventByStoreAndLocalDate(donation.getStore().getId(), donation.getCreatedAt().toLocalDate()) .stream() .findFirst() // 첫 번째 값만 가져옴 .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE)); return ReadOnjungEventOverviewResponseDto.EventDto.fromEntity( - ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity( - donation.getStore().getId(), - donation.getStore().getLogoImgUrl(), - donation.getStore().getTitle(), - donation.getStore().getName() - ), - DateTimeUtil.convertLocalDateTimeToSHORTKORString(donation.getCreatedAt()), - EOnjungType.fromString("DONATION"), - event.getStatus(), - DateTimeUtil.convertLocalDatesToDotSeparatedDatePeriod(event.getStartDate(), event.getEndDate()), - DateTimeUtil.convertLocalDateToDotSeparatedDateTime(event.getStoreDeliveryDate()), - DateTimeUtil.convertLocalDateToDotSeparatedDateTime(event.getTicketIssueDate()), - DateTimeUtil.convertLocalDateToDotSeparatedDateTime(event.getReportDate()) - ); + ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity( + donation.getStore().getId(), + donation.getStore().getLogoImgUrl(), + donation.getStore().getTitle(), + donation.getStore().getName() + ), + DateTimeUtil.convertLocalDateTimeToSHORTKORString(donation.getCreatedAt()), + EOnjungType.fromString("DONATION"), + event.getStatus(), + DateTimeUtil.convertLocalDatesToDotSeparatedDatePeriod(event.getStartDate(), event.getEndDate()), + DateTimeUtil.convertLocalDateToDotSeparatedDateTime(event.getStoreDeliveryDate()), + DateTimeUtil.convertLocalDateToDotSeparatedDateTime(event.getTicketIssueDate()), + DateTimeUtil.convertLocalDateToDotSeparatedDateTime(event.getReportDate()) + ); } else if (entity instanceof Receipt receipt) { return ReadOnjungEventOverviewResponseDto.EventDto.fromEntity( - ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity( - receipt.getStore().getId(), - receipt.getStore().getLogoImgUrl(), - receipt.getStore().getTitle(), - receipt.getStore().getName() - ), - DateTimeUtil.convertLocalDateTimeToSHORTKORString(receipt.getCreatedAt()), - EOnjungType.fromString("RECEIPT"), + ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity( + receipt.getStore().getId(), + receipt.getStore().getLogoImgUrl(), + receipt.getStore().getTitle(), + receipt.getStore().getName() + ), + DateTimeUtil.convertLocalDateTimeToSHORTKORString(receipt.getPaymentDate().atTime(0, 0)), + EOnjungType.fromString("RECEIPT"), EStatus.COMPLETED, DateTimeUtil.convertLocalDateToDotSeparatedDateTime(receipt.getPaymentDate()), - null, - null, - null - ); + null, + null, + null + ); } else if (entity instanceof Share share) { return ReadOnjungEventOverviewResponseDto.EventDto.fromEntity( - ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity( - share.getStore().getId(), - share.getStore().getLogoImgUrl(), - share.getStore().getTitle(), - share.getStore().getName() - ), + ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity( + share.getStore().getId(), + share.getStore().getLogoImgUrl(), + share.getStore().getTitle(), + share.getStore().getName() + ), DateTimeUtil.convertLocalDateTimeToSHORTKORString(share.getCreatedAt().atTime(0, 0)), - EOnjungType.fromString("SHARE"), + EOnjungType.fromString("SHARE"), EStatus.COMPLETED, DateTimeUtil.convertLocalDateToDotSeparatedDateTime(share.getCreatedAt()), null, null, null - ); + ); } throw new CommonException(ErrorCode.INVALID_ARGUMENT); }) diff --git a/src/main/java/com/daon/onjung/event/application/service/ReadTicketService.java b/src/main/java/com/daon/onjung/event/application/service/ReadTicketService.java index 43c7b56..4155bd5 100644 --- a/src/main/java/com/daon/onjung/event/application/service/ReadTicketService.java +++ b/src/main/java/com/daon/onjung/event/application/service/ReadTicketService.java @@ -40,7 +40,7 @@ public ReadTicketResponseDto execute( User user = userRepository.findById(accountId) .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE)); - Page ticketsPage = ticketRepository.findByUserOrderByExpirationDateDesc(user, pageable); + Page ticketsPage = ticketRepository.findByUserOrderByExpirationDateAsc(user, pageable); // dto로 변환 List ticketDtos = ticketsPage.stream() diff --git a/src/main/java/com/daon/onjung/event/repository/mysql/TicketRepository.java b/src/main/java/com/daon/onjung/event/repository/mysql/TicketRepository.java index 24d72df..3b7a71a 100644 --- a/src/main/java/com/daon/onjung/event/repository/mysql/TicketRepository.java +++ b/src/main/java/com/daon/onjung/event/repository/mysql/TicketRepository.java @@ -11,7 +11,7 @@ public interface TicketRepository extends JpaRepository { // user로 Ticket 조회, expirationDate를 ASC로 정렬 - Page findByUserOrderByExpirationDateDesc(User user, Pageable pageable); + Page findByUserOrderByExpirationDateAsc(User user, Pageable pageable); // user로 Ticket 수 조회 Long countByUser(User user);