Skip to content

Commit

Permalink
Merge pull request #145 from modern-agile-team/feature/user
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong authored Nov 22, 2023
2 parents ed42d59 + def16ed commit ec2750f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
21 changes: 19 additions & 2 deletions src/users/controllers/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Controller, Get, UseGuards } from '@nestjs/common';
import {
Controller,
Get,
Param,
ParseIntPipe,
UseGuards,
} from '@nestjs/common';
import { UserService } from '../services/user.service';
import { ApiTags } from '@nestjs/swagger';
import { ApiHeader, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';
import { ApiGetMyInfo } from '../swagger-decorators/get-my-info-decorator';
import { ApiGetMyInfoWithOwner } from '../swagger-decorators/get-my-info-with-owner-decorator';

@Controller('user')
@ApiTags('user API')
Expand All @@ -16,4 +23,14 @@ export class UserController {
async getMyInfo(@GetUserId() userId: number) {
return this.userService.getMyInfo(userId);
}

@UseGuards(JwtAccessTokenGuard)
@ApiGetMyInfoWithOwner()
@Get('my-info/:targetId')
async getMyInfoWithOwner(
@GetUserId() userId: number,
@Param('targetId', ParseIntPipe) targetId: number,
) {
return this.userService.getMyInfoWithOwner(userId, targetId);
}
}
17 changes: 17 additions & 0 deletions src/users/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ export class UserService {
userImage,
};
}

async getMyInfoWithOwner(userId: number, targetId: number) {
const { name, email, gender, admin, provider } =
await this.userRepository.getUserInfo(userId);
const userImage = (await this.userImageRepository.checkUserImage(userId))
.imageUrl;
return {
userId,
name,
email,
gender,
admin,
provider,
userImage,
owner: userId === targetId,
};
}
}
9 changes: 4 additions & 5 deletions src/users/swagger-decorators/get-my-info-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ export function ApiGetMyInfo() {
content: {
JSON: {
example: {
userId: 62,
name: '박준혁',
email: 'pjh_2004@naver.com',
userId: 1,
name: '홍길동',
email: 'abcd@naver.com',
gender: 'M',
admin: false,
provider: 'kakao',
userImage:
'http://k.kakaocdn.net/dn/bgfjbT/btrNZpdv3sK/AMb1oWdaF6WxMEXkuKRkR0/img_640x640.jpg',
userImage: 'http://img.jpg',
},
},
},
Expand Down
56 changes: 56 additions & 0 deletions src/users/swagger-decorators/get-my-info-with-owner-decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { applyDecorators } from '@nestjs/common';
import {
ApiHeaders,
ApiOperation,
ApiParam,
ApiResponse,
} from '@nestjs/swagger';

export function ApiGetMyInfoWithOwner() {
return applyDecorators(
ApiOperation({
summary: '내 정보 조회 API(owner 여부와 함께)',
description: '내 정보 조회 API(owner 여부와 함께)',
}),
ApiResponse({
status: 200,
description: '성공적으로 내 정보를 조회한 경우',
content: {
JSON: {
example: {
userId: 1,
name: '홍길동',
email: '[email protected]',
gender: 'M',
admin: false,
provider: 'kakao',
userImage: 'http://img.jpg',
owner: false,
},
},
},
}),
ApiResponse({
status: 404,
description: '내 정보를 찾을 수 없는 경우',
content: {
JSON: {
example: {
statusCode: 404,
message: '사용자를 찾을 수 없습니다.',
error: 'Not Found',
},
},
},
}),
ApiHeaders([
{
name: 'access_token',
description: '액세스 토큰',
required: true,
example: '여기에 액세스 토큰',
},
]),
ApiParam({ name: 'targetId', example: 1, required: true }),
);
}

0 comments on commit ec2750f

Please sign in to comment.