Skip to content

Commit a3fd0c9

Browse files
feat: 엣지 컨트롤러 구현
1 parent 8e44a0c commit a3fd0c9

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsString, IsArray } from 'class-validator';
3+
import { Edge } from '../edge.entity';
4+
5+
export class FindEdgesResponseDto {
6+
@ApiProperty({
7+
example: 'OO 생성에 성공했습니다.',
8+
description: 'api 요청 결과 메시지',
9+
})
10+
@IsString()
11+
message: string;
12+
13+
@ApiProperty({
14+
example: [
15+
{
16+
id: 1,
17+
fromNode: 2,
18+
fromPoint: 'N',
19+
toNode: 7,
20+
toPoint: 'W',
21+
},
22+
],
23+
description: '모든 Edge 배열',
24+
})
25+
@IsArray()
26+
nodes: Partial<Edge>[];
27+
}
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+
}
Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
1-
import { Controller } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Delete,
6+
Param,
7+
Body,
8+
HttpCode,
9+
HttpStatus,
10+
ParseIntPipe,
11+
} from '@nestjs/common';
212
import { EdgeService } from './edge.service';
13+
import { CreateEdgeDto } from './dtos/createEdge.dto';
14+
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
15+
import { MessageResponseDto } from './dtos/messageResponse.dto';
16+
import { FindEdgesResponseDto } from './dtos/findEdgesResponse.dto';
17+
18+
export enum EdgeResponseMessage {
19+
EDGE_ALL_RETURNED = '모든 엣지를 가져왔습니다.',
20+
EDGE_CREATED = '엣지를 생성했습니다.',
21+
EDGE_DELETED = '엣지를 삭제했습니다.',
22+
}
323

424
@Controller('edge')
525
export class EdgeController {
626
constructor(private readonly edgeService: EdgeService) {}
27+
28+
@ApiResponse({
29+
type: FindEdgesResponseDto,
30+
})
31+
@ApiOperation({
32+
summary: '모든 엣지 정보를 가져옵니다.',
33+
})
34+
@Get('/')
35+
@HttpCode(HttpStatus.OK)
36+
async getNodes() {
37+
const nodes = await this.edgeService.findEdges();
38+
return {
39+
message: EdgeResponseMessage.EDGE_ALL_RETURNED,
40+
nodes: nodes,
41+
};
42+
}
43+
44+
@ApiResponse({ type: MessageResponseDto })
45+
@ApiOperation({ summary: '엣지를 생성합니다.' })
46+
@Post('/')
47+
@HttpCode(HttpStatus.CREATED)
48+
async createEdge(@Body() body: CreateEdgeDto) {
49+
await this.edgeService.createEdge(body);
50+
return {
51+
message: EdgeResponseMessage.EDGE_CREATED,
52+
};
53+
}
54+
55+
@ApiResponse({ type: MessageResponseDto })
56+
@ApiOperation({ summary: '엣지를 삭제합니다.' })
57+
@Delete('/:id')
58+
@HttpCode(HttpStatus.OK)
59+
async deleteNode(
60+
@Param('id', ParseIntPipe) id: number,
61+
): Promise<{ message: string }> {
62+
await this.edgeService.deleteEdge(id);
63+
return {
64+
message: EdgeResponseMessage.EDGE_DELETED,
65+
};
66+
}
767
}

backend/src/node/node.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export enum NodeResponseMessage {
3333
@Controller('node')
3434
export class NodeController {
3535
constructor(private readonly nodeService: NodeService) {}
36+
3637
@ApiResponse({
3738
type: FindNodesResponseDto,
3839
})
@@ -49,6 +50,7 @@ export class NodeController {
4950
nodes: nodes,
5051
};
5152
}
53+
5254
@ApiResponse({
5355
type: FindNodeResponseDto,
5456
})
@@ -78,6 +80,7 @@ export class NodeController {
7880
message: NodeResponseMessage.NODE_CREATED,
7981
};
8082
}
83+
8184
@ApiResponse({
8285
type: MessageResponseDto,
8386
})
@@ -92,6 +95,7 @@ export class NodeController {
9295
message: NodeResponseMessage.NODE_DELETED,
9396
};
9497
}
98+
9599
@ApiResponse({
96100
type: MessageResponseDto,
97101
})
@@ -107,6 +111,7 @@ export class NodeController {
107111
message: NodeResponseMessage.NODE_UPDATED,
108112
};
109113
}
114+
110115
@ApiResponse({
111116
type: CoordinateResponseDto,
112117
})

0 commit comments

Comments
 (0)