Skip to content

Commit

Permalink
feat: 페이지 생성 시 page id 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
ezcolin2 committed Nov 14, 2024
1 parent 5de1374 commit d604dcd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Binary file added backend/db
Binary file not shown.
18 changes: 18 additions & 0 deletions backend/src/page/dtos/createPageResponse.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 11 additions & 1 deletion backend/src/page/page.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions backend/src/page/page.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '페이지와 노드를 생성했습니다.',
Expand All @@ -31,7 +32,7 @@ export class PageController {
constructor(private readonly pageService: PageService) {}

@ApiResponse({
type: MessageResponseDto,
type: CreatePageResponseDto,
})
@ApiOperation({ summary: '페이지를 생성하고 노드도 생성합니다.' })
@ApiBody({
Expand All @@ -40,10 +41,13 @@ export class PageController {
})
@Post('/')
@HttpCode(HttpStatus.CREATED)
async createPage(@Body() body: CreatePageDto): Promise<MessageResponseDto> {
await this.pageService.createPage(body);
async createPage(
@Body() body: CreatePageDto,
): Promise<CreatePageResponseDto> {
const newPage = await this.pageService.createPage(body);
return {
message: PageResponseMessage.PAGE_CREATED,
pageId: newPage.id,
};
}

Expand Down

0 comments on commit d604dcd

Please sign in to comment.