This commit is contained in:
2025-11-25 09:58:13 +03:30
parent fdbc3c9dbe
commit a5992d8e29
4 changed files with 36 additions and 27 deletions
@@ -19,15 +19,25 @@ import { RestId } from 'src/common/decorators';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiTags('admin/categories')
@Controller('admin/categories')
@ApiTags('category')
@Controller()
export class CategoryController {
constructor(private readonly categoryService: CategoryService) {}
@Get('public/categories/restaurant/:slug')
@ApiOperation({ summary: 'Get all categories by restaurant slug' })
@ApiParam({ name: 'slug', required: true, description: 'Restaurant Slug' })
@ApiOkResponse({ description: 'List of all categories for the restaurant' })
findAllByRestaurant(@Param('slug') slug: string) {
return this.categoryService.findAllByRestaurant(slug);
}
@ApiOperation({ summary: 'Create category' })
@ApiCreatedResponse({ description: 'Category created', type: CreateCategoryDto })
@ApiBody({ type: CreateCategoryDto })
@Post()
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Post('admin/categories')
create(@Body() dto: CreateCategoryDto) {
return this.categoryService.create(dto);
}
@@ -36,14 +46,18 @@ export class CategoryController {
@ApiOkResponse({ description: 'List of categories' })
@ApiQuery({ name: 'restId', required: false, type: String })
@ApiQuery({ name: 'isActive', required: false, type: Boolean })
@Get()
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/categories')
findAll(@RestId() restId: string, @Query('isActive') isActive?: string) {
// convert isActive from query string to boolean when provided
const isActiveBool: boolean | undefined = typeof isActive !== 'undefined' ? isActive === 'true' : undefined;
return this.categoryService.findAll({ restId, isActive: isActiveBool });
}
@Get(':id')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/categories/:id')
@ApiOperation({ summary: 'Get category' })
@ApiOkResponse({ description: 'Category detail', type: CreateCategoryDto })
@ApiNotFoundResponse({ description: 'Category not found' })
@@ -52,7 +66,9 @@ export class CategoryController {
return this.categoryService.findOne(restId, id);
}
@Patch(':id')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Patch('admin/categories/:id')
@ApiOperation({ summary: 'Update category' })
@ApiParam({ name: 'id' })
@ApiBody({ type: UpdateCategoryDto })
@@ -61,7 +77,9 @@ export class CategoryController {
return this.categoryService.update(restId, id, dto);
}
@Delete(':id')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Delete('admin/categories/:id')
@ApiOperation({ summary: 'Delete category' })
@ApiParam({ name: 'id' })
@ApiOkResponse({ description: 'Deleted' })