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

fix: book 경로 id 검사 추가 #83

Merged
merged 1 commit into from
Dec 22, 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
11 changes: 6 additions & 5 deletions backend/src/books/books.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
CreateBookCopyResponseDto,
BookCopySearchResponseDto,
UpdateBookRequestDto,
BookIDDto,
} from './dto/books.dto';
import { PaginationOptionsDto } from 'src/common/dtos/page-options.dto';

Expand Down Expand Up @@ -77,7 +78,7 @@
description: '도서 상세 정보 조회 성공',
type: BookDetailResponseDto,
})
async findOne(@Param('id') id: number): Promise<BookDetailResponseDto> {
async findOne(@Param() { id }: BookIDDto): Promise<BookDetailResponseDto> {

Check warning on line 81 in backend/src/books/books.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/books/books.controller.ts#L81

Added line #L81 was not covered by tests
const book = await this.booksService.findOne(id);
if (!book) {
throw new NotFoundException(`Book with ID ${id} not found`);
Expand All @@ -95,7 +96,7 @@
type: CreateBookCopyResponseDto,
})
async createCopy(
@Param('id') id: number,
@Param() { id }: BookIDDto,
@Body() createBookCopyDto: CreateBookCopyRequestDto,
): Promise<CreateBookCopyResponseDto> {
return this.booksService.createCopy(id, createBookCopyDto);
Expand All @@ -110,7 +111,7 @@
type: BookCopySearchResponseDto,
})
async findCopies(
@Param('id') id: number,
@Param() { id }: BookIDDto,

Check warning on line 114 in backend/src/books/books.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/books/books.controller.ts#L114

Added line #L114 was not covered by tests
): Promise<BookCopySearchResponseDto> {
return this.booksService.findCopies(id);
}
Expand All @@ -125,7 +126,7 @@
type: BookDto,
})
async update(
@Param('id') id: number,
@Param() { id }: BookIDDto,
@Body() updateBookDto: UpdateBookRequestDto,
): Promise<BookDto> {
return this.booksService.update(id, updateBookDto);
Expand All @@ -138,7 +139,7 @@
status: 204,
description: '도서 삭제 성공',
})
async remove(@Param('id') id: number): Promise<void> {
async remove(@Param() { id }: BookIDDto): Promise<void> {

Check warning on line 142 in backend/src/books/books.controller.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/books/books.controller.ts#L142

Added line #L142 was not covered by tests
await this.booksService.remove(id);
}
}
1 change: 1 addition & 0 deletions backend/src/books/dto/books.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { createZodDto } from '@anatine/zod-nestjs';
import { extendApi } from '@anatine/zod-openapi';
import { createPageSchema } from 'src/common/dtos/page.dto';
import { metaSchema } from 'src/common/dtos/meta.dto';

Check warning on line 5 in backend/src/books/dto/books.dto.ts

View workflow job for this annotation

GitHub Actions / build (20)

'metaSchema' is defined but never used

Check warning on line 5 in backend/src/books/dto/books.dto.ts

View workflow job for this annotation

GitHub Actions / autofix

'metaSchema' is defined but never used

Check warning on line 5 in backend/src/books/dto/books.dto.ts

View workflow job for this annotation

GitHub Actions / build (22)

'metaSchema' is defined but never used
import { intSchema } from 'src/dto';

const imageSchema = extendApi(z.string().url().nullable(), {
Expand Down Expand Up @@ -79,6 +79,7 @@
export class BookDto extends createZodDto(bookSchema) {}
export class CategoryDto extends createZodDto(categorySchema) {}
export class BookCopyDto extends createZodDto(bookCopySchema) {}
export class BookIDDto extends createZodDto(bookSchema.pick({ id: true })) {}

Check warning on line 82 in backend/src/books/dto/books.dto.ts

View check run for this annotation

Codecov / codecov/patch

backend/src/books/dto/books.dto.ts#L82

Added line #L82 was not covered by tests
export class BookSearchResultDto extends createZodDto(bookSearchResultSchema) {}
export class BookGetResponseDto extends createZodDto(bookGetResponseSchema) {}
export class BookDetailResponseDto extends createZodDto(
Expand Down
Loading