cart
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { CartService } from '../providers/cart.service';
|
||||
import { CreateCartDto } from '../dto/create-cart.dto';
|
||||
import { UpdateCartDto } from '../dto/update-cart.dto';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiBody } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '../../auth/guards/auth.guard';
|
||||
import { UserId } from 'src/common/decorators/user-id.decorator';
|
||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('cart')
|
||||
@Controller('cart')
|
||||
export class CartController {
|
||||
constructor(private readonly cartService: CartService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create or update user cart' })
|
||||
@ApiBody({ type: CreateCartDto })
|
||||
@ApiResponse({ status: 201, description: 'Cart created successfully' })
|
||||
async create(@UserId() userId: string, @RestId() restaurantId: string, @Body() createCartDto: CreateCartDto) {
|
||||
return this.cartService.create(userId, restaurantId, createCartDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get all active carts for the current user' })
|
||||
@ApiResponse({ status: 200, description: 'Carts retrieved successfully' })
|
||||
async findAll(@UserId() userId: string) {
|
||||
return this.cartService.findByUser(userId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a specific cart by ID' })
|
||||
@ApiResponse({ status: 200, description: 'Cart retrieved successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Cart not found' })
|
||||
async findOne(@Param('id') id: string, @UserId() userId: string) {
|
||||
return this.cartService.findOne(id, userId);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiOperation({ summary: 'Update a cart' })
|
||||
@ApiBody({ type: UpdateCartDto })
|
||||
@ApiResponse({ status: 200, description: 'Cart updated successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Cart not found' })
|
||||
async update(@Param('id') id: string, @Body() updateCartDto: UpdateCartDto, @UserId() userId: string) {
|
||||
return this.cartService.update(id, userId, updateCartDto);
|
||||
}
|
||||
|
||||
@Delete('clear')
|
||||
@ApiOperation({ summary: 'Clear all active carts for the current user' })
|
||||
@ApiResponse({ status: 200, description: 'All carts cleared successfully' })
|
||||
async clearAll(@UserId() userId: string) {
|
||||
return this.cartService.clearUserCart(userId);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a cart (soft delete)' })
|
||||
@ApiResponse({ status: 200, description: 'Cart deleted successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Cart not found' })
|
||||
async remove(@Param('id') id: string, @UserId() userId: string) {
|
||||
return this.cartService.remove(id, userId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user