Skip to content

Commit

Permalink
refactor: page를 body로 받기
Browse files Browse the repository at this point in the history
  • Loading branch information
son-daehyeon committed Sep 14, 2024
1 parent cc12eba commit a519ef2
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 21 deletions.
10 changes: 6 additions & 4 deletions src/domain/activity/project/controller/project.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Body, Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
import { Body, Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';

import {
GetProjectRequestDto,
GetProjectResponseDto,
GetProjectsPageResponseDto,
GetProjectsRequestDto,
GetProjectsResponseDto,
} from '@wink/activity/dto';
import { ProjectNotFoundException } from '@wink/activity/exception';
Expand Down Expand Up @@ -33,10 +34,11 @@ export class ProjectController {
return this.projectService.getProjectsPage();
}

@Get('/:page')
@Get()
@ApiOperation({ summary: '프로젝트 목록' })
@ApiProperty({ type: GetProjectsRequestDto })
@ApiCustomResponse(GetProjectsResponseDto)
async getProjects(@Param('page', ParseIntPipe) page: number): Promise<GetProjectsResponseDto> {
return this.projectService.getProjects(page);
async getProjects(@Body() request: GetProjectsRequestDto): Promise<GetProjectsResponseDto> {
return this.projectService.getProjects(request);
}
}
1 change: 1 addition & 0 deletions src/domain/activity/project/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export * from './request/create-project.request.dto';
export * from './request/update-project.request.dto';
export * from './request/get-project.request.dto';
export * from './request/get-projects.request.dto';
export * from './request/delete-project.request.dto';

// Response
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';

import { CommonValidation, TypeValidation } from '@wink/validation';

export class GetProjectsRequestDto {
@ApiProperty({
description: '페이지',
example: 1,
})
@CommonValidation.IsNotEmpty()
@TypeValidation.IsNumber()
page!: number;
}
3 changes: 2 additions & 1 deletion src/domain/activity/project/service/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GetProjectRequestDto,
GetProjectResponseDto,
GetProjectsPageResponseDto,
GetProjectsRequestDto,
GetProjectsResponseDto,
} from '@wink/activity/dto';
import { ProjectRepository } from '@wink/activity/repository';
Expand All @@ -30,7 +31,7 @@ export class ProjectService {
return { page };
}

async getProjects(page: number): Promise<GetProjectsResponseDto> {
async getProjects({ page }: GetProjectsRequestDto): Promise<GetProjectsResponseDto> {
const projects = await this.projectRepository.findAllPage(page);

return { projects };
Expand Down
22 changes: 12 additions & 10 deletions src/domain/activity/study/controller/study.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Body, Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';

import {
GetCategoriesResponseDto,
GetStudiesPageResponse,
GetStudiesResponse,
GetStudiesPageResponseDto,
GetStudiesRequestDto,
GetStudiesResponseDto,
} from '@wink/activity/dto';
import { StudyService } from '@wink/activity/service';

Expand All @@ -24,15 +25,16 @@ export class StudyController {

@Get('/max')
@ApiOperation({ summary: '스터디 최대 페이지' })
@ApiCustomResponse(GetStudiesPageResponse)
async getStudiesPage(): Promise<GetStudiesPageResponse> {
@ApiCustomResponse(GetStudiesPageResponseDto)
async getStudiesPage(): Promise<GetStudiesPageResponseDto> {
return this.studyService.getStudiesPage();
}

@Get('/:page')
@Get()
@ApiOperation({ summary: '스터디 목록' })
@ApiCustomResponse(GetStudiesResponse)
async getStudies(@Param('page', ParseIntPipe) page: number): Promise<GetStudiesResponse> {
return this.studyService.getStudies(page);
@ApiProperty({ type: GetStudiesRequestDto })
@ApiCustomResponse(GetStudiesResponseDto)
async getStudies(@Body() request: GetStudiesRequestDto): Promise<GetStudiesResponseDto> {
return this.studyService.getStudies(request);
}
}
1 change: 1 addition & 0 deletions src/domain/activity/study/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './request/create-category.request.dto';
export * from './request/create-study.request.dto';
export * from './request/delete-category.request.dto';
export * from './request/delete-study.request.dto';
export * from './request/get-studies.request.dto';
export * from './request/update-category.request.dto';

// Response
Expand Down
13 changes: 13 additions & 0 deletions src/domain/activity/study/dto/request/get-studies.request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';

import { CommonValidation, TypeValidation } from '@wink/validation';

export class GetStudiesRequestDto {
@ApiProperty({
description: '페이지',
example: 1,
})
@CommonValidation.IsNotEmpty()
@TypeValidation.IsNumber()
page!: number;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class GetStudiesPageResponse {
export class GetStudiesPageResponseDto {
@ApiProperty({
description: '최대 페이지',
example: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';

import { Study } from '@wink/activity/schema';

export class GetStudiesResponse {
export class GetStudiesResponseDto {
@ApiProperty({
description: '스터디 목록',
type: [Study],
Expand Down
9 changes: 5 additions & 4 deletions src/domain/activity/study/service/study.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Injectable } from '@nestjs/common';

import {
GetCategoriesResponseDto,
GetStudiesPageResponse,
GetStudiesResponse,
GetStudiesPageResponseDto,
GetStudiesRequestDto,
GetStudiesResponseDto,
} from '@wink/activity/dto';
import { StudyRepository, CategoryRepository } from '@wink/activity/repository';

Expand All @@ -20,13 +21,13 @@ export class StudyService {
return { categories };
}

async getStudies(page: number): Promise<GetStudiesResponse> {
async getStudies({ page }: GetStudiesRequestDto): Promise<GetStudiesResponseDto> {
const studies = await this.studyRepository.findAllPage(page);

return { studies };
}

async getStudiesPage(): Promise<GetStudiesPageResponse> {
async getStudiesPage(): Promise<GetStudiesPageResponseDto> {
const studies = await this.studyRepository.findAll();
const page = Math.ceil(studies.length / 10);

Expand Down

0 comments on commit a519ef2

Please sign in to comment.