Skip to content
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 40 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
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 Nov 29, 2023
9543658
modify/#66: modifying entities related to the notice-board
hobiJeong Nov 29, 2023
cf1ab64
modify/#66: modifying entity related to the notice-board
hobiJeong Nov 29, 2023
37e1837
feat/#66: create dto, constant
hobiJeong Nov 29, 2023
7d80f29
feat/#66: feat post api, modify dto
hobiJeong Nov 29, 2023
7a21900
feat/#66: create swagger api docs and set response
hobiJeong Nov 30, 2023
c54f62e
feat/#66: feat findAll and notice-board-history migrate
hobiJeong Nov 30, 2023
2ab2ad7
conflict/#66: conflict
hobiJeong Dec 3, 2023
3865fec
feat/#66: create dto, add and modify entities
hobiJeong Dec 3, 2023
9683159
modify/#66: modify entity
hobiJeong Dec 3, 2023
0d324e1
feat/#66: create api for post, getAll
hobiJeong Dec 3, 2023
4d5f325
feat/#66: create test code
hobiJeong Dec 3, 2023
b600416
refactor/#66: delete console.log
hobiJeong Dec 3, 2023
941b402
refactor/#66: modify string
hobiJeong Dec 3, 2023
782865b
modify/#66: modify Order type
hobiJeong Dec 3, 2023
b3a035f
modify/#66: modify Order type
hobiJeong Dec 3, 2023
62b4bd3
refactor/#66: modify NoticeBoard Create's key for swaggerBuilder
hobiJeong Dec 3, 2023
ebd5e47
feat/#66: add ApiBearerAuth
hobiJeong Dec 4, 2023
d266d56
modify/#66: modify string
hobiJeong Dec 4, 2023
8eae727
modify/#66: remove test code
hobiJeong Dec 4, 2023
75cf9e7
modify/#66: modify notice-board.constants
hobiJeong Dec 4, 2023
66da11a
modify/#66: modify entity
hobiJeong Dec 4, 2023
bbd65bf
modify/#66: modify migration file
hobiJeong Dec 4, 2023
10915d0
modify/#66: modify entities and migration
hobiJeong Dec 4, 2023
1fe7fd1
modify/#66: modify entities
hobiJeong Dec 4, 2023
9a7b052
refactor/#66: modify typo
hobiJeong Dec 4, 2023
8a206fe
modify/#66: modify dtos
hobiJeong Dec 4, 2023
0114f89
modify/#66: modify dtos
hobiJeong Dec 4, 2023
a293353
Update src/apis/notice-boards/services/notice-boards.service.ts
hobiJeong Dec 4, 2023
d4139d4
refactor/#66: use snake case
hobiJeong Dec 4, 2023
4b10111
refactor/#66: modify entity comment
hobiJeong Dec 4, 2023
be43d1e
Merge branch 'develop' into feat/#66/notice_board_crud
hobiJeong Dec 4, 2023
6da5f59
modify/#66: modify column name and dtos
hobiJeong Dec 4, 2023
cc35718
feat/#66: notice_board , notice_board_history migration
hobiJeong Dec 4, 2023
db84c46
modify/#66: 주석처리
hobiJeong Dec 4, 2023
39c7ba2
feat/#66: reflect #81 PR
hobiJeong Dec 4, 2023
4c58c85
feat/#66: add default value
hobiJeong Dec 5, 2023
6fba066
modify/#66: set default value
hobiJeong Dec 5, 2023
11403a3
modify/#66: delete ApiProperty
hobiJeong Dec 5, 2023
be27db6
Merge branch 'develop' into feat/#66/notice_board_crud
hobiJeong Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 247 additions & 0 deletions migrations/1701328900610-notice-board-history.ts
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',
Copy link
Member

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 도 같이 변경돼야할듯합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하고 다시 리뷰요청 하겠습니다!

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' }));
}
}
9 changes: 8 additions & 1 deletion src/apis/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { Module } from '@nestjs/common';
import { AuthModule } from './auth/auth.module';
import { FreeBoardsModule } from './free-boards/free-boards.module';
import { UsersModule } from './users/users.module';
import { NoticeBoardsModule } from './notice-boards/notice-boards.module';
import { MajorModule } from './major/major.module';

@Module({
imports: [AuthModule, UsersModule, FreeBoardsModule, MajorModule],
imports: [
AuthModule,
UsersModule,
FreeBoardsModule,
MajorModule,
NoticeBoardsModule,
],
})
export class ApiModule {}
21 changes: 21 additions & 0 deletions src/apis/notice-boards/constants/notice-board.constant.ts
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,
};
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]);
});
});
});
Loading