From 8c42d0ee7c5c3c2968539f2f86c160ca1c9868b4 Mon Sep 17 00:00:00 2001 From: daisy-kim Date: Sun, 29 Sep 2024 23:02:14 +0900 Subject: [PATCH] Feat: Add GET place list by user API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 특정 지도 내에 특정 유저가 등록한 맛집 리스트 조회 API 추가 --- src/place/place.controller.ts | 13 ++++++ src/place/place.service.ts | 80 ++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/place/place.controller.ts b/src/place/place.controller.ts index 4455f24..4417cef 100644 --- a/src/place/place.controller.ts +++ b/src/place/place.controller.ts @@ -75,6 +75,19 @@ export class PlaceController { return this.placeService.getDifference(mapId, userId, user.id); } + @ApiOperation({ summary: '특정 유저가 특정 지도에 등록한 맛집 목록 조회' }) + @ApiOkResponse({ type: PlaceForMapResponseDto, isArray: true }) + @Get(':mapId/:userId') + @UseMapRoleGuard() + @ApiBearerAuth() + @UseAuthGuard([UserRole.USER]) + async getPlacesByUser( + @Param('mapId') mapId: string, + @Param('userId') userId: number, + ): Promise { + return this.placeService.getPlaceByUserId(mapId, userId); + } + @ApiOperation({ summary: '카카오 place id로 장소 등록' }) @ApiParam({ name: 'mapId', description: '지도(GroupMap) id' }) @ApiParam({ name: 'kakaoPlaceId', description: '카카오 place id' }) diff --git a/src/place/place.service.ts b/src/place/place.service.ts index a1515aa..72725fa 100644 --- a/src/place/place.service.ts +++ b/src/place/place.service.ts @@ -52,9 +52,11 @@ export class PlaceService { * map id (GroupMap.id)에 속한 장소를 전부 가져옵니다. * TODO: 나중에 커지면 geo-query + pagination 해야할듯 */ - async getAllPlacesForMap( - { mapId }: { mapId: string }, - ): Promise { + async getAllPlacesForMap({ + mapId, + }: { + mapId: string; + }): Promise { const placesForMapList = await this.placeForMapRepository.find( { map: rel(GroupMap, mapId), @@ -74,7 +76,10 @@ export class PlaceService { ); } - async findUserLikePlace(mapId: string, userId: number) { + async findUserLikePlace( + mapId: string, + userId: number, + ): Promise { const placeForMap = await this.placeForMapRepository.find( { likedUser: rel(User, userId), @@ -120,19 +125,17 @@ export class PlaceService { ); } - async registerPlaceByKakaoId( - { - kakaoPlaceId, - mapId, - user, - registerPlaceDto, - }: { - kakaoPlaceId: number; - mapId: string; - user: User; - registerPlaceDto: RegisterPlaceDto; - }, - ) { + async registerPlaceByKakaoId({ + kakaoPlaceId, + mapId, + user, + registerPlaceDto, + }: { + kakaoPlaceId: number; + mapId: string; + user: User; + registerPlaceDto: RegisterPlaceDto; + }) { let place = await this.placeRepository.findOne({ kakaoPlace: rel(KakaoPlace, kakaoPlaceId), }); @@ -242,19 +245,17 @@ export class PlaceService { return new PlaceResponseDto(place as unknown as PlaceForMap); } - async likePlace( - { - mapId, - placeId, - user, - like, - }: { - mapId: string; - placeId: number; - user: User; - like: boolean; - }, - ) { + async likePlace({ + mapId, + placeId, + user, + like, + }: { + mapId: string; + placeId: number; + user: User; + like: boolean; + }) { const placeForMap = await this.placeForMapRepository.findOneOrFail( { place: rel(Place, placeId), @@ -305,4 +306,23 @@ export class PlaceService { await this.placeForMapRepository.removeAndFlush(placeForMap); } + + async getPlaceByUserId( + mapId: string, + userId: number, + ): Promise { + const placeForMap: PlaceForMap[] = await this.placeForMapRepository.find( + { + createdBy: rel(User, userId), + map: rel(GroupMap, mapId), + }, + { + populate: ['place', 'place.kakaoPlace', 'tags', 'likedUser'], + }, + ); + + return placeForMap.map( + (place: PlaceForMap) => new PlaceForMapResponseDto(place), + ); + } }