Skip to content

Commit

Permalink
[GWL-77] auth, profile 스웨거 작성 (#110)
Browse files Browse the repository at this point in the history
* feat: swagger 작업

* chore: format 적용
  • Loading branch information
sjy982 authored Nov 23, 2023
1 parent 3e71b00 commit e402b17
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
1 change: 0 additions & 1 deletion BackEnd/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ProfilesModule } from './profiles/profiles.module';
import { LiveModule } from './lives/lives.module';
import { RecordsModule } from './records/records.module';


@Module({
imports: [
TypeOrmModule.forRoot(typeOrmConfig),
Expand Down
32 changes: 32 additions & 0 deletions BackEnd/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,41 @@ import { RefreshTokenGuard } from './guard/bearerToken.guard';
import { SignupDto } from './dto/signup.dto';
import { AuthAppleService } from './auth-apple.service';
import { AppleToken } from './decorator/apple-token.decorator';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import {
CreateAccessTokenResDto,
CreateRefreshTokenResDto,
SignupResDto,
} from './dto/auth-response.dto';

@ApiTags('Authentication')
@Controller('api/v1/auth')
export class AuthController {
constructor(
private readonly authService: AuthService,
private readonly authAppleService: AuthAppleService,
) {}

@ApiOperation({ summary: '유저 회원가입' })
@ApiBody({ description: 'The ID of the item', type: SignupDto })
@ApiResponse({
status: 200,
description: '회원가입 성공',
type: SignupResDto,
})
@ApiResponse({ status: 400, description: 'Bad request' })
@Post('signup')
signup(@Body() body: SignupDto) {
return this.authService.registerWithUserIdAndProvider(body);
}

@ApiOperation({ summary: 'Access token 생성' })
@ApiResponse({
status: 200,
description: '토큰 생성 성공',
type: CreateAccessTokenResDto,
})
@ApiResponse({ status: 400, description: 'Bad request' })
@Post('token/access')
@UseGuards(RefreshTokenGuard)
tokenAccess(@Headers('authorization') raw: string) {
Expand All @@ -29,6 +51,13 @@ export class AuthController {
};
}

@ApiOperation({ summary: 'Refresh token 생성' })
@ApiResponse({
status: 200,
description: '토큰 생성 성공',
type: CreateRefreshTokenResDto,
})
@ApiResponse({ status: 400, description: 'Bad request' })
@Post('token/refresh')
@UseGuards(RefreshTokenGuard)
tokenRefresh(@Headers('authorization') raw: string) {
Expand All @@ -41,6 +70,9 @@ export class AuthController {
};
}

@ApiOperation({ summary: '유저 애플 로그인' })
@ApiResponse({ status: 200, description: '로그인 성공' })
@ApiResponse({ status: 400, description: 'Bad request' })
@Post('apple/signin')
async appleSignIn(@AppleToken() token: string) {
const userInfo = await this.authAppleService.getUserInfo(token);
Expand Down
38 changes: 38 additions & 0 deletions BackEnd/src/auth/dto/auth-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ApiProperty, PickType } from '@nestjs/swagger';

class SuccessResDto {
@ApiProperty({ description: '에러가 없는 경우 null' })
code: number;

@ApiProperty({ description: '에러가 없는 경우 null' })
errorMessage: string;
}

class Token {
@ApiProperty({
example: 'ewaf1313RWDFA...',
description: 'Access Token 입니다.',
})
accessToken: string;

@ApiProperty({
example: 'ewaf1313RWDFA...',
description: 'Refresh Token 입니다.',
})
refreshToken: string;
}

export class SignupResDto extends SuccessResDto {
@ApiProperty({ type: () => Token })
data: Token;
}

export class CreateAccessTokenResDto extends SuccessResDto {
@ApiProperty({ type: () => PickType(Token, ['accessToken']) })
data: Pick<Token, 'accessToken'>;
}

export class CreateRefreshTokenResDto extends SuccessResDto {
@ApiProperty({ type: () => PickType(Token, ['refreshToken']) })
data: Pick<Token, 'refreshToken'>;
}
2 changes: 1 addition & 1 deletion BackEnd/src/lives/lives.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Module} from '@nestjs/common';
import { Module } from '@nestjs/common';
import { LiveGateway } from './lives.gateway';

@Module({
Expand Down
11 changes: 11 additions & 0 deletions BackEnd/src/profiles/entities/profiles.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,35 @@ import {
OneToOne,
OneToMany,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';

@Entity()
export class ProfileModel {
@PrimaryGeneratedColumn()
id: number;

@ApiProperty({ example: '닉네임', description: '닉네임 필드를 의미합니다.' })
@Column({ unique: true })
@IsString({
message: 'nickname은 string 타입으로 입력해야합니다.',
})
nickname: string;

@ApiProperty({
example: 'Male',
description: '성별 필드를 의미합니다',
enum: ['Male', 'Female', 'Other'],
})
@Column({ nullable: false })
@IsString({
message: 'gender는 string 타입으로 입력해야합니다.',
})
gender: string;

@ApiProperty({
example: '2023-11-06',
description: '생년월일 필드를 의미합니다.',
})
@Column({ nullable: false })
@IsString({
message: 'birthdate string 타입으로 입력해야합니다.',
Expand Down
6 changes: 6 additions & 0 deletions BackEnd/src/users/entities/users.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import {
} from 'typeorm';
import { ProfileModel } from '../../profiles/entities/profiles.entity';
import { IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
@Entity()
export class UserModel {
@PrimaryGeneratedColumn()
id: number;

@ApiProperty({
example: 'testid132',
description: 'user의 id를 뜻합니다. (apple이면 apple id)',
})
@Column()
@IsString({
message: 'userId는 string 타입을 입력해야합니다.',
})
userId: string;

@ApiProperty({ example: 'apple', description: 'userId의 플랫폼입니다.' })
@Column()
@IsString({
message: 'provider는 string 타입을 입력해야합니다.',
Expand Down

0 comments on commit e402b17

Please sign in to comment.