diff --git a/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java b/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java index 9e63cd6..d5e610b 100644 --- a/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java +++ b/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java @@ -34,9 +34,9 @@ public class CulturalEventController { private final MemberJwtService memberJwtService; @ApiOperation(value = "문화생활 리스트 조회", - notes = "`ordering` : ticketOpenDate(마감 다가온 순) | -point(인기순) | updatedDate(최근순) | recommend(추천순)\n" + - "`latitude` : 입력시 반경 50km 이내 문화생활\n" + - "`longitude` : 입력시 반경 50km 이내 문화생활") + notes = "`ordering` : ticketOpenDate(오픈 다가온 순) | -point(인기순) | -updatedDate(최근순) | recommend(추천순) | endDate(공연마감순)\n" + + "`latitude` : 입력시 추천순 정렬에 반경 50km 이내 문화생활 적용\n" + + "`longitude` : 입력시 추천순 정렬에 반경 50km 이내 문화생활 적용") @GetMapping public ResponseEntity getCulturalEventList( @RequestParam(defaultValue = "0") int page, diff --git a/src/main/java/project/backend/domain/culturalevent/repository/CulturalEventRepositoryImpl.java b/src/main/java/project/backend/domain/culturalevent/repository/CulturalEventRepositoryImpl.java index 0046790..6049226 100644 --- a/src/main/java/project/backend/domain/culturalevent/repository/CulturalEventRepositoryImpl.java +++ b/src/main/java/project/backend/domain/culturalevent/repository/CulturalEventRepositoryImpl.java @@ -15,7 +15,10 @@ import project.backend.domain.member.service.MemberJwtService; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Arrays; +import java.util.Date; import java.util.List; import static project.backend.domain.culturalevent.entity.QCulturalEvent.culturalEvent; @@ -28,21 +31,41 @@ public class CulturalEventRepositoryImpl implements CulturalEventRepositoryCusto @Override public List getCulturalEventList(int page, int size, List categories, String ordering, Boolean isOpened, Double latitude, Double longitude) { + // 현재 시간 LocalDateTime now = LocalDateTime.now(); + ZonedDateTime zonedDateTime = now.atZone(ZoneId.systemDefault()); + Date dateNow = Date.from(zonedDateTime.toInstant()); + + /// Query 객체 JPAQuery culturalEventJPAQuery = queryFactory.selectFrom(culturalEvent); + // 지난 문화생활 제외 + culturalEventJPAQuery.where(culturalEvent.endDate.after(dateNow)); + // ordering 있을 경우 if (ordering != null) { if (ordering.equals("-point")) { culturalEventJPAQuery.orderBy(culturalEvent.point.desc()); } else if (ordering.equals("ticketOpenDate")) { culturalEventJPAQuery.orderBy(culturalEvent.ticketOpenDate.asc()); - } else if (ordering.equals("updatedDate")) { + } else if (ordering.equals("-updatedDate")) { culturalEventJPAQuery.orderBy(culturalEvent.updatedDate.desc()); + } else if (ordering.equals("endDate")) { + culturalEventJPAQuery.orderBy(culturalEvent.endDate.asc()); } else if (ordering.equals("recommend")) { - List recommendOrdering = requestRecommend(latitude, longitude, getMemberCulturalEventList()); // [200L, 201L, 202L, ...] - OrderSpecifier orderSpecifier = createWeightOrderSpecifier(recommendOrdering); - culturalEventJPAQuery.orderBy(orderSpecifier); + // latitude(위도), longitude(경도) 있을 경우 + if (latitude != null && longitude != null) { + double radiusInKm = 50.0; + double radiusInDegrees = radiusInKm / 111.0; + + culturalEventJPAQuery.where( + culturalEvent.place.latitude.between(latitude - radiusInDegrees, latitude + radiusInDegrees) + .and(culturalEvent.place.longitude.between(longitude - radiusInDegrees, longitude + radiusInDegrees)) + ); + } +// List recommendOrdering = requestRecommend(latitude, longitude, getMemberCulturalEventList()); // [200L, 201L, 202L, ...] +// OrderSpecifier orderSpecifier = createWeightOrderSpecifier(recommendOrdering); +// culturalEventJPAQuery.orderBy(orderSpecifier); } } @@ -56,21 +79,10 @@ public List getCulturalEventList(int page, int size, List