Skip to content

Commit

Permalink
Feat: 공연마감순
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosiee committed May 20, 2024
1 parent c55a36e commit be8e204
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,21 +31,41 @@ public class CulturalEventRepositoryImpl implements CulturalEventRepositoryCusto

@Override
public List<CulturalEvent> getCulturalEventList(int page, int size, List<CategoryTitle> 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<CulturalEvent> 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<Long> recommendOrdering = requestRecommend(latitude, longitude, getMemberCulturalEventList()); // [200L, 201L, 202L, ...]
OrderSpecifier<Double> 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<Long> recommendOrdering = requestRecommend(latitude, longitude, getMemberCulturalEventList()); // [200L, 201L, 202L, ...]
// OrderSpecifier<Double> orderSpecifier = createWeightOrderSpecifier(recommendOrdering);
// culturalEventJPAQuery.orderBy(orderSpecifier);
}
}

Expand All @@ -56,21 +79,10 @@ public List<CulturalEvent> getCulturalEventList(int page, int size, List<Categor
}

// category 있을 경우
if (!(categories.isEmpty() || categories.contains(CategoryTitle.ALL))) {
if (!(categories == null || categories.contains(CategoryTitle.ALL))) {
culturalEventJPAQuery.where(culturalEvent.culturalEventCategory.title.in(categories));
}

// 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))
);
}

// page, size 적용
Pageable pageable = PageRequest.of(page, size);
culturalEventJPAQuery.offset(pageable.getOffset());
Expand Down

0 comments on commit be8e204

Please sign in to comment.