diff --git a/migrations/1700634679995-notice-board.ts b/migrations/1700634679995-notice-board.ts index 4b4e1879..a22cac6c 100644 --- a/migrations/1700634679995-notice-board.ts +++ b/migrations/1700634679995-notice-board.ts @@ -80,7 +80,7 @@ export class NoticeBoard1700634679995 implements MigrationInterface { comment: '조회수', }, { - name: 'is_allow_comment', + name: 'allow_comment', type: 'tinyint', length: '1', unsigned: true, @@ -190,7 +190,7 @@ export class NoticeBoard1700634679995 implements MigrationInterface { comment: '댓글 본문', }, { - name: 'is_anonymous', + name: 'isAnonymous', type: 'tinyint', length: '1', default: 0, @@ -316,7 +316,7 @@ export class NoticeBoard1700634679995 implements MigrationInterface { comment: '대댓글 본문', }, { - name: 'is_anonymous', + name: 'isAnonymous', type: 'tinyint', length: '1', default: 0, diff --git a/migrations/1701328900610-notice-board-history.ts b/migrations/1701328900610-notice-board-history.ts index 8aedd993..bd47e38c 100644 --- a/migrations/1701328900610-notice-board-history.ts +++ b/migrations/1701328900610-notice-board-history.ts @@ -68,7 +68,7 @@ export class NoticeBoardHistory1701328900610 implements MigrationInterface { comment: '공지게시글 내용', }, { - name: 'is_allow_comment', + name: 'allow_comment', type: 'boolean', default: 1, isNullable: false, @@ -126,7 +126,7 @@ export class NoticeBoardHistory1701328900610 implements MigrationInterface { comment: '댓글 본문', }, { - name: 'is_anonymous', + name: 'isAnonymous', type: 'boolean', default: 0, isNullable: false, @@ -191,7 +191,7 @@ export class NoticeBoardHistory1701328900610 implements MigrationInterface { comment: '대댓글 본문', }, { - name: 'is_anonymous', + name: 'isAnonymous', type: 'boolean', default: 0, isNullable: false, diff --git a/migrations/1701696068699-notice-board-change-column-name.ts b/migrations/1701696068699-notice-board-change-column-name.ts index 11b979de..7030372e 100644 --- a/migrations/1701696068699-notice-board-change-column-name.ts +++ b/migrations/1701696068699-notice-board-change-column-name.ts @@ -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 { -// 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 { + 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 { -// await queryRunner.changeColumn( -// 'notice_board', -// 'is_allow_comment', -// new TableColumn({ -// name: 'allow_comment', -// type: 'boolean', -// }), -// ); + public async down(queryRunner: QueryRunner): Promise { + 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', + }), + ); + } +} diff --git a/src/apis/notice-posts/controllers/notice-posts.controller.ts b/src/apis/notice-posts/controllers/notice-posts.controller.ts index 583f3ed6..0199f6d4 100644 --- a/src/apis/notice-posts/controllers/notice-posts.controller.ts +++ b/src/apis/notice-posts/controllers/notice-posts.controller.ts @@ -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'; @@ -109,4 +111,13 @@ export class NoticePostsController { ): Promise { 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 { + return this.noticePostService.increaseHit(noticePostId); + } } diff --git a/src/apis/notice-posts/controllers/notice-posts.swagger.ts b/src/apis/notice-posts/controllers/notice-posts.swagger.ts index 6fca0e84..3ea6d59a 100644 --- a/src/apis/notice-posts/controllers/notice-posts.swagger.ts +++ b/src/apis/notice-posts/controllers/notice-posts.swagger.ts @@ -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'; @@ -109,7 +109,7 @@ export const ApiNoticePost: ApiOperator = { Partial, ): PropertyDecorator => { return applyDecorators( - ApiProperty({ + ApiOperation({ operationId: 'NoticePostPutUpdate', ...apiOperationOptions, }), @@ -147,7 +147,7 @@ export const ApiNoticePost: ApiOperator = { Partial, ): PropertyDecorator => { return applyDecorators( - ApiProperty({ + ApiOperation({ operationId: 'NoticePostPatchUpdate', ...apiOperationOptions, }), @@ -185,7 +185,7 @@ export const ApiNoticePost: ApiOperator = { Partial, ): PropertyDecorator => { return applyDecorators( - ApiProperty({ + ApiOperation({ operationId: 'NoticePostRemove', ...apiOperationOptions, }), @@ -214,4 +214,32 @@ export const ApiNoticePost: ApiOperator = { ]), ); }, + + IncreaseHit: ( + apiOperationOptions: Required, 'summary'>> & + Partial, + ): 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, + ]), + ); + }, }; diff --git a/src/apis/notice-posts/notice-posts.module.ts b/src/apis/notice-posts/notice-posts.module.ts index 08f5c264..70384708 100644 --- a/src/apis/notice-posts/notice-posts.module.ts +++ b/src/apis/notice-posts/notice-posts.module.ts @@ -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], diff --git a/src/apis/notice-posts/services/notice-posts.service.ts b/src/apis/notice-posts/services/notice-posts.service.ts index d2c5e90d..33869e1e 100644 --- a/src/apis/notice-posts/services/notice-posts.service.ts +++ b/src/apis/notice-posts/services/notice-posts.service.ts @@ -16,6 +16,8 @@ import { PutUpdateNoticePostDto } from '../dto/put-update-notice-post.dto'; import { PatchUpdateNoticePostDto } from '../dto/patch-update-notice-post.dto'; import { HttpBadRequestException } from '@src/http-exceptions/exceptions/http-bad-request.exception'; import { NoticePostRepository } from '../repositories/notice-post.repository'; +import { CommonPostsService } from '@src/apis/common-posts/services/common-posts.service'; +import { NoticePost } from '@src/entities/NoticePost'; @Injectable() export class NoticePostsService { @@ -29,6 +31,7 @@ export class NoticePostsService { private readonly noticePostHistoryService: NoticePostHistoryService, private readonly dataSource: DataSource, private readonly noticePostRepository: NoticePostRepository, + private readonly commonPostsService: CommonPostsService, ) {} async create(userId: number, createNoticePostDto: CreateNoticePostDto) { @@ -315,4 +318,8 @@ export class NoticePostsService { } } } + + async increaseHit(noticePostId: number): Promise { + return this.commonPostsService.incrementHit(noticePostId); + } }