Skip to content

Commit

Permalink
notice posts crud hit (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong authored Dec 15, 2023
2 parents edefa74 + 5777d3f commit 78a5108
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 121 deletions.
6 changes: 3 additions & 3 deletions migrations/1700634679995-notice-board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class NoticeBoard1700634679995 implements MigrationInterface {
comment: '조회수',
},
{
name: 'is_allow_comment',
name: 'allow_comment',
type: 'tinyint',
length: '1',
unsigned: true,
Expand Down Expand Up @@ -190,7 +190,7 @@ export class NoticeBoard1700634679995 implements MigrationInterface {
comment: '댓글 본문',
},
{
name: 'is_anonymous',
name: 'isAnonymous',
type: 'tinyint',
length: '1',
default: 0,
Expand Down Expand Up @@ -316,7 +316,7 @@ export class NoticeBoard1700634679995 implements MigrationInterface {
comment: '대댓글 본문',
},
{
name: 'is_anonymous',
name: 'isAnonymous',
type: 'tinyint',
length: '1',
default: 0,
Expand Down
6 changes: 3 additions & 3 deletions migrations/1701328900610-notice-board-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class NoticeBoardHistory1701328900610 implements MigrationInterface {
comment: '공지게시글 내용',
},
{
name: 'is_allow_comment',
name: 'allow_comment',
type: 'boolean',
default: 1,
isNullable: false,
Expand Down Expand Up @@ -126,7 +126,7 @@ export class NoticeBoardHistory1701328900610 implements MigrationInterface {
comment: '댓글 본문',
},
{
name: 'is_anonymous',
name: 'isAnonymous',
type: 'boolean',
default: 0,
isNullable: false,
Expand Down Expand Up @@ -191,7 +191,7 @@ export class NoticeBoardHistory1701328900610 implements MigrationInterface {
comment: '대댓글 본문',
},
{
name: 'is_anonymous',
name: 'isAnonymous',
type: 'boolean',
default: 0,
isNullable: false,
Expand Down
222 changes: 111 additions & 111 deletions migrations/1701696068699-notice-board-change-column-name.ts
Original file line number Diff line number Diff line change
@@ -1,123 +1,123 @@
// import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

// export class NoticeBoardChangeColumnName1701696068699
// implements MigrationInterface
// {
// public async up(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.changeColumn(
// 'notice_board',
// 'allow_comment',
// new TableColumn({
// name: 'is_allow_comment',
// type: 'boolean',
// default: true,
// isNullable: false,
// comment: '댓글 허용 여부 (0: 비활성화, 1: 허용)',
// }),
// );
export class NoticeBoardChangeColumnName1701696068699
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.changeColumn(
'notice_board',
'allow_comment',
new TableColumn({
name: 'is_allow_comment',
type: 'boolean',
default: true,
isNullable: false,
comment: '댓글 허용 여부 (0: 비활성화, 1: 허용)',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_comment',
// 'isAnonymous',
// new TableColumn({
// name: 'is_anonymous',
// type: 'tinyint',
// }),
// );
await queryRunner.changeColumn(
'notice_board_comment',
'isAnonymous',
new TableColumn({
name: 'is_anonymous',
type: 'tinyint',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_reply_comment',
// 'isAnonymous',
// new TableColumn({
// name: 'is_anonymous',
// type: 'tinyint',
// }),
// );
await queryRunner.changeColumn(
'notice_board_reply_comment',
'isAnonymous',
new TableColumn({
name: 'is_anonymous',
type: 'tinyint',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_history',
// 'allow_comment',
// new TableColumn({
// name: 'is_allow_comment',
// type: 'boolean',
// default: true,
// isNullable: false,
// comment: '댓글 허용 여부 (0: 비활성화, 1: 허용)',
// }),
// );
await queryRunner.changeColumn(
'notice_board_history',
'allow_comment',
new TableColumn({
name: 'is_allow_comment',
type: 'boolean',
default: true,
isNullable: false,
comment: '댓글 허용 여부 (0: 비활성화, 1: 허용)',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_comment_history',
// 'isAnonymous',
// new TableColumn({
// name: 'is_anonymous',
// type: 'tinyint',
// }),
// );
await queryRunner.changeColumn(
'notice_board_comment_history',
'isAnonymous',
new TableColumn({
name: 'is_anonymous',
type: 'tinyint',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_reply_comment_history',
// 'isAnonymous',
// new TableColumn({
// name: 'is_anonymous',
// type: 'tinyint',
// }),
// );
// }
await queryRunner.changeColumn(
'notice_board_reply_comment_history',
'isAnonymous',
new TableColumn({
name: 'is_anonymous',
type: 'tinyint',
}),
);
}

// public async down(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.changeColumn(
// 'notice_board',
// 'is_allow_comment',
// new TableColumn({
// name: 'allow_comment',
// type: 'boolean',
// }),
// );
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.changeColumn(
'notice_board',
'is_allow_comment',
new TableColumn({
name: 'allow_comment',
type: 'boolean',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_comment',
// 'is_anonymous',
// new TableColumn({
// name: 'isAnonymous',
// type: 'tinyint',
// }),
// );
await queryRunner.changeColumn(
'notice_board_comment',
'is_anonymous',
new TableColumn({
name: 'isAnonymous',
type: 'tinyint',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_reply_comment',
// 'is_anonymous',
// new TableColumn({
// name: 'isAnonymous',
// type: 'tinyint',
// }),
// );
await queryRunner.changeColumn(
'notice_board_reply_comment',
'is_anonymous',
new TableColumn({
name: 'isAnonymous',
type: 'tinyint',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_history',
// 'is_allow_comment',
// new TableColumn({
// name: 'allow_comment',
// type: 'boolean',
// }),
// );
await queryRunner.changeColumn(
'notice_board_history',
'is_allow_comment',
new TableColumn({
name: 'allow_comment',
type: 'boolean',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_comment_history',
// 'is_anonymous',
// new TableColumn({
// name: 'isAnonymous',
// type: 'tinyint',
// }),
// );
await queryRunner.changeColumn(
'notice_board_comment_history',
'is_anonymous',
new TableColumn({
name: 'isAnonymous',
type: 'tinyint',
}),
);

// await queryRunner.changeColumn(
// 'notice_board_reply_comment_history',
// 'is_anonymous',
// new TableColumn({
// name: 'isAnonymous',
// type: 'tinyint',
// }),
// );
// }
// }
await queryRunner.changeColumn(
'notice_board_reply_comment_history',
'is_anonymous',
new TableColumn({
name: 'isAnonymous',
type: 'tinyint',
}),
);
}
}
11 changes: 11 additions & 0 deletions src/apis/notice-posts/controllers/notice-posts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Put,
Query,
UseGuards,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import { CreateNoticePostDto } from '../dto/create-notice-post.dto';
import { NoticePostsService } from '../services/notice-posts.service';
Expand Down Expand Up @@ -109,4 +111,13 @@ export class NoticePostsController {
): Promise<number> {
return this.noticePostService.remove(user.id, noticePostId);
}

@ApiNoticePost.IncreaseHit({ summary: '조회수 1 증가' })
@HttpCode(HttpStatus.NO_CONTENT)
@Put(':noticePostId/hit')
increaseHit(
@Param('noticePostId', ParsePositiveIntPipe) noticePostId: number,
): Promise<void> {
return this.noticePostService.increaseHit(noticePostId);
}
}
36 changes: 32 additions & 4 deletions src/apis/notice-posts/controllers/notice-posts.swagger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpStatus, applyDecorators } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiProperty } from '@nestjs/swagger';
import { ApiBearerAuth, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
import { COMMON_ERROR_CODE } from '@src/constants/error/common/common-error-code.constant';
import { HttpException } from '@src/http-exceptions/exceptions/http.exception';
Expand Down Expand Up @@ -109,7 +109,7 @@ export const ApiNoticePost: ApiOperator<keyof NoticePostsController> = {
Partial<OperationObject>,
): PropertyDecorator => {
return applyDecorators(
ApiProperty({
ApiOperation({
operationId: 'NoticePostPutUpdate',
...apiOperationOptions,
}),
Expand Down Expand Up @@ -147,7 +147,7 @@ export const ApiNoticePost: ApiOperator<keyof NoticePostsController> = {
Partial<OperationObject>,
): PropertyDecorator => {
return applyDecorators(
ApiProperty({
ApiOperation({
operationId: 'NoticePostPatchUpdate',
...apiOperationOptions,
}),
Expand Down Expand Up @@ -185,7 +185,7 @@ export const ApiNoticePost: ApiOperator<keyof NoticePostsController> = {
Partial<OperationObject>,
): PropertyDecorator => {
return applyDecorators(
ApiProperty({
ApiOperation({
operationId: 'NoticePostRemove',
...apiOperationOptions,
}),
Expand Down Expand Up @@ -214,4 +214,32 @@ export const ApiNoticePost: ApiOperator<keyof NoticePostsController> = {
]),
);
},

IncreaseHit: (
apiOperationOptions: Required<Pick<Partial<OperationObject>, 'summary'>> &
Partial<OperationObject>,
): PropertyDecorator => {
return applyDecorators(
ApiOperation({
operationId: 'NoticePostIncreaseHit',
...apiOperationOptions,
}),
ApiResponse({ status: HttpStatus.NO_CONTENT }),
HttpException.swaggerBuilder(
HttpStatus.BAD_REQUEST,
[COMMON_ERROR_CODE.INVALID_REQUEST_PARAMETER],
{
description:
'해당 필드는 request parameter 가 잘못된 경우에만 리턴됩니다.',
type: ValidationError,
},
),
HttpException.swaggerBuilder(HttpStatus.NOT_FOUND, [
COMMON_ERROR_CODE.RESOURCE_NOT_FOUND,
]),
HttpException.swaggerBuilder(HttpStatus.INTERNAL_SERVER_ERROR, [
COMMON_ERROR_CODE.SERVER_ERROR,
]),
);
},
};
3 changes: 3 additions & 0 deletions src/apis/notice-posts/notice-posts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { QueryHelper } from '@src/helpers/query.helper';
import { NoticePostsController } from './controllers/notice-posts.controller';
import { NoticePostHistoryModule } from './notice-post-history/notice-posts-history.module';
import { NoticePostsService } from './services/notice-posts.service';
import { CommonPostsModule } from '../common-posts/common-posts.module';
import { NoticePost } from '@src/entities/NoticePost';

@Module({
imports: [
TypeOrmExModule.forCustomRepository([NoticePostRepository]),
CommonPostsModule.forFeature(NoticePost),
NoticePostHistoryModule,
],
controllers: [NoticePostsController],
Expand Down
Loading

0 comments on commit 78a5108

Please sign in to comment.