Skip to content

Commit ff854b2

Browse files
committed
feat: 질문지 상세 페이지에 scrapCount 추가
1 parent 50a59b9 commit ff854b2

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

backend/src/question-list/dto/question-list-contents.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface QuestionListContentsDto {
88
usage: number;
99
username: string;
1010
isScrap: boolean;
11+
scrapCount: number;
1112
}

backend/src/question-list/question-list.controller.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,6 @@ export class QuestionListController {
165165
try {
166166
const userId = token ? token.userId : null;
167167

168-
if (!userId) {
169-
// 로그인 안함
170-
// isScrap: false
171-
// 비공개 질문 접근 불가 처리
172-
}
173-
174168
const { questionListId } = body;
175169
const questionListContents: QuestionListContentsDto =
176170
await this.questionListService.getQuestionListContents(questionListId, userId);

backend/src/question-list/question-list.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export class QuestionListService {
140140
? await this.questionListRepository.isQuestionListScrapped(id, userId)
141141
: false;
142142

143+
const scrapCount = await this.questionListRepository.getScrapCount(id);
144+
143145
const questionListContents: QuestionListContentsDto = {
144146
id,
145147
title,
@@ -148,6 +150,7 @@ export class QuestionListService {
148150
usage,
149151
username,
150152
isScrap,
153+
scrapCount: parseInt(scrapCount.count),
151154
};
152155

153156
return questionListContents;

backend/src/question-list/repository/question-list.repository.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export class QuestionListRepository extends Repository<QuestionList> {
6868
.then((result) => !!result);
6969
}
7070

71+
getScrapCount(questionListId: number) {
72+
return this.createQueryBuilder("question_list")
73+
.innerJoin("question_list.scrappedByUsers", "user")
74+
.where("question_list.id = :questionListId", { questionListId })
75+
.select("COUNT(user.id)", "count")
76+
.getRawOne();
77+
}
78+
7179
async paginate(paginateDto: PaginateDto) {
7280
const { queryBuilder, skip, take, field, direction } = paginateDto;
7381
return await queryBuilder

0 commit comments

Comments
 (0)