update cart
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Controller, Get, Post, Body, Patch, Delete, UseGuards, Param } from '@nestjs/common';
|
||||
import { CartService } from '../providers/cart.service';
|
||||
import { AddItemToCartDto } from '../dto/add-item.dto';
|
||||
import { BulkAddItemsToCartDto } from '../dto/bulk-add-items.dto';
|
||||
import { UpdateItemQuantityDto } from '../dto/update-item.dto';
|
||||
import { ApplyCouponDto } from '../dto/apply-coupon.dto';
|
||||
@@ -26,14 +25,23 @@ export class CartController {
|
||||
return this.cartService.findOne(userId, restaurantId);
|
||||
}
|
||||
|
||||
@Post('items')
|
||||
@ApiOperation({ summary: 'Add item to cart (increments quantity if item exists)' })
|
||||
@ApiBody({ type: AddItemToCartDto })
|
||||
@ApiResponse({ status: 201, description: 'Item added to cart successfully' })
|
||||
@Post('items/:foodId/increment')
|
||||
@ApiOperation({ summary: 'Increment item quantity in cart by 1' })
|
||||
@ApiParam({ name: 'foodId', description: 'Food ID to increment in cart' })
|
||||
@ApiResponse({ status: 201, description: 'Item incremented in cart successfully' })
|
||||
@ApiResponse({ status: 400, description: 'Bad request (e.g., insufficient stock)' })
|
||||
@ApiResponse({ status: 404, description: 'Food not found' })
|
||||
async addItem(@UserId() userId: string, @RestId() restaurantId: string, @Body() addItemDto: AddItemToCartDto) {
|
||||
return this.cartService.addItem(userId, restaurantId, addItemDto);
|
||||
async incrementItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
return this.cartService.incrementItem(userId, restaurantId, foodId);
|
||||
}
|
||||
|
||||
@Post('items/:foodId/decrement')
|
||||
@ApiOperation({ summary: 'Decrement item quantity in cart by 1 (removes item if quantity reaches 0)' })
|
||||
@ApiParam({ name: 'foodId', description: 'Food ID to decrement in cart' })
|
||||
@ApiResponse({ status: 200, description: 'Item decremented in cart successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Item not found in cart' })
|
||||
async decrementItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
return this.cartService.decrementItem(userId, restaurantId, foodId);
|
||||
}
|
||||
|
||||
@Post('items/bulk')
|
||||
@@ -50,9 +58,9 @@ export class CartController {
|
||||
return this.cartService.bulkAddItems(userId, restaurantId, bulkAddItemsDto);
|
||||
}
|
||||
|
||||
@Patch('items/:itemId')
|
||||
@Patch('items/:foodId')
|
||||
@ApiOperation({ summary: 'Update item quantity in cart' })
|
||||
@ApiParam({ name: 'itemId', description: 'Item ID in the cart' })
|
||||
@ApiParam({ name: 'foodId', description: 'Food ID in the cart' })
|
||||
@ApiBody({ type: UpdateItemQuantityDto })
|
||||
@ApiResponse({ status: 200, description: 'Item quantity updated successfully' })
|
||||
@ApiResponse({ status: 400, description: 'Bad request (e.g., insufficient stock)' })
|
||||
@@ -60,19 +68,19 @@ export class CartController {
|
||||
async updateItemQuantity(
|
||||
@UserId() userId: string,
|
||||
@RestId() restaurantId: string,
|
||||
@Param('itemId') itemId: string,
|
||||
@Param('foodId') foodId: string,
|
||||
@Body() updateItemDto: UpdateItemQuantityDto,
|
||||
) {
|
||||
return this.cartService.updateItemQuantity(userId, restaurantId, itemId, updateItemDto);
|
||||
return this.cartService.updateItemQuantity(userId, restaurantId, foodId, updateItemDto);
|
||||
}
|
||||
|
||||
@Delete('items/:itemId')
|
||||
@Delete('items/:foodId')
|
||||
@ApiOperation({ summary: 'Remove item from cart' })
|
||||
@ApiParam({ name: 'itemId', description: 'Item ID in the cart' })
|
||||
@ApiParam({ name: 'foodId', description: 'Food ID in the cart' })
|
||||
@ApiResponse({ status: 200, description: 'Item removed from cart successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Item not found in cart' })
|
||||
async removeItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('itemId') itemId: string) {
|
||||
return this.cartService.removeItem(userId, restaurantId, itemId);
|
||||
async removeItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
return this.cartService.removeItem(userId, restaurantId, foodId);
|
||||
}
|
||||
|
||||
@Post('apply-coupon')
|
||||
|
||||
Reference in New Issue
Block a user