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

feat: reviews api 명세 작성 #52

Closed
wants to merge 8 commits into from
46 changes: 46 additions & 0 deletions backend/src/reviews/dto/reviews.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createZodDto } from '@anatine/zod-nestjs';
import {

Check warning on line 2 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L1-L2

Added lines #L1 - L2 were not covered by tests
createReviewsRequestSchema,
deleteReviewsPathSchema,
getMyReviewsRequestSchema,
getMyReviewsResponseSchema,
getReviewsRequestSchema,
getReviewsResponseSchema,
patchReviewsPathSchema,
updateReviewsPathSchema,
updateReviewsRequestSchema,
} from '../schema/reviews.schema';

export class CreateReviewsRequestDto extends createZodDto(

Check warning on line 14 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L14

Added line #L14 was not covered by tests
createReviewsRequestSchema,
) {}

export class GetReviewsRequestDto extends createZodDto(

Check warning on line 18 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L18

Added line #L18 was not covered by tests
getReviewsRequestSchema,
) {}

export class GetReviewsResponseDto extends createZodDto(

Check warning on line 22 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L22

Added line #L22 was not covered by tests
getReviewsResponseSchema,
) {}

export class GetMyReviewsRequestDto extends createZodDto(

Check warning on line 26 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L26

Added line #L26 was not covered by tests
getMyReviewsRequestSchema,
) {}

export class GetMyReviewsResponseDto extends createZodDto(

Check warning on line 30 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L30

Added line #L30 was not covered by tests
getMyReviewsResponseSchema,
) {}

export class UpdateReviewsPathDto extends createZodDto(

Check warning on line 34 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L34

Added line #L34 was not covered by tests
updateReviewsPathSchema,
) {}

export class UpdateReviewsRequestDto extends createZodDto(

Check warning on line 38 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L38

Added line #L38 was not covered by tests
updateReviewsRequestSchema,
) {}

export class PatchReviewsPathDto extends createZodDto(patchReviewsPathSchema) {}

Check warning on line 42 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L42

Added line #L42 was not covered by tests

export class DeleteReviewsPathDto extends createZodDto(

Check warning on line 44 in backend/src/reviews/dto/reviews.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/dto/reviews.dto.ts#L44

Added line #L44 was not covered by tests
deleteReviewsPathSchema,
) {}
292 changes: 292 additions & 0 deletions backend/src/reviews/reviews.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
import {

Check warning on line 1 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L1

Added line #L1 was not covered by tests
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Patch,
Post,
Put,
Query,
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

Check warning on line 14 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'ApiTags' is defined but never used

Check warning on line 14 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'ApiTags' is defined but never used

Check warning on line 14 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'ApiTags' is defined but never used
import {

Check warning on line 15 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L14-L15

Added lines #L14 - L15 were not covered by tests
CreateReviewsRequestDto,
DeleteReviewsPathDto,

Check warning on line 17 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'DeleteReviewsPathDto' is defined but never used

Check warning on line 17 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'DeleteReviewsPathDto' is defined but never used

Check warning on line 17 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'DeleteReviewsPathDto' is defined but never used
GetMyReviewsRequestDto,
GetMyReviewsResponseDto,
GetReviewsRequestDto,
GetReviewsResponseDto,
PatchReviewsPathDto,

Check warning on line 22 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'PatchReviewsPathDto' is defined but never used

Check warning on line 22 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'PatchReviewsPathDto' is defined but never used

Check warning on line 22 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'PatchReviewsPathDto' is defined but never used
UpdateReviewsPathDto,

Check warning on line 23 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'UpdateReviewsPathDto' is defined but never used

Check warning on line 23 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'UpdateReviewsPathDto' is defined but never used

Check warning on line 23 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'UpdateReviewsPathDto' is defined but never used
UpdateReviewsRequestDto,
} from './dto/reviews.dto';

@Controller('reviews')
export class ReviewsController {
constructor() {}

Check warning on line 29 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L28-L29

Added lines #L28 - L29 were not covered by tests

@Post()
@HttpCode(HttpStatus.CREATED)
@ApiOperation({
summary: '책 리뷰를 작성한다.',
description:
'책 리뷰를 작성한다. content 길이는 10글자 이상 420글자 이하로 입력하여야 한다.',
tags: ['reviews'],
})
@ApiResponse({
status: 201,
description: '리뷰가 DB에 정상적으로 insert됨.',
})
@ApiResponse({
status: 400,
description: '잘못된 요청.',
schema: {
type: 'object',
example: {
errorCode: 801,
},
},
})
@ApiResponse({
status: 401,
description: '권한 없음.',
schema: {
type: 'object',
oneOf: [
{ example: { errorCode: 100 } }, // 토큰 누락
{ example: { errorCode: 101 } }, // 토큰 유저 존재하지 않음
{ example: { errorCode: 108 } }, // 토큰 만료
{ example: { errorCode: 109 } }, // 토큰 유효하지 않음
],
},
})
async createReviews(@Body() createReviewsDto: CreateReviewsRequestDto) {}

Check warning on line 66 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'createReviewsDto' is defined but never used

Check warning on line 66 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'createReviewsDto' is defined but never used

Check warning on line 66 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'createReviewsDto' is defined but never used

Check warning on line 66 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L66

Added line #L66 was not covered by tests

@Get()
@HttpCode(HttpStatus.OK)
@ApiOperation({
summary: '책 리뷰 10개를 반환한다.',
description:
'책 리뷰 10개를 반환한다. 최종 페이지의 경우 1 <= n <= 10 개의 값이 반환될 수 있다. content에는 리뷰에 대한 정보를, finalPage 에는 해당 페이지가 마지막인지에 대한 여부를 boolean 값으로 반환한다.',
tags: ['reviews'],
})
@ApiResponse({
status: 200,
description: '리뷰 목록과 메타데이터를 반환합니다.',
type: GetReviewsResponseDto,
})
@ApiResponse({
status: 400,
description: '잘못된 요청.',
schema: {
type: 'object',
oneOf: [
{ example: { errorCode: 2 } }, // 적절하지 않는 bookInfoId 값
{ example: { errorCode: 2 } }, // 적절하지 않는 userId 값
{ example: { errorCode: 2 } }, // 적절하지 않는 page 값
{ example: { errorCode: 2 } }, // 적절하지 않는 sort 값
],
},
})
@ApiResponse({
status: 401,
description: '권한 없음.',
schema: {
type: 'object',
oneOf: [
{ example: { errorCode: 100 } }, // 토큰 누락
{ example: { errorCode: 100 } }, // 사서 권한 없음
{ example: { errorCode: 101 } }, // 토큰 유저 존재하지 않음
{ example: { errorCode: 108 } }, // 토큰 만료
{ example: { errorCode: 109 } }, // 토큰 유효하지 않음
],
},
})
async getReviews(@Query() getReviewsRequestDto: GetReviewsRequestDto) {}

Check warning on line 108 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'getReviewsRequestDto' is defined but never used

Check warning on line 108 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'getReviewsRequestDto' is defined but never used

Check warning on line 108 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'getReviewsRequestDto' is defined but never used

Check warning on line 108 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L108

Added line #L108 was not covered by tests

@Get('my-reviews')
@ApiOperation({
description:
'자기자신에 대한 모든 Review 데이터를 가져온다. 내부적으로 getReview와 같은 함수를 사용한다.',
tags: ['reviews'],
})
@ApiResponse({
status: 200,
description: 'Successful response',
type: GetMyReviewsResponseDto,
})
@ApiResponse({
status: 400,
description: 'Bad Request',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
examples: {
invalidPageValue: {
value: { errorCode: 2 },
},
invalidSortValue: {
value: { errorCode: 2 },
},
},
},
},
})
@ApiResponse({
status: 401,
description: 'Unauthorized',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
examples: {
tokenMissing: {
value: { errorCode: 100 },
},
userNotFound: {
value: { errorCode: 101 },
},
tokenExpired: {
value: { errorCode: 108 },
},
tokenInvalid: {
value: { errorCode: 109 },
},
},
},
},
})
async getMyReviews(@Query() getMyReviewsRequestDto: GetMyReviewsRequestDto) {}

Check warning on line 171 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / autofix

'getMyReviewsRequestDto' is defined but never used

Check warning on line 171 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (20)

'getMyReviewsRequestDto' is defined but never used

Check warning on line 171 in backend/src/reviews/reviews.controller.ts

View workflow job for this annotation

GitHub Actions / build (22)

'getMyReviewsRequestDto' is defined but never used

Check warning on line 171 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L171

Added line #L171 was not covered by tests

@Put(':reviewsId')
@ApiOperation({
description:
'책 리뷰를 수정한다. 작성자만 수정할 수 있다. content 길이는 10글자 이상 100글자 이하로 입력하여야 한다.',
tags: ['reviews'],
})
@ApiResponse({
status: 200,
description: '리뷰가 DB에 정상적으로 update됨.',
})
@ApiResponse({
status: 400,
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
},
},
})
@ApiResponse({
status: 401,
description: '권한 없음.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
},
},
})
@ApiResponse({
status: 404,
description: '존재하지 않는 reviewsId.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
},
},
})
async putReviews(

Check warning on line 224 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L224

Added line #L224 was not covered by tests
@Param('reviewsId') reviewsId: number,
@Body() updateReviewsRequestDto: UpdateReviewsRequestDto,

Check warning on line 226 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L226

Added line #L226 was not covered by tests
) {}

@Patch(':reviewsId')
@ApiOperation({
description: '책 리뷰의 비활성화 여부를 토글 방식으로 변환',
tags: ['reviews'],
})
@ApiResponse({
status: 200,
description: '리뷰가 DB에 정상적으로 fetch됨.',
})
async patchReviews(@Param('reviewsId') reviewsId: number) {}

Check warning on line 238 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L238

Added line #L238 was not covered by tests

@Delete(':reviewsId')
@ApiOperation({
description:
'책 리뷰를 삭제한다. 작성자와 사서 권한이 있는 사용자만 삭제할 수 있다.',
tags: ['reviews'],
})
@ApiResponse({
status: 200,
description: '리뷰가 DB에서 정상적으로 delete됨.',
})
@ApiResponse({
status: 400,
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
},
},
})
@ApiResponse({
status: 401,
description: '권한 없음.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
},
},
})
@ApiResponse({
status: 404,
description: '존재하지 않는 reviewsId.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
errorCode: { type: 'integer' },
},
},
},
},
})
async deleteReviews(@Param('reviewsId') reviewsId: number) {}

Check warning on line 291 in backend/src/reviews/reviews.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.controller.ts#L291

Added line #L291 was not covered by tests
}
10 changes: 10 additions & 0 deletions backend/src/reviews/reviews.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { ReviewsController } from './reviews.controller';
import { ReviewsService } from './reviews.service';

Check warning on line 3 in backend/src/reviews/reviews.module.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.module.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

@Module({
controllers: [ReviewsController],
providers: [ReviewsService],
imports: [],
})
export class ReviewsModule {}

Check warning on line 10 in backend/src/reviews/reviews.module.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.module.ts#L10

Added line #L10 was not covered by tests
4 changes: 4 additions & 0 deletions backend/src/reviews/reviews.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

Check warning on line 1 in backend/src/reviews/reviews.service.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.service.ts#L1

Added line #L1 was not covered by tests

@Injectable()
export class ReviewsService {}

Check warning on line 4 in backend/src/reviews/reviews.service.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/reviews/reviews.service.ts#L4

Added line #L4 was not covered by tests
Loading
Loading