From 33256f68f75612e47abf98c7505ebe287e2bddb2 Mon Sep 17 00:00:00 2001 From: kyeah Date: Wed, 11 Sep 2024 01:48:27 -0600 Subject: [PATCH] fix: home other profile format --- src/decorators/swagger/home.decorator.ts | 16 +++++++++++++++- src/domain/home/home.controller.ts | 16 +++++----------- src/domain/home/home.module.ts | 2 -- src/domain/home/home.service.ts | 10 ++++++++++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/decorators/swagger/home.decorator.ts b/src/decorators/swagger/home.decorator.ts index 20a7cac..2bc6647 100644 --- a/src/decorators/swagger/home.decorator.ts +++ b/src/decorators/swagger/home.decorator.ts @@ -3,12 +3,14 @@ import { ApiBody, ApiOkResponse, ApiOperation, + ApiParam, ApiResponse, } from '@nestjs/swagger'; +import { UserProfileDto } from 'src/domain/dtos/user.dto'; import { HomeInfoResponseDto, likeHomeAnswerDto } from 'src/domain/home/dtos'; import { RandomUserDto } from 'src/domain/home/dtos/homInfoResponse.dto'; -type HomeEndPoints = 'default' | 'like' | 'version' | 'random'; +type HomeEndPoints = 'default' | 'like' | 'version' | 'random' | 'otherProfile'; export function Docs(endpoint: HomeEndPoints) { switch (endpoint) { case 'default': @@ -45,5 +47,17 @@ export function Docs(endpoint: HomeEndPoints) { }), ApiResponse({ type: RandomUserDto, isArray: true }), ); + case 'otherProfile': + return applyDecorators( + ApiOperation({ + summary: '다른 사용자 프로필 정보', + }), + ApiParam({ + name: 'other', + description: '다른 사람 id', + type: Number, + }), + ApiResponse({ type: UserProfileDto }), + ); } } diff --git a/src/domain/home/home.controller.ts b/src/domain/home/home.controller.ts index dfffd0e..f50d9f4 100644 --- a/src/domain/home/home.controller.ts +++ b/src/domain/home/home.controller.ts @@ -6,17 +6,12 @@ import { JwtPayload } from 'src/interfaces/auth'; import { HomeInfoResponseDto, likeHomeAnswerDto } from './dtos'; import { User } from 'src/decorators/accessUser.decorator'; import { Docs } from 'src/decorators/swagger/home.decorator'; -import { OtherProfileDocs } from 'src/decorators/swagger/blurting.decorator'; -import { BlurtingProfileDto } from '../blurting/dtos'; -import { BlurtingService } from '../blurting/blurting.service'; +import { UserProfileDto } from '../dtos/user.dto'; @Controller('home') @ApiTags('home') export class HomeController { - constructor( - private readonly homeService: HomeService, - private readonly blurtingService: BlurtingService, - ) {} + constructor(private readonly homeService: HomeService) {} @Get('/') @UseGuards(AuthGuard('access')) @@ -30,13 +25,12 @@ export class HomeController { @Get('/profile/:other') @UseGuards(AuthGuard('access')) - @OtherProfileDocs() + @Docs('otherProfile') async getBlurtingProfile( @User() userPayload: JwtPayload, @Param('other') other: number, - ): Promise { - const { id } = userPayload; - return this.blurtingService.getProfile(id, other); + ): Promise { + return this.homeService.getOtherProfile(other); } @Put('/like') diff --git a/src/domain/home/home.module.ts b/src/domain/home/home.module.ts index 32c0a4e..21b06b3 100644 --- a/src/domain/home/home.module.ts +++ b/src/domain/home/home.module.ts @@ -18,12 +18,10 @@ import { UserRepository, } from 'src/domain/repositories'; import { UserModule } from 'src/domain/user/user.module'; -import { BlurtingModule } from '../blurting/blurting.module'; @Module({ imports: [ UserModule, - BlurtingModule, TypeOrmModule.forFeature([ LikeEntity, BlurtingArrowEntity, diff --git a/src/domain/home/home.service.ts b/src/domain/home/home.service.ts index e81bd19..dfd2e98 100644 --- a/src/domain/home/home.service.ts +++ b/src/domain/home/home.service.ts @@ -13,6 +13,7 @@ import { compareDateGroupExist, getDateTimeOfNow } from 'src/common/util/time'; import { AnswerWithQuestionDto } from './dtos'; import { UserService } from 'src/domain/user/user.service'; import { Sex, SexOrient } from 'src/common/enums'; +import { UserProfileDto } from '../dtos/user.dto'; @Injectable() export class HomeService { @@ -130,6 +131,15 @@ export class HomeService { ); } + async getOtherProfile(userId: number): Promise { + const userImages = await this.userService.getUserImages(userId); + const userProfile = await this.userService.getUserProfile( + userId, + userImages, + ); + return userProfile; + } + async updateProfile(userId: number) { const user = await this.userRepository.findOneById(userId); if (user.birth == null) return true;