Skip to content

Commit 9b15d3e

Browse files
committed
feat: response dto 생성 및 swagger return type 적용
1 parent 21fa261 commit 9b15d3e

File tree

8 files changed

+138
-12
lines changed

8 files changed

+138
-12
lines changed

backend/db_name

0 Bytes
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString, IsNumber, IsObject } from 'class-validator';
3+
class Coordinate {
4+
@IsNumber()
5+
x: number;
6+
@IsNumber()
7+
y: number;
8+
}
9+
export class CoordinateResponseDto {
10+
@ApiProperty({
11+
example: 'OO 생성에 성공했습니다.',
12+
description: 'api 요청 결과 메시지',
13+
})
14+
@IsString()
15+
message: string;
16+
17+
@ApiProperty({
18+
example: {
19+
x: 14,
20+
y: 14,
21+
},
22+
description: 'api 요청 결과 메시지',
23+
})
24+
@IsObject()
25+
coordinate: Coordinate;
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString } from 'class-validator';
3+
4+
export class MessageResponseDto {
5+
@ApiProperty({
6+
example: 'OO 생성에 성공했습니다.',
7+
description: 'api 요청 결과 메시지',
8+
})
9+
@IsString()
10+
message: string;
11+
}

backend/src/node/node.controller.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
import { NodeService } from './node.service';
1414
import { CreateNodeDto } from './dtos/createNode.dto';
1515
import { UpdateNodeDto } from './dtos/updateNode.dto';
16-
import { ApiOperation } from '@nestjs/swagger';
16+
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
17+
import { MessageResponseDto } from './dtos/messageResponse.dto';
18+
import { CoordinateResponseDto } from './dtos/coordinateResponse.dto';
1719

1820
export enum NodeResponseMessage {
1921
NODE_CREATED = '노드와 페이지를 생성했습니다.',
@@ -26,6 +28,9 @@ export enum NodeResponseMessage {
2628
export class NodeController {
2729
constructor(private readonly nodeService: NodeService) {}
2830

31+
@ApiResponse({
32+
type: MessageResponseDto,
33+
})
2934
@ApiOperation({ summary: '노드를 생성하면서 페이지도 함께 생성합니다.' })
3035
@Post('/')
3136
@HttpCode(HttpStatus.CREATED)
@@ -35,7 +40,9 @@ export class NodeController {
3540
message: NodeResponseMessage.NODE_CREATED,
3641
};
3742
}
38-
43+
@ApiResponse({
44+
type: MessageResponseDto,
45+
})
3946
@ApiOperation({
4047
summary: '노드를 삭제하면서 페이지도 삭제합니다. (delete: cascade)',
4148
})
@@ -47,7 +54,9 @@ export class NodeController {
4754
message: NodeResponseMessage.NODE_DELETED,
4855
};
4956
}
50-
57+
@ApiResponse({
58+
type: MessageResponseDto,
59+
})
5160
@ApiOperation({ summary: '노드의 제목, 좌표를 수정합니다.' })
5261
@Patch('/:id')
5362
@HttpCode(HttpStatus.OK)
@@ -60,7 +69,9 @@ export class NodeController {
6069
message: NodeResponseMessage.NODE_UPDATED,
6170
};
6271
}
63-
72+
@ApiResponse({
73+
type: CoordinateResponseDto,
74+
})
6475
@ApiOperation({ summary: '노드의 좌표를 가져옵니다.' })
6576
@Get(':id/coordinates')
6677
@HttpCode(HttpStatus.OK)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString, IsArray, IsObject } from 'class-validator';
3+
import { Page } from '../page.entity';
4+
5+
export class FindPageResponseDto {
6+
@ApiProperty({
7+
example: 'OO 생성에 성공했습니다.',
8+
description: 'api 요청 결과 메시지',
9+
})
10+
@IsString()
11+
message: string;
12+
13+
@ApiProperty({
14+
example: {
15+
type: 'doc',
16+
content: {},
17+
},
18+
description: '모든 Page 배열',
19+
})
20+
@IsObject()
21+
page: Partial<Page>;
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString, IsArray } from 'class-validator';
3+
import { Page } from '../page.entity';
4+
5+
export class FindPagesResponseDto {
6+
@ApiProperty({
7+
example: 'OO 생성에 성공했습니다.',
8+
description: 'api 요청 결과 메시지',
9+
})
10+
@IsString()
11+
message: string;
12+
13+
@ApiProperty({
14+
example: [
15+
{
16+
id: 1,
17+
title: '페이지 제목',
18+
content: {
19+
type: 'doc',
20+
content: {},
21+
},
22+
},
23+
],
24+
description: '모든 Page 배열',
25+
})
26+
@IsArray()
27+
pages: Partial<Page>[];
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString } from 'class-validator';
3+
4+
export class MessageResponseDto {
5+
@ApiProperty({
6+
example: 'OO 생성에 성공했습니다.',
7+
description: 'api 요청 결과 메시지',
8+
})
9+
@IsString()
10+
message: string;
11+
}

backend/src/page/page.controller.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { PageService } from './page.service';
1414
import { CreatePageDto } from './dtos/createPage.dto';
1515
import { UpdatePageDto } from './dtos/updatePage.dto';
1616
import { ApiBody, ApiOperation, ApiResponse } from '@nestjs/swagger';
17+
import { MessageResponseDto } from './dtos/messageResponse.dto';
18+
import { FindPagesResponseDto } from './dtos/findPagesResponse.dto';
19+
import { FindPageResponseDto } from './dtos/findPageResponse.dto';
1720

1821
export enum PageResponseMessage {
1922
PAGE_CREATED = '페이지와 노드를 생성했습니다.',
@@ -26,60 +29,74 @@ export enum PageResponseMessage {
2629
@Controller('page')
2730
export class PageController {
2831
constructor(private readonly pageService: PageService) {}
29-
32+
@ApiResponse({
33+
type: MessageResponseDto,
34+
})
3035
@ApiOperation({ summary: '페이지를 생성하고 노드도 생성합니다.' })
3136
@ApiBody({
3237
description: 'post',
3338
type: CreatePageDto,
3439
})
3540
@Post('/')
3641
@HttpCode(HttpStatus.CREATED)
37-
async createPage(@Body() body: CreatePageDto): Promise<{ message: string }> {
42+
async createPage(@Body() body: CreatePageDto): Promise<MessageResponseDto> {
3843
await this.pageService.createPage(body);
3944
return {
4045
message: PageResponseMessage.PAGE_CREATED,
4146
};
4247
}
4348

49+
@ApiResponse({
50+
type: MessageResponseDto,
51+
})
4452
@ApiOperation({
4553
summary: '페이지를 삭제하고 노드도 삭제합니다. (cascade delete)',
4654
})
4755
@Delete('/:id')
4856
@HttpCode(HttpStatus.OK)
49-
async deletePage(@Param('id') id: number): Promise<{ message: string }> {
57+
async deletePage(@Param('id') id: number): Promise<MessageResponseDto> {
5058
await this.pageService.deletePage(id);
5159
return {
5260
message: PageResponseMessage.PAGE_DELETED,
5361
};
5462
}
63+
64+
@ApiResponse({
65+
type: MessageResponseDto,
66+
})
5567
@ApiOperation({ summary: '페이지 제목, 내용을 수정합니다.' })
5668
@Patch('/:id')
5769
@HttpCode(HttpStatus.OK)
5870
async updatePage(
5971
@Param('id') id: number,
6072
@Body() body: UpdatePageDto,
61-
): Promise<{ message: string }> {
73+
): Promise<MessageResponseDto> {
6274
await this.pageService.updatePage(id, body);
6375
return {
6476
message: PageResponseMessage.PAGE_UPDATED,
6577
};
6678
}
6779

80+
@ApiResponse({
81+
type: FindPagesResponseDto,
82+
})
6883
@ApiOperation({ summary: '모든 페이지를 가져옵니다.' })
6984
@Get()
7085
@HttpCode(HttpStatus.OK)
71-
async findPages(): Promise<{ message: string; pages: Partial<Page>[] }> {
86+
async findPages(): Promise<FindPagesResponseDto> {
7287
return {
7388
message: PageResponseMessage.PAGE_LIST_RETURNED,
7489
pages: await this.pageService.findPages(),
7590
};
7691
}
92+
93+
@ApiResponse({
94+
type: FindPageResponseDto,
95+
})
7796
@ApiOperation({ summary: '특정 페이지를 가져옵니다.' })
7897
@Get('/:id')
7998
@HttpCode(HttpStatus.OK)
80-
async findPage(
81-
@Param('id') id: number,
82-
): Promise<{ message: string; page: Page }> {
99+
async findPage(@Param('id') id: number): Promise<FindPageResponseDto> {
83100
return {
84101
message: PageResponseMessage.PAGE_RETURNED,
85102
page: await this.pageService.findPageById(id),

0 commit comments

Comments
 (0)