Skip to content

Commit

Permalink
fix: 내 지도/코스 조회 페이지네이션 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
hyohyo12 committed Dec 4, 2024
1 parent fa638bf commit 8cc4392
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
8 changes: 6 additions & 2 deletions backend/src/course/CourseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export class CourseController {

@Get('/my')
@UseGuards(JwtAuthGuard)
async getMyCourses(@AuthUser() user: AuthUser) {
return await this.courseService.getMyCourses(user.userId);
async getMyCourses(
@AuthUser() user: AuthUser,
@Query('page', new ParseOptionalNumberPipe(1)) page?: number,
@Query('limit', new ParseOptionalNumberPipe(15)) limit?: number,
) {
return await this.courseService.getMyCourses(user.userId, page, limit);
}

@Get('/:id')
Expand Down
2 changes: 1 addition & 1 deletion backend/src/course/CourseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CourseService {
return new PagedCourseResponse(courses, totalCount, page, pageSize);
}

async getMyCourses(userId: number, page: number = 1, pageSize: number = 10) {
async getMyCourses(userId: number, page: number = 1, pageSize: number = 15) {
const [ownCourses, totalCount] = await Promise.all([
this.courseRepository.findByUserId(userId, page, pageSize),
this.courseRepository.countByUserId(userId),
Expand Down
8 changes: 6 additions & 2 deletions backend/src/map/MapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ export class MapController {

@UseGuards(JwtAuthGuard)
@Get('/my')
async getMyMaps(@AuthUser() user: AuthUser) {
return await this.mapService.getMyMaps(user.userId);
async getMyMaps(
@AuthUser() user: AuthUser,
@Query('page', new ParseOptionalNumberPipe(1)) page?: number,
@Query('limit', new ParseOptionalNumberPipe(15)) limit?: number,
) {
return await this.mapService.getMyMaps(user.userId, page, limit);
}

@Get('/:id')
Expand Down
2 changes: 1 addition & 1 deletion backend/src/map/MapRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class MapRepository extends SoftDeleteRepository<Map, number> {

countByUserId(userId: number) {
return this.count({
where: { id: userId },
where: { user: { id: userId } },
});
}

Expand Down
4 changes: 1 addition & 3 deletions backend/src/map/MapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ export class MapService {
);
}

async getMyMaps(userId: number, page: number = 1, pageSize: number = 10) {
async getMyMaps(userId: number, page: number = 1, pageSize: number = 15) {
const totalCount = await this.mapRepository.countByUserId(userId);

const ownMaps = await this.mapRepository.findByUserId(
userId,
page,
pageSize,
);

return new PagedMapResponse(
await Promise.all(ownMaps.map(MapListResponse.from)),
totalCount,
Expand Down

0 comments on commit 8cc4392

Please sign in to comment.