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

notice posts crud hit #103

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
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,
]),
);
},
};
2 changes: 2 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,12 @@ 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';

@Module({
imports: [
TypeOrmExModule.forCustomRepository([NoticePostRepository]),
CommonPostsModule.forFeature(NoticePostRepository),
Copy link
Member

Choose a reason for hiding this comment

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

#102 에서 주입받는 방법이 변경돼서 해당 PR 반영되면 수정해서 리리퀘스트 주실 수 있나요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 알겠습니다!

NoticePostHistoryModule,
],
controllers: [NoticePostsController],
Expand Down
6 changes: 6 additions & 0 deletions src/apis/notice-posts/services/notice-posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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';

@Injectable()
export class NoticePostsService {
Expand All @@ -29,6 +30,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) {
Expand Down Expand Up @@ -315,4 +317,8 @@ export class NoticePostsService {
}
}
}

async increaseHit(noticePostId: number): Promise<void> {
return this.commonPostsService.incrementHit(noticePostId);
}
}