Skip to content

Commit

Permalink
Merge pull request #162 from LocalMingle/jonghwa
Browse files Browse the repository at this point in the history
[작업완료]: 페이지네이션 적용
  • Loading branch information
kimjonghwa230412 authored Nov 7, 2023
2 parents 5de9d58 + ee832e1 commit 1f03adb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/events/events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UploadedFile,
UseInterceptors,
UnauthorizedException,
Query,
} from '@nestjs/common';
import {
ApiBearerAuth,
Expand Down Expand Up @@ -58,8 +59,8 @@ export class EventsController {
@Get()
@ApiOperation({ summary: 'Event 전체 조회' })
@ApiOkResponse({ type: EventEntity, isArray: true })
async findAll() {
const events = await this.eventsService.findAll();
async findAll(@Query('lastPage', ParseIntPipe) lastPage: number) {
const events = await this.eventsService.findAll(lastPage);

// 전체 조회 시 이벤트 호스트와 참가자 수 반환
const event = events.map((item) => {
Expand Down
7 changes: 5 additions & 2 deletions src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ export class EventsService {
}

// 2. 이벤트 전체 조회
async findAll() {
const cachedEvents: any = await this.cacheManager.get('events');
async findAll(lastPage: number) {
const cachedEvents:any = await this.cacheManager.get('events');
const cachedData = cachedEvents ? JSON.parse(cachedEvents) : null;
if (cachedData) {
return cachedData;
} else {
const events = await this.prisma.event.findMany({
take: 4,
skip: lastPage ? 1 : 0,
...(lastPage && {cursor: {eventId: lastPage}}),
where: {
isDeleted: false,
},
Expand Down

0 comments on commit 1f03adb

Please sign in to comment.