import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiCreatedResponse, ApiOkResponse, ApiNotFoundResponse, ApiParam, ApiBody, ApiBearerAuth, ApiHeader, } from '@nestjs/swagger'; import { DeliveryService } from '../providers/delivery.service'; import { CreateDeliveryDto } from '../dto/create-delivery.dto'; import { UpdateDeliveryDto } from '../dto/update-delivery.dto'; import { ShopId } from 'src/common/decorators/rest-id.decorator'; import { AuthGuard } from 'src/modules/auth/guards/auth.guard'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; import { Delivery } from '../entities/delivery.entity'; import { API_HEADER_SLUG } from 'src/common/constants'; import { Permission } from 'src/common/enums/permission.enum'; import { Permissions } from 'src/common/decorators/permissions.decorator'; @ApiTags('Delivery') @Controller() export class DeliveryController { constructor(private readonly deliveryService: DeliveryService) { } @UseGuards(AuthGuard) @ApiBearerAuth() @Get('public/delivery-methods/shop') @ApiOperation({ summary: 'Get shop delivery methods' }) @ApiHeader(API_HEADER_SLUG) findAllDeliveryMethods(@ShopId() restId: string) { return this.deliveryService.findAllForRestaurantId(restId); } /*** Admin ***/ @UseGuards(AdminAuthGuard) @ApiBearerAuth() @Permissions(Permission.MANAGE_DELIVERY) @Post('admin/delivery-methods/shop') @ApiOperation({ summary: 'Create a delivery method for a shop' }) @ApiBody({ type: CreateDeliveryDto }) create(@Body() createDto: CreateDeliveryDto, @ShopId() restId: string) { return this.deliveryService.create(restId, createDto); } @UseGuards(AdminAuthGuard) @ApiBearerAuth() @Permissions(Permission.MANAGE_DELIVERY) @Get('admin/delivery-methods/shop') @ApiOperation({ summary: 'Get the shop delivery methods' }) findRestaurantDeliveryMethods(@ShopId() restId: string) { return this.deliveryService.findAllForRestaurantId(restId); } @UseGuards(AdminAuthGuard) @ApiBearerAuth() @Permissions(Permission.MANAGE_DELIVERY) @Get('admin/delivery-methods/shop/:deliveryId') @ApiOperation({ summary: 'Get a shop delivery method by delivery ID' }) @ApiParam({ name: 'deliveryId', description: 'Delivery method ID' }) findOne(@Param('deliveryId') deliveryId: string, @ShopId() restId: string) { return this.deliveryService.findOne(restId, deliveryId); } @UseGuards(AdminAuthGuard) @ApiBearerAuth() @Permissions(Permission.MANAGE_DELIVERY) @Patch('admin/delivery-methods/shop/:deliveryId') @ApiOperation({ summary: 'Update a shop delivery method' }) @ApiParam({ name: 'deliveryId', description: 'Delivery method ID' }) @ApiBody({ type: UpdateDeliveryDto }) update(@Param('deliveryId') deliveryId: string, @Body() updateDto: UpdateDeliveryDto, @ShopId() restId: string) { return this.deliveryService.update(restId, deliveryId, updateDto); } @UseGuards(AdminAuthGuard) @ApiBearerAuth() @Permissions(Permission.MANAGE_DELIVERY) @Delete('admin/delivery-methods/shop/:deliveryId') @ApiOperation({ summary: 'Delete a shop delivery method' }) @ApiParam({ name: 'deliveryId', description: 'Delivery method ID' }) remove(@Param('deliveryId') deliveryId: string, @ShopId() restId: string) { return this.deliveryService.remove(restId, deliveryId); } }