72 lines
3.0 KiB
TypeScript
72 lines
3.0 KiB
TypeScript
import { Controller, Get, Post, Body, Patch, Param, UseGuards, Delete, NotFoundException } from '@nestjs/common';
|
|
import { RestaurantsService } from '../providers/restaurants.service';
|
|
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
|
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
|
import { ApiBearerAuth, ApiBody, ApiNotFoundResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { RestId } from 'src/common/decorators';
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiTags('admin/restaurants')
|
|
@Controller('admin/restaurants')
|
|
export class RestaurantsController {
|
|
constructor(private readonly restaurantsService: RestaurantsService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a new restaurant' })
|
|
@ApiBody({ type: CreateRestaurantDto })
|
|
@ApiResponse({ status: 201, description: 'Restaurant created' })
|
|
create(@Body() createRestaurantDto: CreateRestaurantDto) {
|
|
return this.restaurantsService.create(createRestaurantDto);
|
|
}
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Get all restaurants' })
|
|
@ApiResponse({ status: 200, description: 'Restaurants found' })
|
|
@Get()
|
|
findAll() {
|
|
return this.restaurantsService.findAll();
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Get a restaurant by slug' })
|
|
@ApiResponse({ status: 200, description: 'Restaurant found' })
|
|
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
|
|
@Get(':slug')
|
|
@ApiOperation({ summary: 'Get a restaurant by slug' })
|
|
@ApiResponse({ status: 200, description: 'Restaurant found' })
|
|
@ApiNotFoundResponse({ description: 'Restaurant not found' })
|
|
findOne(@Param('slug') slug: string) {
|
|
return this.restaurantsService.findBySlug(slug);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Update a restaurant' })
|
|
@ApiBody({ type: UpdateRestaurantDto })
|
|
@ApiResponse({ status: 200, description: 'Restaurant updated' })
|
|
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
|
|
@Patch(':id')
|
|
update(@Param('id') id: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
|
|
return this.restaurantsService.update(id, updateRestaurantDto);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Update a restaurant' })
|
|
@ApiBody({ type: UpdateRestaurantDto })
|
|
@ApiResponse({ status: 200, description: 'Restaurant updated' })
|
|
@ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' })
|
|
@Patch('my-restaurant')
|
|
updateMyRestaurant(@RestId() restId: string, @Body() updateRestaurantDto: UpdateRestaurantDto) {
|
|
return this.restaurantsService.update(restId, updateRestaurantDto);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@ApiOperation({ summary: 'Delete a restaurant' })
|
|
@ApiResponse({ status: 200, description: 'Restaurant deleted' })
|
|
@ApiNotFoundResponse({ description: 'Restaurant not found' })
|
|
@Delete(':id')
|
|
remove(@Param('id') id: string) {
|
|
return this.restaurantsService.remove(id);
|
|
}
|
|
}
|