1- import { Controller , Get , UseGuards } from '@nestjs/common' ;
1+ import { Controller , Get , UseGuards , Body , Patch , Query } from '@nestjs/common' ;
22import { UserService } from './user.service' ;
33import { JwtAuthGuard } from 'src/auth/jwt.auth.strategy' ;
44import { GetUser } from './decorator/get-user.decorator' ;
@@ -8,10 +8,13 @@ import {
88 ApiInternalServerErrorResponse ,
99 ApiOkResponse ,
1010 ApiOperation ,
11+ ApiQuery ,
1112 ApiTags ,
1213 ApiUnauthorizedResponse ,
1314} from '@nestjs/swagger' ;
1415import { UserInfoDto } from './dto/res/userInfo.dto' ;
16+ import { UpdateNicknameDto } from './dto/req/updateNickname.dto' ;
17+ import { NicknameDuplicateCheckDto } from './dto/res/nicknameDuplicateCheck.dto' ;
1518
1619@ApiTags ( 'User' )
1720@Controller ( 'user' )
@@ -35,4 +38,49 @@ export class UserController {
3538 async getProfile ( @GetUser ( ) user : UserInfo ) : Promise < UserInfo > {
3639 return user ;
3740 }
41+
42+ @ApiOperation ( {
43+ summary : 'check nickname duplicate' ,
44+ } )
45+ @ApiQuery ( {
46+ name : 'nickname' ,
47+ type : String ,
48+ description : 'Nickname to check' ,
49+ required : true ,
50+ } )
51+ @ApiOkResponse ( {
52+ type : NicknameDuplicateCheckDto ,
53+ description : 'Return whether nickname is duplicate or not' ,
54+ } )
55+ @Get ( 'nickname/check' )
56+ async checkNicknameDuplicate (
57+ @Query ( 'nickname' ) nickname : string ,
58+ ) : Promise < NicknameDuplicateCheckDto > {
59+ const isDuplicate = await this . userService . checkNicknameDuplicate ( nickname ) ;
60+ return { isDuplicate } ;
61+ }
62+
63+ @ApiOperation ( {
64+ summary : 'update my nickname' ,
65+ } )
66+ @ApiOkResponse ( {
67+ type : UserInfoDto ,
68+ description : 'Return updated profile' ,
69+ } )
70+ @ApiUnauthorizedResponse ( { description : 'Unauthorized' } )
71+ @ApiInternalServerErrorResponse ( {
72+ description : 'Internal Server Error' ,
73+ } )
74+ @ApiBearerAuth ( 'JWT' )
75+ @Patch ( 'nickname' )
76+ @UseGuards ( JwtAuthGuard )
77+ async updateNickname (
78+ @GetUser ( ) user : UserInfo ,
79+ @Body ( ) updateNicknameDto : UpdateNicknameDto ,
80+ ) : Promise < UserInfo > {
81+ return this . userService . updateNickname (
82+ user . uuid ,
83+ updateNicknameDto . nickname ,
84+ ) ;
85+ }
3886}
0 commit comments