Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger 설치 및 작성 #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 104 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/jwt": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/swagger": "^6.1.4",
"@nestjs/typeorm": "^9.0.1",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
Expand All @@ -37,6 +38,7 @@
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"swagger-ui-express": "^4.6.0",
"typeorm": "^0.3.10"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as config from 'config';

import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
const app = await NestFactory.create(AppModule);


const swaggerConfig = new DocumentBuilder()
.setTitle('API DOCS From Swagger.')
.setDescription('회원 서버 API 문서입니다.')
.setVersion('0.0.1')
.addBearerAuth(
{ type: 'http', scheme: 'bearer', bearerFormat: 'Token' },
'access-token',
)
.build();

const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('api', app, document);

const serverConfig = config.get('server');
const port = serverConfig.port;

Expand Down
12 changes: 11 additions & 1 deletion src/members/dto/create-member.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString, Matches, MaxLength, MinLength } from 'class-validator';
import { MemberAlarm } from '../model/member-alarm.enum';
import { MemberStatus } from '../model/member-status.enum';
Expand All @@ -6,35 +7,44 @@ export class CreateMemberDto {

@IsNotEmpty()
@IsString()
@ApiProperty({ type: String, description: '유저 폰번호' })
phone: string;

@IsNotEmpty()
@IsString()
@MinLength(2)
@MaxLength(20)
@ApiProperty({ type: String, description: '유저 이름' })
memberName: string;

@IsNotEmpty()
@IsString()
@MinLength(8)
@MaxLength(20)
@ApiProperty({ type: String, description: '유저가 입력한 id 계정' })
memberId: string;

@IsEmail()
@ApiProperty({ type: String, description: '유저 이메일' })
email: string;

@IsNotEmpty()
@Matches(/^[a-zA-Z0-9]*$/, {
message: 'Password only accepts english and number', // Matches 에 적합하지 않으면 이 메세지 노출
})
@ApiProperty({ type: String, description: '유저가 입력한 pw 계정' })
password: string;

alarmFlag: string = MemberAlarm.ACTIVE;
@ApiProperty({ type: "${MemberAlarm}", description: '유저 알람 발송 활성화 여부' })
alarmFlag: MemberAlarm = MemberAlarm.ACTIVE;

@ApiProperty({ type: "${MemberStatus}", description: '유저 활동 활성화 상태' })
status: MemberStatus = MemberStatus.ACTIVE;

@ApiProperty({ type: Date, description: '유저 회원가입 날짜' })
createdAt: Date = new Date();

@ApiProperty({ type: Date, description: '유저 회원정보 수정 날짜' })
modifiedAt: Date = new Date();

}
3 changes: 3 additions & 0 deletions src/members/dto/login-info.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, Matches, MaxLength, MinLength } from 'class-validator';

export class LoginInfoDto {
Expand All @@ -6,6 +7,7 @@ export class LoginInfoDto {
@IsString()
@MinLength(4)
@MaxLength(20)
@ApiProperty({ type: String, description: '유저가 입력한 id 계정' })
memberId: string;

@IsNotEmpty()
Expand All @@ -16,6 +18,7 @@ export class LoginInfoDto {
@Matches(/^[a-zA-Z0-9]*$/, {
message: 'Password only accepts english and number', // Matches 에 적합하지 않으면 이 메세지 노출
})
@ApiProperty({ type: String, description: '유저가 입력한 pw 계정' })
password: string;

}
10 changes: 9 additions & 1 deletion src/members/dto/modify-member.dto.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDate, IsNotEmpty, IsOptional, isString, IsString, Matches, MaxLength, MinLength } from 'class-validator';
import { MemberAlarm } from '../model/member-alarm.enum';
import { MemberStatus } from '../model/member-status.enum';

export class ModifyMemberDto {

@IsOptional()
@IsString()
@ApiProperty({ type: String, description: '유저 폰번호' })
phone: string;

@IsOptional()
@ApiProperty({ type: "${MemberStatus}", description: '유저 활동 활성화 상태' })
status: MemberStatus

@IsString()
alarmFlag: string
@ApiProperty({ type: "${MemberAlarm}", description: '유저 알람 발송 활성화 상태' })
alarmFlag: MemberAlarm

@ApiProperty({ type: Date, description: '유저 회원정보 수정 날짜' })
modifiedAt: Date = new Date(); // 수정날짜는 현재날짜

@IsOptional()
@ApiProperty({ type: Date, description: '유저 회원 삭제 날짜' })
deletedAt: Date = new Date(); // status 가 SLP 이면 insert

@IsOptional()
@Matches(/^[a-zA-Z0-9]*$/, {
message: 'Password only accepts english and number', // Matches 에 적합하지 않으면 이 메세지 노출
})
@ApiProperty({ type: String, description: '유저가 입력한 pw 계정' })
password: string;

}
3 changes: 3 additions & 0 deletions src/members/dto/signin-member.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, Matches, MaxLength, MinLength } from 'class-validator';

export class SignInMemberDto {
Expand All @@ -6,11 +7,13 @@ export class SignInMemberDto {
@IsString()
@MinLength(8)
@MaxLength(20)
@ApiProperty({ type: String, description: '유저가 입력한 id 계정' })
memberId: string;

@IsNotEmpty()
@Matches(/^[a-zA-Z0-9]*$/, {
message: 'Password only accepts english and number', // Matches 에 적합하지 않으면 이 메세지 노출
})
@ApiProperty({ type: String, description: '유저가 입력한 pw 계정' })
password: string;
}
7 changes: 6 additions & 1 deletion src/members/entity/loginlog.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import {
BaseEntity,
Column,
Expand All @@ -8,22 +9,26 @@ import {
import { Members } from './members.entity';

@Entity()
export class LoginLog extends BaseEntity {
export class LoginLog extends BaseEntity { // api 게이트웨이나 인증 서버로 옮기기

// pk
@PrimaryGeneratedColumn()
@ApiProperty({ type: Number })
id: number;

// 휴대폰번호
@Column()
@ApiProperty({ type: Date })
loginAt: Date;

// 로그인 로그 테이블과 회원의 연관관계 설정
@ManyToOne((type) => Members, (member) => member.id, { eager: false })
@ApiProperty({ type: Members })
member: Members;

// 디바이스 정보
@Column()
@ApiProperty({ type: String })
device: string;

}
Loading