category.controller.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { JwtGuard } from '@/common/guards';
  2. import {
  3. Body,
  4. Controller,
  5. Delete,
  6. Get,
  7. Param,
  8. Patch,
  9. Post,
  10. Query,
  11. UseGuards,
  12. } from '@nestjs/common';
  13. import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
  14. import { CategoryService } from './category.service';
  15. import { CreateCategoryDto, GetAllCategoryDto, GetCategoryDto, UpdateCategoryDto } from './dto';
  16. @Controller('category')
  17. @ApiTags('category')
  18. @ApiBearerAuth('JWT')
  19. @UseGuards(JwtGuard)
  20. export class CategoryController {
  21. constructor(private readonly categoryService: CategoryService) {}
  22. @Post()
  23. create(@Body() createCategoryDto: CreateCategoryDto) {
  24. return this.categoryService.create(createCategoryDto);
  25. }
  26. @Get()
  27. getAllCategories(@Query() getAllCategoryDto: GetAllCategoryDto) {
  28. return this.categoryService.findAll(getAllCategoryDto);
  29. }
  30. @Get('tree')
  31. getAllCategoriesTree(@Query() getAllCategoryDto: GetAllCategoryDto) {
  32. return this.categoryService.findAllWithTree(getAllCategoryDto);
  33. }
  34. @Get('page')
  35. findPagination(@Query() queryDto: GetCategoryDto) {
  36. return this.categoryService.findPagination(queryDto);
  37. }
  38. @Delete(':id')
  39. remove(@Param('id') id: string) {
  40. return this.categoryService.remove(+id);
  41. }
  42. @Patch(':id')
  43. update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) {
  44. return this.categoryService.update(+id, updateCategoryDto);
  45. }
  46. }