Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

내 지도,코스 조회 페이지네이션 파라미터 적용 #237

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading