Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
feat: 유저 프로필 조회 API를 추가하라
Browse files Browse the repository at this point in the history
  • Loading branch information
kaaang committed Feb 14, 2024
1 parent 81da743 commit 3162523
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Body, Controller, Delete, Get, Post, Query, Req, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Delete,
Get,
Post,
Query,
Req,
UseGuards,
} from '@nestjs/common';
import { UserService } from './user.service';
import { IUserProfile } from './user.dto';
import { UserGuard } from './user.guard';
Expand Down Expand Up @@ -28,6 +37,12 @@ export class UserController {
return this.userService.updateUserProfile(req.user.id, body);
}

@Get('/profile')
@UseGuards(UserGuard)
GetUserProfile(@Req() req: Request) {
return this.userService.GetUserProfile(req.user.id);
}

@Post('/profile/nickname')
@UseGuards(UserGuard)
UpdateNickname(@Body('nickname') nickname: string, @Req() req: Request) {
Expand Down
35 changes: 35 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,39 @@ export class UserService {
},
);
}

async GetUserProfile(userId: number) {
const user = await UserEntity.findOne({
where: {
id: userId,
},
relations: {
profileImage: true,
follower: true,
following: true,
},
});

const profileImage = user.profileImage
? await this.s3Service.getImageUrl(user.profileImage.imageKey)
: null;

return new ResponseDto(
ResponseCode.GET_USER_PROFILE_SUCCESS,
true,
'유저 프로필 조회 성공',
{
user: {
id: user.id,
email: user.email,
nickname: user.nickname,
introduction: user.introduction,
visibility: user.visibility,
profileImage: profileImage,
followers: user.follower.length,
followings: user.following.length,
},
},
);
}
}

0 comments on commit 3162523

Please sign in to comment.