Skip to content

Commit

Permalink
♻️ refactor/#188 : event 조회 최적화
Browse files Browse the repository at this point in the history
Signed-off-by: EunJiJung <[email protected]>
  • Loading branch information
bianbbc87 committed Dec 6, 2024
1 parent 247ecb9 commit 895e217
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ public ReadOnjungEventOverviewResponseDto execute(
List<ReadOnjungEventOverviewResponseDto.EventDto> eventDtos = sortedOnjungByCreatedAtDesc.stream()
.map(entity -> {
if (entity instanceof Donation donation) {
// donation 날짜가 포함된 이벤트 가져오기
Event event = eventRepository.findTopEventByStoreAndLocalDate(donation.getStore().getId(), donation.getCreatedAt().toLocalDate())
.stream()
.findFirst() // 첫 번째 값만 가져옴
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE));
Event event = donation.getEvent();

return ReadOnjungEventOverviewResponseDto.EventDto.fromEntity(
ReadOnjungEventOverviewResponseDto.EventDto.StoreInfoDto.fromEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

public interface EventRepository extends JpaRepository<Event, Long> {

// 가게의 이벤트들 중에, 현재 모금중인 이벤트 하나를 반환
@Query("SELECT e FROM Event e WHERE e.store.id = :storeId AND e.status = 'IN_PROGRESS'")
Optional<Event> findINPROGRESSEventByStoreId(@Param("storeId") Long storeId);

// 가게와 localdate로 event의 start date와 end date 사이에 있는 이벤트를 반환
@Query("SELECT e FROM Event e WHERE e.store.id = :store AND e.startDate <= :date AND e.endDate >= :date ORDER BY e.id ASC")
List<Event> findTopEventByStoreAndLocalDate(@Param("store") Long storeId, @Param("date") LocalDate date);

}

0 comments on commit 895e217

Please sign in to comment.