-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create notice board post, getAll apis #74
Merged
Merged
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
0aba6f0
feat/#66: create notice-boards module
hobiJeong 9543658
modify/#66: modifying entities related to the notice-board
hobiJeong cf1ab64
modify/#66: modifying entity related to the notice-board
hobiJeong 37e1837
feat/#66: create dto, constant
hobiJeong 7d80f29
feat/#66: feat post api, modify dto
hobiJeong 7a21900
feat/#66: create swagger api docs and set response
hobiJeong c54f62e
feat/#66: feat findAll and notice-board-history migrate
hobiJeong 2ab2ad7
conflict/#66: conflict
hobiJeong 3865fec
feat/#66: create dto, add and modify entities
hobiJeong 9683159
modify/#66: modify entity
hobiJeong 0d324e1
feat/#66: create api for post, getAll
hobiJeong 4d5f325
feat/#66: create test code
hobiJeong b600416
refactor/#66: delete console.log
hobiJeong 941b402
refactor/#66: modify string
hobiJeong 782865b
modify/#66: modify Order type
hobiJeong b3a035f
modify/#66: modify Order type
hobiJeong 62b4bd3
refactor/#66: modify NoticeBoard Create's key for swaggerBuilder
hobiJeong ebd5e47
feat/#66: add ApiBearerAuth
hobiJeong d266d56
modify/#66: modify string
hobiJeong 8eae727
modify/#66: remove test code
hobiJeong 75cf9e7
modify/#66: modify notice-board.constants
hobiJeong 66da11a
modify/#66: modify entity
hobiJeong bbd65bf
modify/#66: modify migration file
hobiJeong 10915d0
modify/#66: modify entities and migration
hobiJeong 1fe7fd1
modify/#66: modify entities
hobiJeong 9a7b052
refactor/#66: modify typo
hobiJeong 8a206fe
modify/#66: modify dtos
hobiJeong 0114f89
modify/#66: modify dtos
hobiJeong a293353
Update src/apis/notice-boards/services/notice-boards.service.ts
hobiJeong d4139d4
refactor/#66: use snake case
hobiJeong 4b10111
refactor/#66: modify entity comment
hobiJeong be43d1e
Merge branch 'develop' into feat/#66/notice_board_crud
hobiJeong 6da5f59
modify/#66: modify column name and dtos
hobiJeong cc35718
feat/#66: notice_board , notice_board_history migration
hobiJeong db84c46
modify/#66: 주석처리
hobiJeong 39c7ba2
feat/#66: reflect #81 PR
hobiJeong 4c58c85
feat/#66: add default value
hobiJeong 6fba066
modify/#66: set default value
hobiJeong 11403a3
modify/#66: delete ApiProperty
hobiJeong be27db6
Merge branch 'develop' into feat/#66/notice_board_crud
hobiJeong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
import { | ||
MigrationInterface, | ||
QueryRunner, | ||
Table, | ||
TableColumnOptions, | ||
} from 'typeorm'; | ||
|
||
const generatePrimaryColumn = ( | ||
comment: string = '고유 ID', | ||
): TableColumnOptions => { | ||
return { | ||
name: 'id', | ||
type: 'int', | ||
unsigned: true, | ||
isPrimary: true, | ||
isNullable: false, | ||
isGenerated: true, | ||
generationStrategy: 'increment', | ||
comment, | ||
}; | ||
}; | ||
|
||
const generateCreatedAtColumn = ( | ||
comment: string = '생성 일자', | ||
): TableColumnOptions => { | ||
return { | ||
name: 'created_at', | ||
type: 'timestamp', | ||
isNullable: false, | ||
default: 'CURRENT_TIMESTAMP', | ||
comment, | ||
}; | ||
}; | ||
|
||
export class NoticeBoardHistory1701328900610 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// 공지게시글 히스토리 | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: 'notice_board_history', | ||
columns: [ | ||
generatePrimaryColumn('공지 게시글 히스토리 고유 ID'), | ||
{ | ||
name: 'notice_board_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '공지 게시글 고유 ID', | ||
}, | ||
{ | ||
name: 'user_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '게시글 작성 유저 고유 ID', | ||
}, | ||
{ | ||
name: 'title', | ||
type: 'varchar', | ||
length: '255', | ||
isNullable: false, | ||
comment: '공지게시글 제목', | ||
}, | ||
{ | ||
name: 'description', | ||
type: 'text', | ||
isNullable: false, | ||
comment: '공지게시글 내용', | ||
}, | ||
{ | ||
name: 'allow_comment', | ||
type: 'tinyint', | ||
length: '1', | ||
unsigned: true, | ||
default: 1, | ||
isNullable: false, | ||
comment: '댓글 허용 여부 (0: 비활성화, 1: 허용)', | ||
}, | ||
generateCreatedAtColumn(), | ||
], | ||
foreignKeys: [ | ||
{ | ||
referencedTableName: 'notice_board', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['notice_board_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
{ | ||
referencedTableName: 'user', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['user_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
], | ||
}), | ||
); | ||
await queryRunner.query( | ||
'ALTER TABLE notice_board_history COMMENT = "공지 게시판 수정이력"', | ||
); | ||
|
||
// 공지게시글 댓글 수정이력 | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: 'notice_board_comment_history', | ||
columns: [ | ||
generatePrimaryColumn('공지게시글 댓글 수정이력 고유 ID'), | ||
{ | ||
name: 'user_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '댓글 작성 유저 고유 ID', | ||
}, | ||
{ | ||
name: 'notice_board_history_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '게시글 고유 ID', | ||
}, | ||
{ | ||
name: 'description', | ||
type: 'varchar', | ||
length: '255', | ||
isNullable: false, | ||
comment: '댓글 본문', | ||
}, | ||
{ | ||
name: 'isAnonymous', | ||
hobiJeong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: 'tinyint', | ||
length: '1', | ||
default: 0, | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '작성자 익명 여부 (0: 실명, 1: 익명)', | ||
}, | ||
generateCreatedAtColumn(), | ||
], | ||
foreignKeys: [ | ||
{ | ||
referencedTableName: 'user', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['user_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
{ | ||
referencedTableName: 'notice_board_history', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['notice_board_history_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
], | ||
}), | ||
); | ||
await queryRunner.query( | ||
'ALTER TABLE notice_board_comment_history COMMENT = "공지 게시글 댓글 수정이력"', | ||
); | ||
|
||
// 공지 게시글 대댓글 | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: 'notice_board_reply_comment_history', | ||
columns: [ | ||
generatePrimaryColumn('공지 게시글 대댓글 고유 ID'), | ||
hobiJeong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
name: 'notice_board_history_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '게시글 고유 ID', | ||
}, | ||
{ | ||
name: 'notice_board_comment_history_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '공지 게시글 댓글 고유 ID', | ||
}, | ||
{ | ||
name: 'user_id', | ||
type: 'int', | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '대댓글 작성 유저 고유 ID', | ||
}, | ||
{ | ||
name: 'description', | ||
type: 'varchar', | ||
length: '255', | ||
isNullable: false, | ||
comment: '대댓글 본문', | ||
}, | ||
{ | ||
name: 'isAnonymous', | ||
type: 'tinyint', | ||
length: '1', | ||
default: 0, | ||
unsigned: true, | ||
isNullable: false, | ||
comment: '작성자 익명 여부 (0: 실명, 1: 익명)', | ||
}, | ||
generateCreatedAtColumn(), | ||
], | ||
foreignKeys: [ | ||
{ | ||
referencedTableName: 'user', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['user_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
{ | ||
referencedTableName: 'notice_board_history', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['notice_board_history_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
{ | ||
referencedTableName: 'notice_board_comment_history', | ||
referencedColumnNames: ['id'], | ||
columnNames: ['notice_board_comment_history_id'], | ||
onDelete: 'NO ACTION', | ||
onUpdate: 'NO ACTION', | ||
}, | ||
], | ||
}), | ||
); | ||
await queryRunner.query( | ||
'ALTER TABLE notice_board_reply_comment_history COMMENT = "공지 게시판 대댓글 수정이력"', | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable( | ||
new Table({ name: 'notice_board_reply_comment_history' }), | ||
); | ||
await queryRunner.dropTable( | ||
new Table({ name: 'notice_board_comment_history' }), | ||
); | ||
await queryRunner.dropTable(new Table({ name: 'notice_board_history' })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NoticeBoardDto } from '../dto/notice-board.dto'; | ||
|
||
export const NOTICE_BOARD_ORDER_FIELD: readonly (keyof NoticeBoardDto)[] = [ | ||
'id', | ||
'userId', | ||
'title', | ||
'hit', | ||
'allowComment', | ||
'createdAt', | ||
'updatedAt', | ||
] as const; | ||
|
||
export const NOTICE_BOARD_TITLE_LENGTH = { | ||
MIN: 1, | ||
MAX: 255, | ||
} as const; | ||
|
||
export const NOTICE_BOARD_ALLOW_COMMENT_LENGTH = { | ||
hobiJeong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MIN: 0, | ||
MAX: 1, | ||
}; |
75 changes: 75 additions & 0 deletions
75
src/apis/notice-boards/controllers/notice-boards.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { faker } from '@faker-js/faker'; | ||
hobiJeong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserDto } from '@src/apis/users/dto/user.dto'; | ||
import { mockNoticeBoardsService } from '@test/mock/mock.service'; | ||
import { CreateNoticeBoardDto } from '../dto/create-notice-board.dto'; | ||
import { FindNoticeBoardListQueryDto } from '../dto/find-notice-board-list-query.dto'; | ||
import { NoticeBoardDto } from '../dto/notice-board.dto'; | ||
import { NoticeBoardsService } from '../services/notice-boards.service'; | ||
import { NoticeBoardsController } from './notice-boards.controller'; | ||
|
||
describe(NoticeBoardsController.name, () => { | ||
let controller: NoticeBoardsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [NoticeBoardsController], | ||
providers: [ | ||
{ | ||
provide: NoticeBoardsService, | ||
useValue: mockNoticeBoardsService, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
controller = module.get<NoticeBoardsController>(NoticeBoardsController); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe(NoticeBoardsController.prototype.create.name, () => { | ||
let user: UserDto; | ||
let createNoticeBoardDto: CreateNoticeBoardDto; | ||
|
||
let newNoticeBoard: NoticeBoardDto; | ||
|
||
beforeEach(() => { | ||
user = new UserDto(); | ||
createNoticeBoardDto = new CreateNoticeBoardDto(); | ||
|
||
newNoticeBoard = new NoticeBoardDto(); | ||
}); | ||
|
||
it('create notice board', async () => { | ||
user.id = faker.number.int(); | ||
|
||
mockNoticeBoardsService.create.mockResolvedValue(newNoticeBoard); | ||
|
||
await expect( | ||
controller.create(user, createNoticeBoardDto), | ||
).resolves.toEqual(newNoticeBoard); | ||
}); | ||
}); | ||
|
||
describe(NoticeBoardsController.prototype.findAllAndCount.name, () => { | ||
let findNoticeBoardListQueryDto: FindNoticeBoardListQueryDto; | ||
|
||
beforeEach(() => { | ||
findNoticeBoardListQueryDto = new FindNoticeBoardListQueryDto(); | ||
}); | ||
|
||
it('find all and count', async () => { | ||
mockNoticeBoardsService.findAllAndCount.mockResolvedValue([[], 0]); | ||
|
||
await expect( | ||
controller.findAllAndCount(findNoticeBoardListQueryDto), | ||
).resolves.toEqual([[], 0]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 원래 전에 notice_board 를 생성할 때 했어야하는 피드백인데 allow_comment 는 허용여부라는 의미를 정확하게 표현하지 못하는거같아요 is_allow_comment 같은 컬럼명으로 변경하는건 어떨까요??
변경한다면 notice_board table 도 같이 변경돼야할듯합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정하고 다시 리뷰요청 하겠습니다!