Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import { FolderComplexModule } from './folder-complex/folder-complex.module';
TripModule,
FolderModule,
CollectionModule,
CrawlingModule,
//CrawlingModule,
CollectionComplexModule,
PlaceComplexModule,
FolderComplexModule,
Expand Down
21 changes: 21 additions & 0 deletions src/place/dtos/paginated-places-list-res.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
CursorPaginationMeta,
} from 'src/common/utils/cursor-pagination.util';
import { IeumCategory } from 'src/common/enums/ieum-category.enum';
import {
createNormalList,
NormalListMeta,
} from 'src/common/utils/normal-list.util';

export class PlaceInfoDto {
@ApiProperty()
Expand Down Expand Up @@ -57,3 +61,20 @@ export class PlacesListResDto {
this.items = items;
}
}

export class PlacesListNoPaginationResDto {
@ApiProperty()
meta: NormalListMeta<RawPlaceInfo>; //GET /collections에서 정의한 listMeta 재활용
@ApiProperty({ type: [PlaceInfoDto] })
items: PlaceInfoDto[];

constructor(rawData: RawPlaceInfo[]) {
const { meta, items } = createNormalList(
rawData,
(item) => new PlaceInfoDto(item),
);

this.meta = meta;
this.items = items;
}
}
19 changes: 19 additions & 0 deletions src/place/dtos/rec-places-list-req.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsInt } from 'class-validator';

export class RecommendedPlacesListReqDto {
@ApiProperty()
@Type(() => Number)
@IsInt()
userId: number;

@ApiProperty()
@Transform(({ value }) => (typeof value === 'number' ? [value] : value))
placeIds: number[];

@ApiProperty()
@Type(() => Number)
@IsInt()
numPlaceRec: number;
}
14 changes: 14 additions & 0 deletions src/place/dtos/rec-schedule-req.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsInt } from 'class-validator';

export class RecommendedScheduleReqDto {
@ApiProperty()
@Transform(({ value }) => (typeof value === 'number' ? [value] : value))
placeIds: number[];

@ApiProperty()
@Type(() => Number)
@IsInt()
numCluster: number;
}
21 changes: 21 additions & 0 deletions src/place/repositories/place.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { Place } from 'src/place/entities/place.entity';
import { DataSource, Repository } from 'typeorm';
import { KakaoLocalSearchRes } from 'src/common/interfaces/kakao-local-search-res.interface';
import { RawPlaceInfo } from 'src/common/interfaces/raw-place-info.interface';

@Injectable()
export class PlaceRepository extends Repository<Place> {
Expand Down Expand Up @@ -47,6 +48,26 @@ export class PlaceRepository extends Repository<Place> {
return placePreviewInfo;
}

async getPlacePreviewInfoByIds(placeIds: number[]): Promise<RawPlaceInfo[]> {
const placePreviewInfoList = await this.createQueryBuilder('place')
.leftJoinAndSelect('place.placeTags', 'placeTag')
.leftJoinAndSelect('placeTag.tag', 'tag')
.leftJoinAndSelect('place.placeImages', 'placeImage')
.select([
'place.id AS id',
'place.name AS name',
'place.address AS address',
'place.primary_category AS primary_category ',
'ARRAY_AGG(placeImage.url ORDER BY placeImage.id DESC) AS "image_urls"',
])
.where('place.id IN (:...placeIds)', { placeIds })
.groupBy('place.id')
.orderBy('place.id', 'DESC')
.getRawMany();

return placePreviewInfoList;
}

async getPlacesByPlaceName(placeName: string): Promise<Place[]> {
const places = await this.createQueryBuilder('place')
.select(['place.id', 'place.name'])
Expand Down
33 changes: 33 additions & 0 deletions src/place/services/place.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { addressSimplifier } from 'src/common/utils/address-simplifier.util';
import { GooglePlacesApiPlaceDetailsRes } from 'src/common/interfaces/google-places-api.interface';
import { KakaoCategoryMappingService } from './kakao-category-mapping.service';
import { IeumCategory } from 'src/common/enums/ieum-category.enum';
import { PlacesListNoPaginationResDto } from '../dtos/paginated-places-list-res.dto';
import { RecommendedPlacesListReqDto } from '../dtos/rec-places-list-req.dto';

@Injectable()
export class PlaceService {
Expand Down Expand Up @@ -91,6 +93,14 @@ export class PlaceService {

return placePhoto.data;
}

// --------- 외부 API 호출: AI 서버 ---------
async getRecommendedPlacesIds(
recommendedPlacesListReqDto: RecommendedPlacesListReqDto,
) {}

async getRecommendedSchedule() {}

// --------- 주요 메서드 ---------
@Transactional()
async createPlaceDetailByGooglePlacesApi(placeId: number) {
Expand Down Expand Up @@ -197,6 +207,29 @@ export class PlaceService {
return new PlacePreviewResDto(place, ieumCategory);
}

async getPlacePreviewInfoByIds(
placeIds: number[],
): Promise<PlacesListNoPaginationResDto> {
//빈 배열 처리.
if (placeIds.length == 0) {
return new PlacesListNoPaginationResDto([]);
}

const rawPlacesInfoList =
await this.placeRepository.getPlacePreviewInfoByIds(placeIds);

await Promise.all(
rawPlacesInfoList.map(async (placeInfo) => {
placeInfo.ieumCategory = await this.getIeumCategoryByKakaoCategory(
placeInfo.primary_category,
);
return placeInfo; // 이 반환값은 실제로 사용되지 않지만, 명시적으로 표현
}),
);

return new PlacesListNoPaginationResDto(rawPlacesInfoList);
}

async getPlacesByPlaceName(placeName: string): Promise<Place[]> {
return await this.placeRepository.getPlacesByPlaceName(placeName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/trip/trip.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller } from '@nestjs/common';

@Controller('trip')
@Controller('trips')
export class TripController {}