diff --git a/src/admin/admin.controller.ts b/src/admin/admin.controller.ts index 4408193..3c49521 100644 --- a/src/admin/admin.controller.ts +++ b/src/admin/admin.controller.ts @@ -9,7 +9,12 @@ import { Patch, Post, } from '@nestjs/common'; -import { ApiBearerAuth, ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; +import { + ApiBearerAuth, + ApiCreatedResponse, + ApiOperation, + ApiTags, +} from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; import { RolesGuard } from 'src/auth/guards/roles.guard'; import { Roles } from 'src/libs/decorators/roles.decorator'; @@ -45,6 +50,9 @@ export class AdminController { ) {} @Get('/all') + @ApiOperation({ + summary: '모든 어드민을 조회합니다.', + }) @Roles([Role.Admin]) async login(@Request() req) { return await this.adminService.findAll(); @@ -54,6 +62,9 @@ export class AdminController { // 생성 @Post('/user') + @ApiOperation({ + summary: '새로운 유저를 생성합니다.', + }) @Roles([Role.Admin]) async createUser(@Body() createUserData: RequestCreateUserDto) { return await this.userService.create(createUserData); @@ -61,6 +72,9 @@ export class AdminController { // 조회 @Get('/user/all') + @ApiOperation({ + summary: '모든 유저를 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseReadAllUserDto, @@ -72,6 +86,9 @@ export class AdminController { } @Get('/user') + @ApiOperation({ + summary: '특정 유저를 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseReadUserDto }) @Roles([Role.Admin]) async getUser(@Query('user_id') userID: string) { @@ -79,10 +96,12 @@ export class AdminController { } @Get('/userAT') + @ApiOperation({ + summary: '특정 유저의 access_token을 얻을 수 있습니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetUserATDto, - description: '해당 유저의 access_token을 얻을수있습니다.', }) @Roles([Role.Admin]) async getUserAT(@Query('user_id') userID: string) { @@ -91,6 +110,9 @@ export class AdminController { // 수정 @Patch('/user') + @ApiOperation({ + summary: '특정 유저 정보를 수정합니다.', + }) @Roles([Role.Admin]) async patchUser(@Body() body: RequestUpdateUserDto) { return await this.userService.update(body.user_id, body); @@ -98,6 +120,9 @@ export class AdminController { // 삭제 @Delete('/user') + @ApiOperation({ + summary: '특정 유저를 삭제합니다.', + }) @Roles([Role.Admin]) async removeUser(@Body() body: RequestDeleteUserDto) { return await this.userService.delete(body.user_id); @@ -106,10 +131,12 @@ export class AdminController { /* Friends 제어 */ @Get('/friends/all') + @ApiOperation({ + summary: '모든 친구 관계를 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetAllFriendByAdminDto, - description: '모든 친구 요청 목록을 조회합니다.', isArray: true, }) @Roles([Role.Admin]) @@ -118,9 +145,11 @@ export class AdminController { } @Patch('/friends') + @ApiOperation({ + summary: '친구 관계를 수정합니다.', + }) @ApiCreatedResponse({ status: 200, - description: '친구 목록에서 관계를 수정합니다.', }) @Roles([Role.Admin]) async updateFriendRelation(@Body() body: RequestUpdateFriendRelationDto) { @@ -131,9 +160,11 @@ export class AdminController { } @Delete('/friends') + @ApiOperation({ + summary: '특정 친구 관계를 삭제합니다.', + }) @ApiCreatedResponse({ status: 200, - description: '특정 친구 관계를 삭제합니다.', }) @Roles([Role.Admin]) async deleteFriendRelation(@Body() body: RequestUpdateFriendRelationDto) { @@ -143,10 +174,12 @@ export class AdminController { /* Posting 제어 */ @Get('/post/all') + @ApiOperation({ + summary: '모든 우연 목록을 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetAllPostDto, - description: '모든 우연 목록을 조회합니다.', isArray: true, }) @Roles([Role.Admin]) @@ -155,9 +188,11 @@ export class AdminController { } @Patch('/post') + @ApiOperation({ + summary: '특정 우연을 수정합니다.', + }) @ApiCreatedResponse({ status: 200, - description: '특정 우연을 수정합니다.', }) @Roles([Role.Admin]) async updatePost(@Body() body: RequestUpdatePostDto) { @@ -165,6 +200,9 @@ export class AdminController { } @Delete('/post') + @ApiOperation({ + summary: '특정 우연을 삭제합니다.', + }) @ApiCreatedResponse({ status: 200, description: '특정 우연을 삭제합니다.', diff --git a/src/app.controller.ts b/src/app.controller.ts index 3b03c7a..863a860 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,26 +1,16 @@ -import { - Controller, - Request, - Get, - Logger, - Post, - UseGuards, -} from '@nestjs/common'; +import { Controller, Get } from '@nestjs/common'; +import { ApiOperation } from '@nestjs/swagger'; import { AppService } from './app.service'; -import { JwtAuthGuard } from './auth/guards/jwt-auth.guard'; @Controller() export class AppController { constructor(private readonly appService: AppService) {} @Get('healthcheck') + @ApiOperation({ + summary: 'healthcheck url 입니다.', + }) healthCheck(): string { return this.appService.getHealthCheck(); } - - @Get() - getHello(): string { - Logger.log(`${process.env.DB_URL}`); - return this.appService.getHello(); - } } diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index e8fcd8c..74c1263 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -12,7 +12,7 @@ import { } from '@nestjs/common'; import { LocalAuthGuard } from './guards/local-auth.guard'; import { AuthService } from './auth.service'; -import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; +import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; import { ResponseAdminLoginDto } from './dto/ResponseAdminLogin.dto'; import { KakaoAuthGuard } from './guards/kakao-auth.guard'; import { ResponseUserLoginDto } from './dto/ResponseUserLogin.dto'; @@ -21,12 +21,13 @@ import { Response } from 'express'; @ApiTags('auth') @Controller('auth') export class AuthController { - constructor( - private authService: AuthService - ) {} + constructor(private authService: AuthService) {} + @ApiOperation({ + summary: '어드민 로그인', + }) @Post('/admin') - @ApiCreatedResponse({ status: 200, type: ResponseAdminLoginDto , description: "어드민 로그인"}) + @ApiCreatedResponse({ status: 200, type: ResponseAdminLoginDto }) @UseGuards(LocalAuthGuard) async login( @Request() req, @@ -37,19 +38,27 @@ export class AuthController { } @Get('/kakao') - @ApiCreatedResponse({ status: 200, type: ResponseUserLoginDto, description: "유저 카카오 소셜로그인"}) + @ApiOperation({ + summary: '유저 카카오 소셜 로그인.', + }) + @ApiCreatedResponse({ status: 200, type: ResponseUserLoginDto }) @UseGuards(KakaoAuthGuard) - async kakaoLogin(){ - return HttpStatus.OK + async kakaoLogin() { + return HttpStatus.OK; } @Get('/kakao/oauth') + @ApiOperation({ + summary: '카카오 Redirect URL.', + }) @UseGuards(KakaoAuthGuard) - async kakaoRedirect(@Req() req, @Res() res: Response){ - if(req.user.email == null){ - return HttpStatus.NOT_ACCEPTABLE - } - const result = await this.authService.userLogin(req.user) - res.redirect(`${process.env.CLIENT_URL}/auth/kakao/redirect?access_token=${result.access_token}`) + async kakaoRedirect(@Req() req, @Res() res: Response) { + if (req.user.email == null) { + return HttpStatus.NOT_ACCEPTABLE; + } + const result = await this.authService.userLogin(req.user); + res.redirect( + `${process.env.CLIENT_URL}/auth/kakao/redirect?access_token=${result.access_token}`, + ); } } diff --git a/src/emotion/dto/RequestAddEmotion.dto.ts b/src/emotion/dto/RequestAddEmotion.dto.ts index 329d85b..2316862 100644 --- a/src/emotion/dto/RequestAddEmotion.dto.ts +++ b/src/emotion/dto/RequestAddEmotion.dto.ts @@ -1,11 +1,11 @@ import { ApiProperty } from '@nestjs/swagger'; export class RequestAddEmotionDto { - @ApiProperty() post_id: string; - @ApiProperty() + @ApiProperty({ + description: '(0: 좋아요, 1: 멋져요, 2: 슬퍼요)', + }) emotion_type: number; - } diff --git a/src/emotion/emotion.controller.ts b/src/emotion/emotion.controller.ts index 5459e6c..71dcf00 100644 --- a/src/emotion/emotion.controller.ts +++ b/src/emotion/emotion.controller.ts @@ -1,16 +1,22 @@ import { - Body, - Controller, - Delete, - Get, - HttpException, - HttpStatus, - Patch, - Post, - Req, - UseGuards, + Body, + Controller, + Delete, + Get, + HttpException, + HttpStatus, + Patch, + Post, + Req, + UseGuards, } from '@nestjs/common'; -import { ApiBearerAuth, ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; +import { + ApiBearerAuth, + ApiCreatedResponse, + ApiOperation, + ApiProperty, + ApiTags, +} from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; import { RolesGuard } from 'src/auth/guards/roles.guard'; import { Roles } from 'src/libs/decorators/roles.decorator'; @@ -26,64 +32,64 @@ import { RequestUpdateEmotionDto } from './dto/RequestUpdateEmotion.dto'; @Controller('emotion') @UseGuards(RolesGuard) @UseGuards(JwtAuthGuard) - export class EmotionController { + constructor(private emotionService: EmotionService) {} - constructor(private emotionService: EmotionService){} - - //add + //add - @Post() - @ApiCreatedResponse({ - status: 200, - description: '감정표현을 추가합니다.', - }) - @Roles([Role.User]) - async create(@Req() req, @Body() body: RequestAddEmotionDto) { - return await this.emotionService - .addEmotion(req.user.user_id, body.post_id, body.emotion_type) - .catch((err) => { - throw new HttpException( - { - message: err.message, - }, - HttpStatus.BAD_REQUEST, - ); - }); - } + @Post() + @ApiOperation({ + summary: '감정표현을 추가합니다.', + }) + @Roles([Role.User]) + async create(@Req() req, @Body() body: RequestAddEmotionDto) { + return await this.emotionService + .addEmotion(req.user.user_id, body.post_id, body.emotion_type) + .catch((err) => { + throw new HttpException( + { + message: err.message, + }, + HttpStatus.BAD_REQUEST, + ); + }); + } - //delete - @Delete() - @Roles([Role.User]) - async deleteEmotion(@Body() body: RequestDeleteEmotionDto) { - return await this.emotionService - .deleteEmotion(body.emotion_id) - .catch((err) => { - throw new HttpException( - { - message: err.message, - }, - HttpStatus.BAD_REQUEST, - ); - }); - } + //delete + @Delete() + @ApiOperation({ + summary: '감정표현을 삭제합니다.', + }) + @Roles([Role.User]) + async deleteEmotion(@Body() body: RequestDeleteEmotionDto) { + return await this.emotionService + .deleteEmotion(body.emotion_id) + .catch((err) => { + throw new HttpException( + { + message: err.message, + }, + HttpStatus.BAD_REQUEST, + ); + }); + } - //update - @Patch() - @Roles([Role.User]) - async updateEmotion(@Body() body: RequestUpdateEmotionDto) { - return await this.emotionService - .updateEmotion(body.emotion_id, body.emotion_type) - .catch((err) => { - throw new HttpException( - { - message: err.message, - }, - HttpStatus.BAD_REQUEST, - ); - }); - } - + //update + @Patch() + @ApiOperation({ + summary: '감정표현을 수정합니다.', + }) + @Roles([Role.User]) + async updateEmotion(@Body() body: RequestUpdateEmotionDto) { + return await this.emotionService + .updateEmotion(body.emotion_id, body.emotion_type) + .catch((err) => { + throw new HttpException( + { + message: err.message, + }, + HttpStatus.BAD_REQUEST, + ); + }); + } } - - diff --git a/src/emotion/emotion.module.ts b/src/emotion/emotion.module.ts index f799623..767a3dd 100644 --- a/src/emotion/emotion.module.ts +++ b/src/emotion/emotion.module.ts @@ -7,9 +7,9 @@ import { Posting } from 'src/posting/posting.entity'; import { User } from 'src/user/user.entity'; @Module({ - imports: [TypeOrmModule.forFeature([Emotion]), TypeOrmModule.forFeature([Posting]), TypeOrmModule.forFeature([User])], + imports: [TypeOrmModule.forFeature([Emotion, Posting, User])], controllers: [EmotionController], providers: [EmotionService], - exports: [EmotionService] + exports: [EmotionService], }) export class EmotionModule {} diff --git a/src/footprint/footprint.controller.ts b/src/footprint/footprint.controller.ts index 2f6d0d6..cf570be 100644 --- a/src/footprint/footprint.controller.ts +++ b/src/footprint/footprint.controller.ts @@ -7,7 +7,7 @@ import { Req, UseGuards, } from '@nestjs/common'; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; import { FootprintService } from './footprint.service'; import { RequestCreateFootPrintDto } from './dto/RequestCreateFootPrint.dto'; import { RolesGuard } from 'src/auth/guards/roles.guard'; @@ -25,6 +25,9 @@ export class FootprintController { // 발자국 수 추가 @Post() + @ApiOperation({ + summary: '발자국을 생성합니다.', + }) @Roles([Role.User]) async createFootPrint(@Req() req, @Body() body: RequestCreateFootPrintDto) { return await this.footprintService.addFootprint( @@ -35,6 +38,9 @@ export class FootprintController { // 발자국 수 조회 @Get() + @ApiOperation({ + summary: '발자국 수를 조회합니다.', + }) @Roles([Role.User]) async getFootprints(@Query('post_id') post_id: string) { return await this.footprintService.getFootprints(post_id); diff --git a/src/footprint/footprint.module.ts b/src/footprint/footprint.module.ts index 0a6ed0f..196185a 100644 --- a/src/footprint/footprint.module.ts +++ b/src/footprint/footprint.module.ts @@ -6,11 +6,7 @@ import { Footprint } from './footprint.entity'; import { User } from 'src/user/user.entity'; import { Posting } from 'src/posting/posting.entity'; @Module({ - imports: [ - TypeOrmModule.forFeature([Footprint]), - TypeOrmModule.forFeature([User]), - TypeOrmModule.forFeature([Posting]), - ], + imports: [TypeOrmModule.forFeature([Footprint, User, Posting])], controllers: [FootprintController], providers: [FootprintService], exports: [FootprintService], diff --git a/src/friends/friends.controller.ts b/src/friends/friends.controller.ts index 502e8da..6bf8161 100644 --- a/src/friends/friends.controller.ts +++ b/src/friends/friends.controller.ts @@ -10,7 +10,12 @@ import { Req, UseGuards, } from '@nestjs/common'; -import { ApiBearerAuth, ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; +import { + ApiBearerAuth, + ApiCreatedResponse, + ApiOperation, + ApiTags, +} from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; import { RolesGuard } from 'src/auth/guards/roles.guard'; import { Roles } from 'src/libs/decorators/roles.decorator'; @@ -34,10 +39,12 @@ export class FriendsController { constructor(private friendsService: FriendsService) {} @Post() + @ApiOperation({ + summary: '친구 신청을 합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseCreateFriendDto, - description: '친구 신청을 합니다.', }) @Roles([Role.User]) async create(@Req() req, @Body() body: RequestCreateFriendDto) { @@ -54,10 +61,12 @@ export class FriendsController { } @Get() + @ApiOperation({ + summary: '모든 친구를 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetAllFriendDto, - description: '모든 친구를 조회합니다.', }) @Roles([Role.User]) async getAllFriend(@Req() req) { @@ -74,6 +83,9 @@ export class FriendsController { } @Post('/accept') + @ApiOperation({ + summary: '친구요청을 수락합니다.', + }) @Roles([Role.User]) async acceptFriendRequest(@Req() req, @Body() body: RequestAcceptFriendDto) { return await this.friendsService @@ -89,6 +101,9 @@ export class FriendsController { } @Post('/decline') + @ApiOperation({ + summary: '친구요청을 거절합니다.', + }) @Roles([Role.User]) async declineFriendRequest( @Req() req, @@ -107,10 +122,12 @@ export class FriendsController { } @Get('/request') + @ApiOperation({ + summary: '받은 친구요청 목록을 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetFriendRequestDto, - description: '받은 친구요청 목록을 조회합니다.', isArray: true, }) @Roles([Role.User]) @@ -128,10 +145,12 @@ export class FriendsController { } @Get('/requested') + @ApiOperation({ + summary: '보낸 친구요청 목록을 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetRequestFriendListDto, - description: '보낸 친구요청 목록을 조회합니다.', isArray: true, }) @Roles([Role.User]) @@ -149,6 +168,9 @@ export class FriendsController { } @Delete() + @ApiOperation({ + summary: '친구를 삭제합니다.', + }) @Roles([Role.User]) async deleteFriend(@Req() req, @Body() body: RequestDeleteFriendDto) { return await this.friendsService diff --git a/src/friends/friends.module.ts b/src/friends/friends.module.ts index 770b179..ab96f65 100644 --- a/src/friends/friends.module.ts +++ b/src/friends/friends.module.ts @@ -6,10 +6,7 @@ import { Friends } from './friends.entity'; import { User } from 'src/user/user.entity'; @Module({ - imports: [ - TypeOrmModule.forFeature([Friends]), - TypeOrmModule.forFeature([User]), - ], + imports: [TypeOrmModule.forFeature([Friends, User])], controllers: [FriendsController], providers: [FriendsService], exports: [FriendsService], diff --git a/src/posting/dto/ResponseGetOnePost.dto.ts b/src/posting/dto/ResponseGetOnePost.dto.ts index d127ba7..275515f 100644 --- a/src/posting/dto/ResponseGetOnePost.dto.ts +++ b/src/posting/dto/ResponseGetOnePost.dto.ts @@ -8,6 +8,14 @@ class Image { img_url: string; } +class Emotion { + @ApiProperty() + emotion_id: string; + + @ApiProperty() + emotion_type: number; +} + export class ResponseGetOnePostDto { @ApiProperty() post_id: string; @@ -26,6 +34,21 @@ export class ResponseGetOnePostDto { @ApiProperty() longitude: number; + + @ApiProperty() + like_count: number; + + @ApiProperty() + cool_count: number; + + @ApiProperty() + sad_count: number; + + @ApiProperty({ + type: Emotion, + }) + emotion: Emotion; + @ApiProperty({ type: Image, isArray: true, diff --git a/src/posting/posting.controller.ts b/src/posting/posting.controller.ts index 1b6611c..d3bd9de 100644 --- a/src/posting/posting.controller.ts +++ b/src/posting/posting.controller.ts @@ -19,6 +19,7 @@ import { ApiBody, ApiConsumes, ApiCreatedResponse, + ApiOperation, ApiTags, } from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; @@ -47,6 +48,9 @@ export class PostingController { // } @Post() + @ApiOperation({ + summary: '우연을 생성합니다.', + }) @ApiConsumes('multipart/form-data') @ApiBody({ schema: { @@ -99,10 +103,12 @@ export class PostingController { } @Get() + @ApiOperation({ + summary: '하나의 우연을 조회합니다. 반경 50m 안에 있어야됩니댜..', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetOnePostDto, - description: '하나의 우연을 조회합니다. 반경 50m 안에 있어야됩니댜.', }) @Roles([Role.User]) async getOnePost( @@ -125,10 +131,12 @@ export class PostingController { } @Get('/near') + @ApiOperation({ + summary: '반경 500m 이내의 우연들을 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetPostByLocation, - description: '반경 500m 이내의 우연들을 조회합니다.', }) @Roles([Role.User]) async getPostByLocation( @@ -150,6 +158,9 @@ export class PostingController { } @Delete() + @ApiOperation({ + summary: '우연을 삭제합니다.', + }) @Roles([Role.User]) async deletePost(@Body() body: RequestDeletePostingDto, @Req() req) { const user_id = req.user.user_id; diff --git a/src/posting/posting.module.ts b/src/posting/posting.module.ts index 8974aa1..e1f4824 100644 --- a/src/posting/posting.module.ts +++ b/src/posting/posting.module.ts @@ -7,13 +7,16 @@ import { MulterModule } from '@nestjs/platform-express'; import { S3Module } from 'src/s3/s3.module'; import { UserModule } from 'src/user/user.module'; import { FootprintModule } from 'src/footprint/footprint.module'; +import { EmotionModule } from 'src/emotion/emotion.module'; +import { Emotion } from 'src/emotion/emotion.entity'; @Module({ imports: [ - TypeOrmModule.forFeature([Posting]), + TypeOrmModule.forFeature([Posting, Emotion]), S3Module, UserModule, FootprintModule, + EmotionModule, ], controllers: [PostingController], providers: [PostingService], diff --git a/src/posting/posting.service.ts b/src/posting/posting.service.ts index c927f02..5a547d9 100644 --- a/src/posting/posting.service.ts +++ b/src/posting/posting.service.ts @@ -13,6 +13,8 @@ import { UserService } from 'src/user/user.service'; import { Image } from 'src/image/image.entity'; import { FootprintService } from 'src/footprint/footprint.service'; import { RequestUpdatePostDto } from 'src/admin/dto/RequestUpdatePost.dto'; +import { EmotionService } from 'src/emotion/emotion.service'; +import { Emotion } from 'src/emotion/emotion.entity'; @Injectable() export class PostingService { private readonly awsS3: AWS.S3; @@ -20,9 +22,14 @@ export class PostingService { constructor( @InjectRepository(Posting) private postingRepository: Repository, + + @InjectRepository(Emotion) + private emotionRepository: Repository, + private s3Service: S3Service, private userService: UserService, private footprintService: FootprintService, + private emotionService: EmotionService, ) {} async create( @@ -104,6 +111,21 @@ forFriend = 0 인 게시물 중에 .leftJoin('user.follower', 'follower') .leftJoinAndSelect('post.image', 'image') .loadRelationCountAndMap('post.footprint_count', 'post.footprint') + .loadRelationCountAndMap( + 'post.like_count', + 'post.emotion', + 'like', + (qb) => qb.where('like.emotion_type = 0'), + ) + .loadRelationCountAndMap( + 'post.cool_count', + 'post.emotion', + 'cool', + (qb) => qb.where('cool.emotion_type = 1'), + ) + .loadRelationCountAndMap('post.sad_count', 'post.emotion', 'sad', (qb) => + qb.where('sad.emotion_type = 2'), + ) .where('post.post_id=:post_id', { post_id }) .andWhere( new Brackets((qb) => { @@ -128,17 +150,42 @@ forFriend = 0 인 게시물 중에 .orderBy('distance', 'ASC'); const result = await query.getOne(); - const distance = (await query.getRawOne())?.distance; if (result == null) throw new NotFoundException({ status: HttpStatus.NOT_FOUND, message: '50m 이내 게시물만 조회할 수 있거나, 친구가 아닙니다.', }); + const distance = (await query.getRawOne())?.distance; + // const emotion = await this.emotionRepository.findOne({ + // relations: { + // user_id: true, + // // post_id: true + // }, + // where: { + // emotion_type: 1, + // user_id: { + // user_id, + // }, + // }, + // // select: { + // // emotion_id: true, + // // emotion_type: true, + // // }, + // }); + + const emotion = await this.emotionRepository + .createQueryBuilder('emotion') + .leftJoin('emotion.user_id', 'user') + .leftJoin('emotion.post_id', 'post') + .where('user.user_id = :user_id', { user_id }) + .where('post.post_id = :post_id', { post_id }) + .getOne(); + /* 발자국 추가 */ await this.footprintService.addFootprint(user_id, post_id); - return { ...result, distance }; + return { ...result, emotion: { ...emotion }, distance }; } async deletePost(user_id: string, post_id: string) { diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 8948a71..11a6d40 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -10,7 +10,7 @@ import { HttpException, HttpStatus, } from '@nestjs/common'; -import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; +import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; import { RolesGuard } from 'src/auth/guards/roles.guard'; import { Roles } from 'src/libs/decorators/roles.decorator'; @@ -27,10 +27,12 @@ export class UserController { constructor(private userService: UserService) {} @Get() + @ApiOperation({ + summary: '본인 정보를 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetUserDto, - description: '본인 정보를 조회합니다.', }) @Roles([Role.User]) async getOwnUser(@Req() req) { @@ -46,6 +48,9 @@ export class UserController { // 수정 @Patch() + @ApiOperation({ + summary: '본인 정보를 수정합니다.', + }) @Roles([Role.User]) async patchUser(@Req() req, @Body() updateData: RequestUpdateUserDto) { return await this.userService @@ -62,6 +67,9 @@ export class UserController { // 삭제 @Delete() + @ApiOperation({ + summary: '본인 정보를 삭제합니다.', + }) @Roles([Role.User]) async removeUser(@Req() req) { return await this.userService.delete(req.user_id).catch((err) => { @@ -75,10 +83,12 @@ export class UserController { } @Get('search') + @ApiOperation({ + summary: '상대 정보를 조회합니다.', + }) @ApiCreatedResponse({ status: 200, type: ResponseGetUserDto, - description: '상대 정보를 조회합니다.', }) @Roles([Role.User]) async getUser(@Query('user_id') user_id: string) {