Skip to content

Commit

Permalink
feat : 검색 반경 설정 #66
Browse files Browse the repository at this point in the history
- 음식점 이름을 통한 검색 시 검색 반경에 따라 필터링 되도록 구현
  • Loading branch information
LeeTH916 committed Nov 23, 2023
1 parent bc192a7 commit 1bcf4cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions be/src/restaurant/restaurant.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ export class RestaurantRepository extends Repository<RestaurantInfoEntity> {

async searchRestarant(searchInfoDto: SearchInfoDto) {
const rawQuery = `
SELECT *,
ST_DistanceSphere(
location,
ST_GeomFromText('POINT(${searchInfoDto.longitude} ${searchInfoDto.latitude})', 4326)
) AS distance
FROM restaurant
WHERE name LIKE '%${searchInfoDto.partialName}%'
ORDER BY location <-> ST_GeomFromText('POINT(${searchInfoDto.longitude} ${searchInfoDto.latitude})', 4326)
SELECT * FROM (
SELECT *,
ST_DistanceSphere(
location,
ST_GeomFromText('POINT(${searchInfoDto.longitude} ${searchInfoDto.latitude})', 4326)
) AS distance
FROM restaurant
) AS subquery
WHERE name LIKE '%${searchInfoDto.partialName}%' AND distance < ${searchInfoDto.radius}
ORDER BY location <-> ST_GeomFromText('POINT(${searchInfoDto.longitude} ${searchInfoDto.latitude})', 4326)
`
return this.query(rawQuery)
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/restaurant/restaurant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const key = "api키 입력하세요";
@Injectable()
export class RestaurantService implements OnModuleInit {
onModuleInit() {
this.updateRestaurantsFromSeoulData();
//this.updateRestaurantsFromSeoulData();
setInterval(
() => {
this.updateRestaurantsFromSeoulData();
Expand Down

0 comments on commit 1bcf4cf

Please sign in to comment.