Skip to content

Commit

Permalink
[v1.0.4] 응원 댓글 개수 조회 api 구현
Browse files Browse the repository at this point in the history
[v1.0.4] 응원 댓글 개수 조회 api 구현
  • Loading branch information
ImNM authored Aug 6, 2022
2 parents 2137fec + ceda0ac commit c48c5db
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/database/repositories/comment.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Role } from 'src/common/consts/enum';
import { Repository } from 'typeorm';
import { QueryBuilder, Repository } from 'typeorm';
import { Comment } from '../entities/comment.entity';
import { User } from '../entities/user.entity';
import { RequestCommentDto } from 'src/users/dtos/Comment.request.dto';
Expand All @@ -14,6 +14,7 @@ import { CommentDto } from 'src/users/dtos/Comment.dto';
import { UserProfileDto } from 'src/common/dtos/user-profile.dto';
import { RequestRandomCommentDto } from 'src/users/dtos/RandomComment.request.dto';
import { ResponseRandomCommentDto } from 'src/users/dtos/RandomComment.response.dto';
import { ResponseCommentNumDto } from 'src/users/dtos/CommentNum.response.dto';

@Injectable()
export class CommentRepository {
Expand Down Expand Up @@ -78,6 +79,21 @@ export class CommentRepository {
return new ResponseScrollCommentDto(entities, scrollMetaDto);
}

// 응원 댓글 갯수 조회
async getCommentNum() {
const queryBuilder = this.commentRepository.createQueryBuilder('comment');

queryBuilder
.getMany();

const commentNum = await queryBuilder.getCount();
const ret_commentNum = {
commentNum
};

return plainToInstance(ResponseCommentNumDto, ret_commentNum);
}

// 댓글 랜덤 조회
async getRandomComment(requestRandomCommentDto: RequestRandomCommentDto) {
const { take } = requestRandomCommentDto;
Expand Down
2 changes: 1 addition & 1 deletion src/users/dtos/Comment.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export class ResponseCommentDto {
} else {
return false;
}
} ;
};
}
11 changes: 11 additions & 0 deletions src/users/dtos/CommentNum.response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';

export class ResponseCommentNumDto {
@ApiProperty({
description: '응원 댓글 개수',
type: Number
})
@Expose()
public commentNum: number;
}
15 changes: 15 additions & 0 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ResponseUserTicketNumDto } from './dtos/UserTicketNum.response.dto';
import { RequestRandomCommentDto } from './dtos/RandomComment.request.dto';
import { ResponseRandomCommentDto } from './dtos/RandomComment.response.dto';
import { UserFindDto } from './dtos/UserFind.dto';
import { ResponseCommentNumDto } from './dtos/CommentNum.response.dto';

@ApiTags('users')
@ApiBearerAuth('accessToken')
Expand Down Expand Up @@ -155,6 +156,20 @@ export class UsersController {
return await this.userService.getAllComment(user.id, scrollOptionsDto);
}

// 응원 댓글 개수 조회
@ApiOperation({ summary: '응원 댓글 갯수 조회' })
@SuccessResponse(HttpStatus.OK, [
{
model: ResponseCommentNumDto,
exampleDescription: '응원 댓글 갯수 조회 성공시',
exampleTitle: '응원 댓글 갯수 조회 성공'
}
])
@Get('/comment/count')
async getCommentNum() {
return await this.userService.getCommentNum();
}

// 댓글 랜덤 조회
@ApiOperation({ summary: '댓글 랜덤 조회' })
@SuccessResponse(HttpStatus.OK, [
Expand Down
6 changes: 6 additions & 0 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ScrollOptionsDto } from './dtos/Scroll/ScrollOptions.dto';
import { ResponseScrollCommentsDto } from './dtos/Scroll/ScrollComments.response.dto';
import { RequestRandomCommentDto } from './dtos/RandomComment.request.dto';
import { UserFindDto } from './dtos/UserFind.dto';
import { ResponseCommentNumDto } from './dtos/CommentNum.response.dto';

@Injectable()
export class UsersService {
Expand Down Expand Up @@ -94,6 +95,11 @@ export class UsersService {
);
}

// 응원 댓글 갯수 조회
async getCommentNum() {
return await this.commentRepository.getCommentNum();
}

// 댓글 랜덤 조회
async getRandomComment(requestRandomCommentDto: RequestRandomCommentDto) {
return await this.commentRepository.getRandomComment(
Expand Down

0 comments on commit c48c5db

Please sign in to comment.