Skip to content

Commit

Permalink
Feat: Add GET place list by user API
Browse files Browse the repository at this point in the history
- 특정 지도 내에 특정 유저가 등록한 맛집 리스트 조회 API 추가
  • Loading branch information
sally0226 committed Sep 29, 2024
1 parent 8ef2234 commit 8c42d0e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 30 deletions.
13 changes: 13 additions & 0 deletions src/place/place.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlaceForMapResponseDto[]> {
return this.placeService.getPlaceByUserId(mapId, userId);
}

@ApiOperation({ summary: '카카오 place id로 장소 등록' })
@ApiParam({ name: 'mapId', description: '지도(GroupMap) id' })
@ApiParam({ name: 'kakaoPlaceId', description: '카카오 place id' })
Expand Down
80 changes: 50 additions & 30 deletions src/place/place.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export class PlaceService {
* map id (GroupMap.id)에 속한 장소를 전부 가져옵니다.
* TODO: 나중에 커지면 geo-query + pagination 해야할듯
*/
async getAllPlacesForMap(
{ mapId }: { mapId: string },
): Promise<PlaceForMapResponseDto[]> {
async getAllPlacesForMap({
mapId,
}: {
mapId: string;
}): Promise<PlaceForMapResponseDto[]> {
const placesForMapList = await this.placeForMapRepository.find(
{
map: rel(GroupMap, mapId),
Expand All @@ -74,7 +76,10 @@ export class PlaceService {
);
}

async findUserLikePlace(mapId: string, userId: number) {
async findUserLikePlace(
mapId: string,
userId: number,
): Promise<PlaceForMapResponseDto[]> {
const placeForMap = await this.placeForMapRepository.find(
{
likedUser: rel(User, userId),
Expand Down Expand Up @@ -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),
});
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -305,4 +306,23 @@ export class PlaceService {

await this.placeForMapRepository.removeAndFlush(placeForMap);
}

async getPlaceByUserId(
mapId: string,
userId: number,
): Promise<PlaceForMapResponseDto[]> {
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),
);
}
}

0 comments on commit 8c42d0e

Please sign in to comment.