Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -13,7 +13,7 @@
@Repository
public interface ExhibitRepositoryCustom {

Slice<Exhibit> findExhibitByFilters(ExhibitFilterRequest filter, Pageable pageable, Long cursorId);
Slice<Exhibit> findExhibitByFilters(ExhibitFilterRequest filter, Long size, Long cursorId);

List<HomeListResponse> findRandomExhibits(RandomExhibitRequest condition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ExhibitRepositoryImpl implements ExhibitRepositoryCustom{
private final JPAQueryFactory queryFactory;

@Override
public Slice<Exhibit> findExhibitByFilters(ExhibitFilterRequest dto, Pageable pageable, Long cursorId) {
public Slice<Exhibit> findExhibitByFilters(ExhibitFilterRequest dto, Long size, Long cursorId) {

QExhibit e = QExhibit.exhibit;
QExhibitHall h = QExhibitHall.exhibitHall;
Expand Down Expand Up @@ -74,16 +74,18 @@ public Slice<Exhibit> findExhibitByFilters(ExhibitFilterRequest dto, Pageable pa
styleIn(dto.getStyles())
)
.orderBy(sortFilter(dto, e, f))
.limit(pageable.getPageSize() + 1)
.limit(size+1)
.groupBy(e.exhibitId)
.fetch();


boolean hasNext = content.size() > pageable.getPageSize();
if (hasNext) content.remove(pageable.getPageSize());
boolean hasNext = content.size() > size;

return new SliceImpl<>(content, pageable, hasNext);
}
if (hasNext)
content.remove(size.intValue());

return new SliceImpl<>(content, PageRequest.of(0, size.intValue()), hasNext);
}// 페이지 개념은 사용 x

@Override
public List<HomeListResponse> findRandomExhibits(RandomExhibitRequest c) {
Expand Down Expand Up @@ -127,18 +129,19 @@ public List<HomeListResponse> findRandomExhibits(RandomExhibitRequest c) {

private BooleanExpression cursorCondition(Exhibit cursor, long cursorFavoriteCount, SortType sortType, QExhibit e, QFavoriteExhibit f) {
if (cursor == null) return null;
if (sortType == null) sortType = SortType.LATEST;

return switch (sortType) {

case POPULAR -> f.favoriteId.count().loe(cursorFavoriteCount)
case POPULAR -> f.favoriteId.count().loe(cursorFavoriteCount)//<=
.or(f.favoriteId.count().eq(cursorFavoriteCount)
.and(e.exhibitId.lt(cursor.getExhibitId())));
.and(e.exhibitId.lt(cursor.getExhibitId())));//<

case LATEST -> e.createdAt.lt(cursor.getCreatedAt())
.or(e.createdAt.eq(cursor.getCreatedAt())
case LATEST -> e.startDate.lt(cursor.getStartDate())
.or(e.startDate.eq(cursor.getStartDate())
.and(e.exhibitId.lt(cursor.getExhibitId())));

case ENDING_SOON -> e.endDate.gt(cursor.getEndDate())
default -> e.endDate.gt(cursor.getEndDate())
.or(e.endDate.eq(cursor.getEndDate())
.and(e.exhibitId.lt(cursor.getExhibitId())));
};
Expand All @@ -147,23 +150,24 @@ private BooleanExpression cursorCondition(Exhibit cursor, long cursorFavoriteCo
private OrderSpecifier<?>[] sortFilter(ExhibitFilterRequest dto, QExhibit e, QFavoriteExhibit f) {

if (dto.getSortType() == null) {
return new OrderSpecifier[]{e.createdAt.desc()};
return new OrderSpecifier[]{e.startDate.desc(), e.exhibitId.desc()};
}

switch (dto.getSortType()) {
case POPULAR:
return new OrderSpecifier[]{
f.favoriteId.count().desc().nullsLast(), // 인기순
e.createdAt.desc() // 동률일 때 최신순
f.favoriteId.count().desc().nullsLast(),
e.exhibitId.desc()
};

// case LATEST:
// return new OrderSpecifier[]{e.createdAt.desc()};
case ENDING_SOON:
return new OrderSpecifier[]{e.endDate.asc()};
return new OrderSpecifier[]{
e.endDate.asc(),
e.exhibitId.desc()
};

default:
return new OrderSpecifier[]{e.createdAt.desc()};
return new OrderSpecifier[]{e.startDate.desc(),e.exhibitId.desc()};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public ResponseEntity<CommonResponse<List<RegionResponse>>> getDomestic2(){
@PostMapping("/filter")
public ResponseEntity<FilterResponse> getDomesticFilter(@RequestBody ExhibitFilterRequest dto,
@RequestParam(required = false) Long cursor,
@PageableDefault(size = 20) Pageable pageable,
@RequestParam(defaultValue = "20") Long size,
@AuthenticationPrincipal UserDetails userDetails) {
Long userId = getUserId(userDetails);
FilterResponse exhibits = homeService.getFilterExhibit(dto, pageable, cursor,userId);
FilterResponse exhibits = homeService.getFilterExhibit(dto, size, cursor,userId);

return ResponseEntity.ok(exhibits);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.atdev.artrip.domain.exhibit.web.dto.response;


import lombok.Builder;
import lombok.Getter;
import org.atdev.artrip.domain.exhibit.data.Exhibit;

import java.util.List;

@Getter
@Builder
public class ExhibitFilterResponse {
private List<Exhibit> content;
private Long nextCursorId;
private boolean hasNext;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public FilterResponse toFilterResponse(Slice<Exhibit> slice, Set<Long> favorites
.map(exhibit -> toHomeExhibitListResponse(exhibit, favorites.contains(exhibit.getExhibitId())))
.toList();

Long nextCursor = slice.hasNext()
Long nextCursor = slice.hasNext() && !slice.isEmpty()
? slice.getContent().get(slice.getContent().size() - 1).getExhibitId()
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -83,9 +82,9 @@ public List<RegionResponse> getRegions() {


//필터 전체 조회
public FilterResponse getFilterExhibit(ExhibitFilterRequest dto, Pageable pageable, Long cursorId, Long userId) {
public FilterResponse getFilterExhibit(ExhibitFilterRequest dto, Long size, Long cursorId, Long userId) {

Slice<Exhibit> slice = exhibitRepository.findExhibitByFilters(dto, pageable, cursorId);
Slice<Exhibit> slice = exhibitRepository.findExhibitByFilters(dto, size, cursorId);
Set<Long> favoriteIds = getFavoriteIds(userId);
return homeConverter.toFilterResponse(slice, favoriteIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Slice<Review> findByUserIdAndIdLessThan(@Param("userId") Long userId,
Pageable pageable);

@Query("select r from Review r where r.exhibit.exhibitId = :exhibitId order by r.reviewId desc")
Slice<Review> findTopByExhibitId(@Param("exhibitId") Long exhibitId, Pageable pageable);
Slice<Review> findByExhibitId(@Param("exhibitId") Long exhibitId, Pageable pageable);

@Query("select r from Review r where r.exhibit.exhibitId = :exhibitId and r.reviewId < :cursor order by r.reviewId desc")
Slice<Review> findByExhibitIdAndIdLessThan(@Param("exhibitId") Long exhibitId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public ExhibitReviewSliceResponse getExhibitReview(Long exhibitId, Long cursor,
Slice<Review> slice;

if (cursor == null) {
slice = reviewRepository.findTopByExhibitId(exhibitId, PageRequest.ofSize(size));
slice = reviewRepository.findByExhibitId(exhibitId, PageRequest.ofSize(size));
} else {
slice = reviewRepository.findByExhibitIdAndIdLessThan(exhibitId, cursor, PageRequest.ofSize(size));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.atdev.artrip.domain.keyword.service.KeywordService;
import org.atdev.artrip.domain.keyword.web.dto.KeywordRequest;
import org.atdev.artrip.domain.user.service.UserService;
import org.atdev.artrip.domain.user.web.dto.request.NicknameRequest;
import org.atdev.artrip.domain.user.web.dto.response.MypageResponse;
import org.atdev.artrip.domain.user.web.dto.response.NicknameResponse;
import org.atdev.artrip.global.apipayload.CommonResponse;
import org.atdev.artrip.global.apipayload.code.status.CommonError;
import org.atdev.artrip.global.apipayload.code.status.KeywordError;
import org.atdev.artrip.global.apipayload.code.status.UserError;
import org.atdev.artrip.global.s3.web.dto.request.ImageResizeRequest;
import org.atdev.artrip.global.swagger.ApiErrorResponses;
Expand Down
Loading