Skip to content

Commit

Permalink
Merge pull request #171 from kakao-tech-campus-2nd-step3/refactor/Pla…
Browse files Browse the repository at this point in the history
…cesResponse

[refactor]: Places 조회의 Pagenation 정상화
  • Loading branch information
BaeJunH0 authored Nov 14, 2024
2 parents d6aeccd + d21dfe0 commit 4a87fe8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -41,7 +40,10 @@ public Page<Place> findPlacesByDistance(String longitude, String latitude, Pagea
.limit(pageable.getPageSize())
.fetch();

return new PageImpl<>(places, pageable, places.size());
JPAQuery<Long> countQuery = jpaQueryFactory.select(place.id.count()) // 중복 제거
.from(place);

return PageableExecutionUtils.getPage(places, pageable, countQuery::fetchOne);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ create table places
latitude text not null,
longitude text not null,
menu_img_url text null,
category enum ('CAFE', 'JAPANESE', 'KOREAN', 'NONE', 'RESTAURANT', 'WESTERN') not null
category enum ('CAFE', 'JAPANESE', 'KOREAN', 'NONE', 'RESTAURANT', 'WESTERN') not null,

FULLTEXT INDEX ft_name_ngram (name) WITH PARSER ngram,
INDEX idx_long_lat (longitude(15), latitude(15))
Expand Down

0 comments on commit 4a87fe8

Please sign in to comment.