diff --git a/src/modules/foods/controllers/category.controller.ts b/src/modules/foods/controllers/category.controller.ts index d9dde36..b6c0842 100644 --- a/src/modules/foods/controllers/category.controller.ts +++ b/src/modules/foods/controllers/category.controller.ts @@ -17,8 +17,6 @@ import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; import { UseGuards } from '@nestjs/common'; import { RestId } from 'src/common/decorators'; -@UseGuards(AdminAuthGuard) -@ApiBearerAuth() @ApiTags('category') @Controller() export class CategoryController { diff --git a/src/modules/restaurants/controllers/public-restaurant.controller.ts b/src/modules/restaurants/controllers/public-restaurant.controller.ts deleted file mode 100644 index ce0920b..0000000 --- a/src/modules/restaurants/controllers/public-restaurant.controller.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Controller, Get, Param } from '@nestjs/common'; -import { RestaurantsService } from '../providers/restaurants.service'; -import { RestaurantSpecificationDto } from '../dto/restaurant-specification.dto'; -import { ApiTags, ApiOperation, ApiOkResponse, ApiParam, ApiNotFoundResponse } from '@nestjs/swagger'; - -@ApiTags('public/restaurants') -@Controller('public/restaurants') -export class PublicRestaurantController { - constructor(private readonly restaurantsService: RestaurantsService) {} - - @Get(':slug') - @ApiOperation({ summary: 'Get restaurant specification by slug' }) - @ApiParam({ name: 'slug', required: true, description: 'Restaurant slug' }) - @ApiOkResponse({ type: RestaurantSpecificationDto, description: 'Restaurant specification found' }) - @ApiNotFoundResponse({ description: 'Restaurant not found' }) - findBySlug(@Param('slug') slug: string): Promise { - return this.restaurantsService.getRestaurantSpecification(slug); - } -} - diff --git a/src/modules/restaurants/controllers/public-schedule.controller.ts b/src/modules/restaurants/controllers/public-schedule.controller.ts deleted file mode 100644 index 43f4a03..0000000 --- a/src/modules/restaurants/controllers/public-schedule.controller.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Controller, Get, Param } from '@nestjs/common'; -import { ScheduleService } from '../providers/schedule.service'; -import { Schedule } from '../entities/schedule.entity'; -import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger'; - -@ApiTags('public/schedules') -@Controller('public/schedules') -export class PublicScheduleController { - constructor(private readonly scheduleService: ScheduleService) {} - - @Get(':restId/today') - @ApiOperation({ summary: 'Get today schedule of a restaurant' }) - @ApiParam({ name: 'restId', description: 'Restaurant ID' }) - @ApiOkResponse({ description: 'Today schedule of the restaurant', type: Schedule }) - async getTodaySchedules(@Param('restId') restId: string): Promise { - return await this.scheduleService.findTodaySchedules(restId); - } -} diff --git a/src/modules/restaurants/controllers/restaurants.controller.ts b/src/modules/restaurants/controllers/restaurants.controller.ts index e46ef4f..62975d7 100644 --- a/src/modules/restaurants/controllers/restaurants.controller.ts +++ b/src/modules/restaurants/controllers/restaurants.controller.ts @@ -3,17 +3,33 @@ 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 { + ApiBearerAuth, + ApiBody, + ApiNotFoundResponse, + ApiOperation, + ApiParam, + ApiResponse, + ApiTags, +} from '@nestjs/swagger'; import { RestId } from 'src/common/decorators'; -@UseGuards(AdminAuthGuard) -@ApiBearerAuth() -@ApiTags('admin/restaurants') -@Controller('admin/restaurants') +@ApiTags('restaurants') +@Controller() export class RestaurantsController { constructor(private readonly restaurantsService: RestaurantsService) {} - @Post() + @Get('public/restaurants/:slug') + @ApiOperation({ summary: 'Get restaurant specification by slug' }) + @ApiParam({ name: 'slug', required: true, description: 'Restaurant slug' }) + @ApiNotFoundResponse({ description: 'Restaurant not found' }) + findBySlug(@Param('slug') slug: string) { + return this.restaurantsService.getRestaurantSpecification(slug); + } + + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Post('admin/restaurants') @ApiOperation({ summary: 'Create a new restaurant' }) @ApiBody({ type: CreateRestaurantDto }) @ApiResponse({ status: 201, description: 'Restaurant created' }) @@ -28,7 +44,9 @@ export class RestaurantsController { return this.restaurantsService.findAll(); } + @UseGuards(AdminAuthGuard) @ApiBearerAuth() + @ApiBearerAuth('admin/restaurants') @ApiOperation({ summary: 'Get restaurant by ID from request' }) @ApiResponse({ status: 200, description: 'Restaurant found' }) @ApiNotFoundResponse({ description: 'Restaurant not found' }) @@ -37,31 +55,34 @@ export class RestaurantsController { return await this.restaurantsService.findOne(restId); } + @UseGuards(AdminAuthGuard) @ApiBearerAuth() @ApiOperation({ summary: 'Update a restaurant' }) @ApiBody({ type: UpdateRestaurantDto }) @ApiResponse({ status: 200, description: 'Restaurant updated' }) @ApiNotFoundResponse({ type: NotFoundException, description: 'Restaurant not found' }) - @Patch(':id') + @Patch('admin/restaurants/:id') update(@Param('id') id: string, @Body() updateRestaurantDto: UpdateRestaurantDto) { return this.restaurantsService.update(id, updateRestaurantDto); } + @UseGuards(AdminAuthGuard) @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') + @Patch('admin/restaurants/my-restaurant') updateMyRestaurant(@RestId() restId: string, @Body() updateRestaurantDto: UpdateRestaurantDto) { return this.restaurantsService.update(restId, updateRestaurantDto); } + @UseGuards(AdminAuthGuard) @ApiBearerAuth() @ApiOperation({ summary: 'Delete a restaurant' }) @ApiResponse({ status: 200, description: 'Restaurant deleted' }) @ApiNotFoundResponse({ description: 'Restaurant not found' }) - @Delete(':id') + @Delete('admin/restaurants/:id') remove(@Param('id') id: string) { return this.restaurantsService.remove(id); } diff --git a/src/modules/restaurants/controllers/schedule.controller.ts b/src/modules/restaurants/controllers/schedule.controller.ts index a85cc5b..a459b0a 100644 --- a/src/modules/restaurants/controllers/schedule.controller.ts +++ b/src/modules/restaurants/controllers/schedule.controller.ts @@ -18,14 +18,22 @@ import { Schedule } from '../entities/schedule.entity'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; import { RestId } from 'src/common/decorators/rest-id.decorator'; -@UseGuards(AdminAuthGuard) -@ApiBearerAuth() -@ApiTags('admin/schedules') -@Controller('admin/schedules') +@ApiTags('schedules') +@Controller() export class ScheduleController { constructor(private readonly scheduleService: ScheduleService) {} - @Post() + @Get('public/schedules/restaurant/:slug/today') + @ApiOperation({ summary: 'Get today schedule of a restaurant' }) + @ApiParam({ name: 'slug', description: 'Restaurant Slug' }) + @ApiOkResponse({ description: 'Today schedule of the restaurant', type: Schedule }) + async getTodaySchedules(@Param('slug') slug: string): Promise { + return this.scheduleService.findTodaySchedules(slug); + } + + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Post('admin/schedules') @ApiOperation({ summary: 'Create a new schedule' }) @ApiBody({ type: CreateScheduleDto }) @ApiCreatedResponse({ description: 'Schedule created successfully', type: Schedule }) @@ -33,7 +41,9 @@ export class ScheduleController { return this.scheduleService.create(restId, createScheduleDto); } - @Get() + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Get('admin/schedules') @ApiOperation({ summary: 'Get all schedules' }) @ApiQuery({ name: 'weekDay', @@ -49,7 +59,9 @@ export class ScheduleController { return this.scheduleService.findAll(restId, query); } - @Get(':id') + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Get('admin/schedules/:id') @ApiOperation({ summary: 'Get a schedule by ID' }) @ApiParam({ name: 'id', description: 'Schedule ID' }) @ApiOkResponse({ description: 'Schedule details', type: Schedule }) @@ -58,7 +70,9 @@ export class ScheduleController { return this.scheduleService.findOne(id, restId); } - @Patch(':id') + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Patch('admin/schedules/:id') @ApiOperation({ summary: 'Update a schedule' }) @ApiParam({ name: 'id', description: 'Schedule ID' }) @ApiBody({ type: UpdateScheduleDto }) @@ -68,7 +82,9 @@ export class ScheduleController { return this.scheduleService.update(id, restId, updateScheduleDto); } - @Delete(':id') + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Delete('admin/schedules/:id') @ApiOperation({ summary: 'Delete a schedule' }) @ApiParam({ name: 'id', description: 'Schedule ID' }) @ApiOkResponse({ description: 'Schedule deleted successfully' }) diff --git a/src/modules/restaurants/providers/schedule.service.ts b/src/modules/restaurants/providers/schedule.service.ts index 6633427..b364bcb 100644 --- a/src/modules/restaurants/providers/schedule.service.ts +++ b/src/modules/restaurants/providers/schedule.service.ts @@ -7,6 +7,8 @@ import { CreateScheduleDto } from '../dto/create-schedule.dto'; import { UpdateScheduleDto } from '../dto/update-schedule.dto'; import { FindSchedulesDto } from '../dto/find-schedules.dto'; import { RestRepository } from '../repositories/rest.repository'; +import { Restaurant } from '../entities/restaurant.entity'; +import { RestMessage } from 'src/common/enums/message.enum'; // import { RestMessage } from 'src/common/enums/message.enum'; @Injectable() @@ -46,12 +48,16 @@ export class ScheduleService { return this.scheduleRepository.find(where, { orderBy: { weekDay: 'asc' } }); } - async findTodaySchedules(restId: string): Promise { + async findTodaySchedules(slug: string): Promise { + const restaurant = await this.em.findOne(Restaurant, { slug }); + if (!restaurant) { + throw new NotFoundException(RestMessage.NOT_FOUND); + } const today = new Date(); const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday const where: FilterQuery = { - restId, + restId: restaurant.id.toString(), weekDay, isActive: true, }; diff --git a/src/modules/restaurants/restaurants.module.ts b/src/modules/restaurants/restaurants.module.ts index 6e74309..b9d9121 100644 --- a/src/modules/restaurants/restaurants.module.ts +++ b/src/modules/restaurants/restaurants.module.ts @@ -1,7 +1,6 @@ import { Module, forwardRef } from '@nestjs/common'; import { RestaurantsService } from './providers/restaurants.service'; import { RestaurantsController } from './controllers/restaurants.controller'; -import { PublicRestaurantController } from './controllers/public-restaurant.controller'; import { MikroOrmModule } from '@mikro-orm/nestjs'; import { Restaurant } from './entities/restaurant.entity'; import { RestRepository } from './repositories/rest.repository'; @@ -9,12 +8,11 @@ import { ScheduleRepository } from './repositories/schedule.repository'; import { Schedule } from './entities/schedule.entity'; import { ScheduleService } from './providers/schedule.service'; import { ScheduleController } from './controllers/schedule.controller'; -import { PublicScheduleController } from './controllers/public-schedule.controller'; import { JwtModule } from '@nestjs/jwt'; import { AuthModule } from '../auth/auth.module'; @Module({ - controllers: [RestaurantsController, PublicRestaurantController, ScheduleController, PublicScheduleController], + controllers: [RestaurantsController, ScheduleController], providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService], imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule)], exports: [RestRepository, ScheduleRepository, ScheduleService],