Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/show group like #57

Merged
merged 4 commits into from
Sep 21, 2024
Merged
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/map/dtos/map-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class PublicMapResponseDto {
@ApiProperty()
description: string;

constructor(map: GroupMap & { placeCount: number; userCount: number }) {
constructor(map: PublicMapResponseDto) {
this.id = map.id;
this.name = map.name;
this.placeCount = map.placeCount;
Expand Down
2 changes: 1 addition & 1 deletion src/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class MapService {
}: {
order: ArrayElement<typeof publicMapOrder>;
name: string;
}) {
}): Promise<PublicMapResponseDto[]> {
const qb = this.placeForMapRepository.createQueryBuilder('placeForMap');
qb.select('map.*')
.leftJoin('placeForMap.map', 'map')
Expand Down
6 changes: 6 additions & 0 deletions src/place/dto/place-for-map-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ export class PlaceForMapResponseDto {
@ApiProperty()
updatedAt: Date;

@ApiProperty({ type: [User] })
likedUser: Partial<User>[];

constructor(placeForMap: PlaceForMap) {
this.place = placeForMap.place;
this.tags = placeForMap.tags
Expand All @@ -269,5 +272,8 @@ export class PlaceForMapResponseDto {
this.createdBy = new CreatedUser(placeForMap.createdBy);
this.createdAt = placeForMap.createdAt;
this.updatedAt = placeForMap.updatedAt;
this.likedUser = placeForMap.likedUser.map((v) => ({
id: v.id,
}));
}
}
30 changes: 29 additions & 1 deletion src/place/place.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@nestjs/common';
import {
ApiBearerAuth,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiResponse,
Expand All @@ -26,7 +27,7 @@ import {

import { UseAuthGuard } from '../common/decorators/auth-guard.decorator';
import { CurrentUser } from '../common/decorators/user.decorator';
import { User, UserMapRole } from '../entities';
import { User, UserMapRole, UserRole } from '../entities';
import { PlaceService } from './place.service';

@ApiTags('place')
Expand All @@ -53,6 +54,33 @@ export class PlaceController {
});
}

@Get('like/:mapId/:userId')
@ApiOperation({ summary: '특정 유저가 좋아요한 맛집을 조회합니다' })
@ApiOkResponse({ type: PlaceForMapResponseDto, isArray: true })
@UseMapRoleGuard()
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
async findUserLikePlace(
@Param('mapId') mapId: string,
@Param('userId') userId: number,
) {
return this.placeService.findUserLikePlace(mapId, userId);
}

@Get('differ/:mapId/:userId')
@ApiOperation({ summary: '취향 차이' })
@ApiOkResponse({ type: Number })
@UseMapRoleGuard()
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
async getDifference(
@Param('mapId') mapId: string,
@Param('userId') userId: number,
@CurrentUser() user: User,
) {
return this.placeService.getDifference(mapId, userId, user.id);
}

@ApiOperation({ summary: '카카오 place id로 장소 등록' })
@ApiParam({ name: 'mapId', description: '지도(GroupMap) id' })
@ApiParam({ name: 'kakaoPlaceId', description: '카카오 place id' })
Expand Down
56 changes: 55 additions & 1 deletion src/place/place.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,67 @@ export class PlaceService {
{
map: rel(GroupMap, mapId),
},
{ populate: ['place', 'place.kakaoPlace', 'createdBy', 'tags'] },
{
populate: [
'place',
'place.kakaoPlace',
'createdBy',
'tags',
'likedUser',
],
},
);
return placesForMapList.map(
(placeForMap) => new PlaceForMapResponseDto(placeForMap),
);
}

async findUserLikePlace(mapId: string, userId: number) {
const placeForMap = await this.placeForMapRepository.find(
{
likedUser: rel(User, userId),
map: rel(GroupMap, mapId),
},
{
populate: [
'place',
'place.kakaoPlace',
'createdBy',
'tags',
'likedUser',
],
},
);

return placeForMap.map((place) => new PlaceForMapResponseDto(place));
}

async getDifference(mapId: string, userId: number, myId: number) {
const youLike = await this.placeForMapRepository
.createQueryBuilder('pfm')
.select('pfm.place')
.where({
likedUser: rel(User, userId),
map: rel(GroupMap, mapId),
})
.execute();

const iLike = await this.placeForMapRepository
.createQueryBuilder('pfm')
.select('pfm.place')
.where({
likedUser: rel(User, myId),
map: rel(GroupMap, mapId),
})
.execute();

return (
(iLike.filter((v) => youLike.some((k) => k.place === v.place)).length /
iLike.length) *
100
);
}

async registerPlaceByKakaoId({
kakaoPlaceId,
mapId,
Expand Down
Loading