Skip to content

Commit

Permalink
Merge pull request #165 from LocalMingle/jonghwa
Browse files Browse the repository at this point in the history
[페이지네이션 수정]
  • Loading branch information
kimjonghwa230412 authored Nov 8, 2023
2 parents e9dc429 + bd1e9b7 commit 28754f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/events/events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class EventsController {
@Get()
@ApiOperation({ summary: 'Event 전체 조회' })
@ApiOkResponse({ type: EventEntity, isArray: true })
async findAll(@Query('lastPage', ParseIntPipe) lastPage: number) {
const events = await this.eventsService.findAll(lastPage);
async findAll(@Query('page', ParseIntPipe) page: number) {
const events = await this.eventsService.findAll(page);

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

// 2. 이벤트 전체 조회
async findAll(lastPage: number) {
async findAll(page: 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: 0,
...(lastPage && { cursor: { eventId: lastPage } }),
skip: page,
where: {
isDeleted: false,
},
Expand All @@ -77,7 +76,6 @@ export class EventsService {
},
});
await this.cacheManager.set('events', JSON.stringify(events));
console.log('events', events);
return events;
}
}
Expand Down

0 comments on commit 28754f0

Please sign in to comment.