Skip to content

Commit e777262

Browse files
authored
Merge pull request #354 from boostcampwm-2024/docs/user-signup
📝 docs: 사용자 API swagger 작성
2 parents 1ff6fb5 + e826a85 commit e777262

File tree

8 files changed

+178
-4
lines changed

8 files changed

+178
-4
lines changed

server/src/common/swagger/swagger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function setupSwagger(app: INestApplication) {
1414
.addTag('Feed', '피드 관리와 검색 관련 API')
1515
.addTag('RSS', '관리자 전용 API')
1616
.addTag('Statistic', '통계 정보 조회 API')
17+
.addTag('User', '사용자 관리와 인증 관련 API')
1718
.setLicense('MIT License', 'https://opensource.org/licenses/MIT')
1819
.build();
1920

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { applyDecorators } from '@nestjs/common';
2+
import {
3+
ApiBadRequestResponse,
4+
ApiNotFoundResponse,
5+
ApiOkResponse,
6+
ApiOperation,
7+
} from '@nestjs/swagger';
8+
9+
export function ApiCertificateUser() {
10+
return applyDecorators(
11+
ApiOperation({
12+
summary: '회원 인증 API',
13+
}),
14+
ApiOkResponse({
15+
description: 'Ok',
16+
schema: {
17+
properties: {
18+
message: {
19+
type: 'string',
20+
},
21+
},
22+
},
23+
example: {
24+
message: '회원 인증 요청이 성공적으로 처리되었습니다.',
25+
},
26+
}),
27+
ApiBadRequestResponse({
28+
description: 'Bad Request',
29+
example: {
30+
message: '오류 메세지',
31+
},
32+
}),
33+
ApiNotFoundResponse({
34+
description: 'Not Found',
35+
example: {
36+
message: '인증에 실패했습니다.',
37+
},
38+
}),
39+
);
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { applyDecorators } from '@nestjs/common';
2+
import {
3+
ApiBadRequestResponse,
4+
ApiOkResponse,
5+
ApiOperation,
6+
ApiUnauthorizedResponse,
7+
} from '@nestjs/swagger';
8+
9+
export function ApiCheckEmailDuplication() {
10+
return applyDecorators(
11+
ApiOperation({
12+
summary: '이메일 중복 조회 API',
13+
}),
14+
ApiOkResponse({
15+
description: 'Ok',
16+
schema: {
17+
properties: {
18+
message: {
19+
type: 'string',
20+
},
21+
},
22+
},
23+
example: {
24+
message: '이메일 중복 조회 요청이 성공적으로 처리되었습니다.',
25+
},
26+
}),
27+
ApiBadRequestResponse({
28+
description: 'Bad Request',
29+
example: {
30+
message: '오류 메세지',
31+
},
32+
}),
33+
ApiUnauthorizedResponse({
34+
description: 'Unauthorized',
35+
example: {
36+
message: '인증되지 않은 사용자입니다.',
37+
},
38+
}),
39+
);
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { applyDecorators } from '@nestjs/common';
2+
import {
3+
ApiBadRequestResponse,
4+
ApiConflictResponse,
5+
ApiOkResponse,
6+
ApiOperation,
7+
} from '@nestjs/swagger';
8+
9+
export function ApiSignupUser() {
10+
return applyDecorators(
11+
ApiOperation({
12+
summary: '회원 가입 API',
13+
}),
14+
ApiOkResponse({
15+
description: 'Ok',
16+
schema: {
17+
properties: {
18+
message: {
19+
type: 'string',
20+
},
21+
},
22+
},
23+
example: {
24+
message: '회원가입이 요청이 성공적으로 처리되었습니다.',
25+
},
26+
}),
27+
ApiBadRequestResponse({
28+
description: 'Bad Request',
29+
example: {
30+
message: '오류 메세지',
31+
},
32+
}),
33+
ApiConflictResponse({
34+
description: 'Conflict',
35+
example: {
36+
message: '이미 존재하는 이메일입니다.',
37+
},
38+
}),
39+
);
40+
}

server/src/user/controller/user.controller.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,35 @@ import {
1111
import { ApiResponse } from '../../common/response/common.response';
1212
import { UserService } from '../service/user.service';
1313
import { SignupDto } from '../dto/request/signup.dto';
14+
import { ApiCheckEmailDuplication } from '../api-docs/checkEmailDuplication.api-docs';
15+
import { ApiSignupUser } from '../api-docs/signupUser.api-docs';
16+
import { ApiCertificateUser } from '../api-docs/certificateUser.api-docs';
17+
import { CertificateDto } from '../dto/request/certificate.dto';
18+
import { CheckEmailDuplicationRequestDto } from '../dto/request/CheckEmailDuplcation.dto';
1419

1520
@ApiTags('User')
1621
@Controller('user')
1722
export class UserController {
1823
constructor(private readonly userService: UserService) {}
1924

25+
@ApiCheckEmailDuplication()
2026
@Get('/email-check')
2127
@HttpCode(HttpStatus.OK)
22-
async checkEmailDuplication(@Query('email') email: string) {
28+
async checkEmailDuplication(
29+
@Query()
30+
checkEmailDuplicationRequestDto: CheckEmailDuplicationRequestDto,
31+
) {
2332
return ApiResponse.responseWithData(
2433
'이메일 중복 조회 요청이 성공적으로 처리되었습니다.',
2534
{
26-
exists: await this.userService.checkEmailDuplication(email),
35+
exists: await this.userService.checkEmailDuplication(
36+
checkEmailDuplicationRequestDto.email,
37+
),
2738
},
2839
);
2940
}
3041

42+
@ApiSignupUser()
3143
@Post('/signup')
3244
@HttpCode(HttpStatus.CREATED)
3345
async signupUser(@Body() signupDto: SignupDto) {
@@ -37,10 +49,11 @@ export class UserController {
3749
);
3850
}
3951

52+
@ApiCertificateUser()
4053
@Post('/certificate')
4154
@HttpCode(HttpStatus.OK)
42-
async certificateUser(@Body() uuid: string) {
43-
await this.userService.certificateUser(uuid);
55+
async certificateUser(@Body() certificateDto: CertificateDto) {
56+
await this.userService.certificateUser(certificateDto.uuid);
4457
return ApiResponse.responseWithNoContent(
4558
'이메일 인증이 성공적으로 처리되었습니다.',
4659
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { IsEmail, IsNotEmpty } from 'class-validator';
2+
import { ApiProperty } from '@nestjs/swagger';
3+
import { Type } from 'class-transformer';
4+
5+
export class CheckEmailDuplicationRequestDto {
6+
@ApiProperty({
7+
example: 'test1234@test.com',
8+
description: '중복 확인할 이메일을 입력해주세요.',
9+
})
10+
@IsEmail({}, { message: '이메일 형식이 아닙니다.' })
11+
@IsNotEmpty({ message: '이메일을 입력해주세요.' })
12+
@Type(() => String)
13+
email: string;
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsNotEmpty } from 'class-validator';
3+
4+
export class CertificateDto {
5+
@ApiProperty({
6+
example: 'd2ba0d98-95ce-4905-87fc-384965ffe7c9',
7+
description: '인증 코드를 입력해주세요.',
8+
})
9+
@IsNotEmpty({
10+
message: '인증 코드를 입력해주세요.',
11+
})
12+
uuid: string;
13+
}

server/src/user/dto/request/signup.dto.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { IsEmail, IsNotEmpty } from 'class-validator';
22
import { User } from '../../entity/user.entity';
3+
import { ApiProperty } from '@nestjs/swagger';
34

45
export class SignupDto {
6+
@ApiProperty({
7+
example: 'test123@test.com',
8+
description: '이메일을 입력해주세요.',
9+
})
510
@IsEmail(
611
{},
712
{
@@ -13,11 +18,19 @@ export class SignupDto {
1318
})
1419
email: string;
1520

21+
@ApiProperty({
22+
example: 'test1234!',
23+
description: '비밀번호를 입력해주세요.',
24+
})
1625
@IsNotEmpty({
1726
message: '비밀번호가 없습니다.',
1827
})
1928
password: string;
2029

30+
@ApiProperty({
31+
example: '홍길동',
32+
description: '사용자 이름을 입력해주세요.',
33+
})
2134
@IsNotEmpty({
2235
message: '사용자 이름이 없습니다.',
2336
})

0 commit comments

Comments
 (0)