Skip to content

Commit

Permalink
feat: 해당 유저가 설정한 리마인더의 개수를 반환하는 api 구현 - Quickchive#180
Browse files Browse the repository at this point in the history
현재 reminder가 비어있다면 카운트하도록 되어있음
알람 보낼 때 리마인더에 설정된 값을 지우는 작업이 필요함
  • Loading branch information
hou27 committed Mar 23, 2023
1 parent cee5d2f commit 15a195e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/contents/contents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
LoadFavoritesOutput,
LoadPersonalContentsOutput,
} from './dtos/load-personal-contents.dto';
import { LoadReminderCountOutput } from './dtos/load-personal-remider-count.dto';

@Controller('contents')
@ApiTags('Contents')
Expand Down Expand Up @@ -260,6 +261,23 @@ export class ContentsController {
return await this.contentsService.loadFavorites(user);
}

@ApiOperation({
summary: '자신의 리마인더 개수 조회',
description: '자신의 리마인더 개수를 조회하는 메서드',
})
@ApiOkResponse({
description: '설정되어있는 리마인더 개수를 반환한다.',
type: LoadReminderCountOutput,
})
@ApiBearerAuth('Authorization')
@UseGuards(JwtAuthGuard)
@Get('load-reminder-count')
async loadReminderCount(
@AuthUser() user: User,
): Promise<LoadReminderCountOutput> {
return await this.contentsService.loadReminderCount(user);
}

@ApiOperation({
summary: '콘텐츠 문서 요약',
description: '콘텐츠의 문서를 요약하는 메서드',
Expand Down
17 changes: 17 additions & 0 deletions src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { User } from '../users/entities/user.entity';
import { Category } from './entities/category.entity';
import { Content } from './entities/content.entity';
import { CategoryRepository } from './repository/category.repository';
import { LoadReminderCountOutput } from './dtos/load-personal-remider-count.dto';

@Injectable()
export class ContentsService {
Expand Down Expand Up @@ -449,6 +450,22 @@ export class ContentsService {
}
}

async loadReminderCount(user: User): Promise<LoadReminderCountOutput> {
try {
const reminderCount = await this.contents
.createQueryBuilder('content')
.where('content.userId = :userId', { userId: user.id })
.andWhere('content.reminder IS NULL')
.getCount();

return {
count: reminderCount,
};
} catch (e) {
throw e;
}
}

async summarizeContent(
user: User,
contentId: number,
Expand Down
9 changes: 9 additions & 0 deletions src/contents/dtos/load-personal-remider-count.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { CoreOutput } from '../../common/dtos/output.dto';

export class LoadReminderCountOutput extends CoreOutput {
@ApiProperty({
description: '설정된 리마인더 개수',
})
count!: number;
}

0 comments on commit 15a195e

Please sign in to comment.