Skip to content

Commit

Permalink
refactor: lat, lon 네이밍을 줄이지 않고 사용하도록 변경 #163
Browse files Browse the repository at this point in the history
  • Loading branch information
koomchang committed Nov 23, 2024
1 parent 1c04daa commit 1ade903
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
4 changes: 2 additions & 2 deletions backend/src/place/place.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class PlaceService {
name: name,
rating: rating || null,
location: {
longitude: geometry.location.lng,
latitude: geometry.location.lat,
longitude: geometry.location.longitude,
latitude: geometry.location.latitude,
},
formattedAddress: formatted_address || null,
category: types?.[0] || null,
Expand Down
8 changes: 4 additions & 4 deletions backend/src/search/dto/ESPlaceSaveDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export class ESPlaceSaveDTO {
readonly thumbnailUrl: string,
readonly rating: number,
readonly location: {
lat: number;
lon: number;
latitude: number;
longitude: number;
},
readonly formattedAddress: string,
readonly category: string,
Expand All @@ -28,8 +28,8 @@ export class ESPlaceSaveDTO {
place.thumbnailUrl,
place.rating,
{
lat: place.latitude,
lon: place.longitude,
latitude: place.latitude,
longitude: place.longitude,
},
place.formattedAddress,
place.category,
Expand Down
16 changes: 11 additions & 5 deletions backend/src/search/query/ElasticSearchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ export class ElasticSearchQuery {

async searchPlace(
query: string,
lat?: number,
long?: number,
latitude?: number,
longitude?: number,
page: number = 1,
size: number = 10,
) {
const tokens = await this.tokenizeQuery(query);
const location = !isNaN(lat) && !isNaN(long) ? { lat, long: long } : null;
const location =
!isNaN(latitude) && !isNaN(longitude)
? {
latitude: latitude,
longitude: longitude,
}
: null;
const from = (page - 1) * size;
return await this.esService.search({
index: ElasticSearchConfig.PLACE_INDEX,
Expand Down Expand Up @@ -56,8 +62,8 @@ export class ElasticSearchQuery {
...(location
? [
ElasticSearchQueryBuilder.GAUSS_LOCATION(
location.lat,
location.long,
location.latitude,
location.longitude,
),
]
: []),
Expand Down
6 changes: 3 additions & 3 deletions backend/src/search/query/builder/LocationBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const LocationQueryBuilders = {
GAUSS_LOCATION: (
lat: number,
long: number,
latitude: number,
longitude: number,
scale = '10km',
offset = '2km',
decay = 0.5,
weight = 20,
) => ({
gauss: {
location: {
origin: `${lat},${long}`,
origin: `${latitude},${longitude}`,
scale: scale,
offset: offset,
decay: decay,
Expand Down
12 changes: 9 additions & 3 deletions backend/src/search/search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ export class SearchController {
@Get()
async search(
@Query('query') query: string,
@Query('lat') lat?: number,
@Query('long') long?: number,
@Query('latitude') latitude?: number,
@Query('longitude') longitude?: number,
@Query('page', new ParseOptionalNumberPipe(1)) page?: number,
@Query('limit', new ParseOptionalNumberPipe(10)) limit?: number,
) {
return await this.searchService.searchPlace(query, lat, long, page, limit);
return await this.searchService.searchPlace(
query,
latitude,
longitude,
page,
limit,
);
}
}
12 changes: 6 additions & 6 deletions backend/src/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export class SearchService {

async searchPlace(
query: string,
lat?: number,
long?: number,
latitude?: number,
longitude?: number,
page: number = 1,
size: number = 10,
) {
const searched = await this.elasticSearchQuery.searchPlace(
query,
lat,
long,
latitude,
longitude,
page,
size,
);
Expand All @@ -61,8 +61,8 @@ export class SearchService {
_source.name,
_source.location
? {
latitude: _source.location.lat,
longitude: _source.location.long,
latitude: _source.location.latitude,
longitude: _source.location.longitude,
}
: null,
_source.googlePlaceId,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/search/search.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export type PlaceSearchHit = {
id: string;
name: string;
location: {
lat: number;
long: number;
latitude: number;
longitude: number;
};
googlePlaceId: string;
category: string | null;
Expand Down

0 comments on commit 1ade903

Please sign in to comment.