diff --git a/src/events/events.controller.ts b/src/events/events.controller.ts index b50702b..7b51d00 100644 --- a/src/events/events.controller.ts +++ b/src/events/events.controller.ts @@ -13,6 +13,7 @@ import { UploadedFile, UseInterceptors, UnauthorizedException, + Query, } from '@nestjs/common'; import { ApiBearerAuth, @@ -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) => { diff --git a/src/events/events.service.ts b/src/events/events.service.ts index 5f03dce..50cae1c 100644 --- a/src/events/events.service.ts +++ b/src/events/events.service.ts @@ -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, },