diff --git a/backend/db b/backend/db new file mode 100644 index 00000000..39523de4 Binary files /dev/null and b/backend/db differ diff --git a/backend/src/page/dtos/createPageResponse.dto.ts b/backend/src/page/dtos/createPageResponse.dto.ts new file mode 100644 index 00000000..b03b6719 --- /dev/null +++ b/backend/src/page/dtos/createPageResponse.dto.ts @@ -0,0 +1,18 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsInt, IsString } from 'class-validator'; + +export class CreatePageResponseDto { + @ApiProperty({ + example: 'OO 생성에 성공했습니다.', + description: 'api 요청 결과 메시지', + }) + @IsString() + message: string; + + @ApiProperty({ + example: 1, + description: '페이지의 PK', + }) + @IsInt() + pageId: number; +} diff --git a/backend/src/page/page.controller.spec.ts b/backend/src/page/page.controller.spec.ts index 7cb8af69..a1e16e1f 100644 --- a/backend/src/page/page.controller.spec.ts +++ b/backend/src/page/page.controller.spec.ts @@ -47,8 +47,18 @@ describe('PageController', () => { }; const expectedResponse = { message: PageResponseMessage.PAGE_CREATED, + pageId: 1, }; - + const newDate = new Date(); + jest.spyOn(pageService, 'createPage').mockResolvedValue({ + id: 1, + title: 'New Page', + content: {} as JSON, + createdAt: newDate, + updatedAt: newDate, + version: 1, + node: null, + }); const result = await controller.createPage(dto); expect(pageService.createPage).toHaveBeenCalledWith(dto); diff --git a/backend/src/page/page.controller.ts b/backend/src/page/page.controller.ts index 96ebdec6..aa32bdbb 100644 --- a/backend/src/page/page.controller.ts +++ b/backend/src/page/page.controller.ts @@ -17,6 +17,7 @@ import { ApiBody, ApiOperation, ApiResponse } from '@nestjs/swagger'; import { MessageResponseDto } from './dtos/messageResponse.dto'; import { FindPagesResponseDto } from './dtos/findPagesResponse.dto'; import { FindPageResponseDto } from './dtos/findPageResponse.dto'; +import { CreatePageResponseDto } from './dtos/createPageResponse.dto'; export enum PageResponseMessage { PAGE_CREATED = '페이지와 노드를 생성했습니다.', @@ -31,7 +32,7 @@ export class PageController { constructor(private readonly pageService: PageService) {} @ApiResponse({ - type: MessageResponseDto, + type: CreatePageResponseDto, }) @ApiOperation({ summary: '페이지를 생성하고 노드도 생성합니다.' }) @ApiBody({ @@ -40,10 +41,13 @@ export class PageController { }) @Post('/') @HttpCode(HttpStatus.CREATED) - async createPage(@Body() body: CreatePageDto): Promise { - await this.pageService.createPage(body); + async createPage( + @Body() body: CreatePageDto, + ): Promise { + const newPage = await this.pageService.createPage(body); return { message: PageResponseMessage.PAGE_CREATED, + pageId: newPage.id, }; }