-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding services for books (#11)
- Loading branch information
1 parent
dae0c4d
commit eaa82dd
Showing
18 changed files
with
371 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
HttpStatus, | ||
Param, | ||
Post, | ||
Put, | ||
Query, | ||
Res, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
import { Response } from 'express'; | ||
|
||
import { CreateBookDto, UpdateBookDto } from '~/app/book/book.dto'; | ||
import { BookService } from '~/app/book/book.service'; | ||
import { QuerySearchDto } from '~/app/author/author.dto'; | ||
import { JwtAuthGuard } from '~/app/auth/auth.guard'; | ||
import { RoleGuard } from '~/app/auth/role.guard'; | ||
import { Roles } from '~/app/auth/auth.decorator'; | ||
import { Role } from '~/types/role.enum'; | ||
|
||
@ApiTags('Book') | ||
@Controller('book') | ||
export class BookController { | ||
constructor(private readonly bookService: BookService) {} | ||
|
||
@Post('create') | ||
@ApiResponse({ | ||
status: 201, | ||
description: 'Create new book', | ||
}) | ||
@UseGuards(JwtAuthGuard, RoleGuard) | ||
@Roles([Role.ADMIN]) | ||
async create(@Body() body: CreateBookDto, @Res() res: Response) { | ||
const data = await this.bookService.create(body); | ||
|
||
return res.status(HttpStatus.CREATED).json(data); | ||
} | ||
|
||
@Get('show/:id') | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Get a book', | ||
}) | ||
async getById(@Param('id') id: string, @Res() res: Response) { | ||
const data = await this.bookService.getById(id); | ||
|
||
return res.status(HttpStatus.OK).json(data); | ||
} | ||
|
||
@Delete('delete/:id') | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Delete a book', | ||
}) | ||
@UseGuards(JwtAuthGuard, RoleGuard) | ||
@Roles([Role.ADMIN]) | ||
async delete(@Param('id') id: string, @Res() res: Response) { | ||
await this.bookService.delete(id); | ||
|
||
return res.status(HttpStatus.OK).send(); | ||
} | ||
|
||
@Put('update/:id') | ||
@ApiResponse({ | ||
status: 201, | ||
description: 'Update a book', | ||
}) | ||
@UseGuards(JwtAuthGuard, RoleGuard) | ||
@Roles([Role.ADMIN]) | ||
async update( | ||
@Body() body: UpdateBookDto, | ||
@Param('id') id: string, | ||
@Res() res: Response, | ||
) { | ||
const data = await this.bookService.update(id, body); | ||
|
||
return res.status(HttpStatus.OK).json(data); | ||
} | ||
|
||
@Get('search') | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Book search', | ||
}) | ||
async search(@Query() query: QuerySearchDto, @Res() res: Response) { | ||
const data = await this.bookService.search(query); | ||
|
||
return res.status(HttpStatus.OK).json(data); | ||
} | ||
} |
Oops, something went wrong.