Skip to content

Commit a2ac04c

Browse files
authored
Merge pull request #103 from boostcampwm-2024/dev-be
백엔드 브랜치를 메인으로 머지
2 parents 0e68438 + 209f7ce commit a2ac04c

29 files changed

+1059
-28
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"*.ttml": "xml",
4+
"*.ttss": "css"
5+
}
6+
}

backend/src/edge/edge.controller.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ describe('EdgeController', () => {
88
beforeEach(async () => {
99
const module: TestingModule = await Test.createTestingModule({
1010
controllers: [EdgeController],
11-
providers: [EdgeService],
11+
providers: [
12+
{
13+
provide: EdgeService,
14+
useValue: {},
15+
},
16+
],
1217
}).compile();
1318

1419
controller = module.get<EdgeController>(EdgeController);
1520
});
1621

17-
it('should be defined', () => {
22+
it('컨트롤러 클래스가 정상적으로 인스턴스화된다.', () => {
1823
expect(controller).toBeDefined();
1924
});
2025
});
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { EdgeService } from './edge.service';
3-
3+
import { EdgeRepository } from './edge.repository';
44
describe('EdgeService', () => {
55
let service: EdgeService;
66

77
beforeEach(async () => {
88
const module: TestingModule = await Test.createTestingModule({
9-
providers: [EdgeService],
9+
providers: [
10+
EdgeService,
11+
{
12+
provide: EdgeRepository,
13+
useValue: {},
14+
},
15+
],
1016
}).compile();
1117

1218
service = module.get<EdgeService>(EdgeService);
1319
});
1420

15-
it('should be defined', () => {
21+
it('서비스 클래스가 정상적으로 인스턴스화된다.', () => {
1622
expect(service).toBeDefined();
1723
});
1824
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NotFoundException } from '@nestjs/common';
2+
3+
export class EdgeNotFoundException extends NotFoundException {
4+
constructor() {
5+
super(`엣지를 찾지 못했습니다.`);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NotFoundException } from '@nestjs/common';
2+
3+
export class NodeNotFoundException extends NotFoundException {
4+
constructor() {
5+
super(`노드를 찾지 못했습니다.`);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NotFoundException } from '@nestjs/common';
2+
3+
export class PageNotFoundException extends NotFoundException {
4+
constructor() {
5+
super(`페이지를 찾지 못했습니다.`);
6+
}
7+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
ExceptionFilter,
3+
Catch,
4+
ArgumentsHost,
5+
HttpException,
6+
} from '@nestjs/common';
7+
import { Request, Response } from 'express';
8+
import { Logger } from '@nestjs/common';
9+
10+
@Catch(HttpException)
11+
export class HttpExceptionFilter implements ExceptionFilter {
12+
private readonly logger = new Logger();
13+
14+
catch(exception: HttpException, host: ArgumentsHost) {
15+
const ctx = host.switchToHttp();
16+
const response = ctx.getResponse<Response>();
17+
const request = ctx.getRequest<Request>();
18+
const status = exception.getStatus();
19+
20+
const log = {
21+
statusCode: status,
22+
timestamp: new Date().toISOString(),
23+
path: request.url,
24+
};
25+
26+
this.logger.error(log);
27+
28+
response.status(status).json(log);
29+
}
30+
}

backend/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
3+
import { HttpExceptionFilter } from './filter/http-exception.filter';
34

45
async function bootstrap() {
56
const app = await NestFactory.create(AppModule);
7+
app.useGlobalFilters(new HttpExceptionFilter());
68
await app.listen(3000);
79
}
810
bootstrap();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { IsString, IsNumber } from 'class-validator';
2+
3+
export class CreateNodeDto {
4+
@IsString()
5+
title: string;
6+
7+
@IsNumber()
8+
x: number;
9+
10+
@IsNumber()
11+
y: number;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { IsString, IsNumber } from 'class-validator';
2+
3+
export class UpdateNodeDto {
4+
@IsString()
5+
title: string;
6+
7+
@IsNumber()
8+
x: number;
9+
10+
@IsNumber()
11+
y: number;
12+
}

0 commit comments

Comments
 (0)