All files / src/lib/api-docs/endpoints cart.ts

100% Statements 167/167
100% Branches 0/0
100% Functions 0/0
100% Lines 167/167

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 1681x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Cart Endpoints
 * Shopping cart management endpoints
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const cartEndpoints: ApiEndpoint[] = [
  {
    id: 'cart-get',
    method: 'GET',
    path: '/api/cart',
    summary: 'Get current cart',
    description: 'Returns the current user cart with all items',
    category: 'cart',
    requiresAuth: true,
    responses: [
      {
        status: 200,
        description: 'Cart contents',
        example: {
          success: true,
          data: {
            items: [
              { id: 1, productId: 101, quantity: 2, price: 29.99 },
            ],
            total: 59.98,
          },
        },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
  {
    id: 'cart-add',
    method: 'POST',
    path: '/api/cart',
    summary: 'Add item to cart',
    description: 'Adds a product to the shopping cart',
    category: 'cart',
    requiresAuth: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'productId', type: 'number', required: true, description: 'Product ID to add' },
        { name: 'quantity', type: 'number', required: true, description: 'Quantity to add' },
        { name: 'rentalStart', type: 'string', required: false, description: 'Rental start date (ISO)' },
        { name: 'rentalEnd', type: 'string', required: false, description: 'Rental end date (ISO)' },
      ],
      example: { productId: 1, quantity: 2 },
    },
    responses: [
      {
        status: 201,
        description: 'Item added to cart',
        example: { success: true, data: { id: 1, productId: 1, quantity: 2, price: 29.99 } },
      },
      {
        status: 400,
        description: 'Invalid product or quantity',
        example: { success: false, error: { code: 'VALIDATION_ERROR', message: 'Invalid product or quantity' } },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
  {
    id: 'cart-update-item',
    method: 'PATCH',
    path: '/api/cart/{id}',
    summary: 'Update cart item',
    description: 'Updates quantity or dates for a cart item',
    category: 'cart',
    requiresAuth: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Cart item ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'quantity', type: 'number', required: false, description: 'New quantity' },
      ],
      example: { quantity: 3 },
    },
    responses: [
      {
        status: 200,
        description: 'Cart item updated',
        example: { success: true, data: { id: 1, productId: 1, quantity: 3, price: 29.99 } },
      },
      {
        status: 404,
        description: 'Cart item not found',
        example: { success: false, error: { code: 'NOT_FOUND', message: 'Cart item not found' } },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
  {
    id: 'cart-remove-item',
    method: 'DELETE',
    path: '/api/cart/{id}',
    summary: 'Remove cart item',
    description: 'Removes an item from the cart',
    category: 'cart',
    requiresAuth: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Cart item ID' },
    ],
    responses: [
      {
        status: 200,
        description: 'Item removed',
        example: { success: true, data: { message: 'Item removed from cart' } },
      },
      {
        status: 404,
        description: 'Cart item not found',
        example: { success: false, error: { code: 'NOT_FOUND', message: 'Cart item not found' } },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
  {
    id: 'cart-merge',
    method: 'POST',
    path: '/api/cart/merge',
    summary: 'Merge guest cart',
    description: 'Merges guest cart with user cart after login',
    category: 'cart',
    requiresAuth: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'guestCartId', type: 'string', required: true, description: 'Guest cart session ID' },
      ],
      example: { guestCartId: 'guest-session-abc123' },
    },
    responses: [
      {
        status: 200,
        description: 'Carts merged successfully',
        example: { success: true, data: { message: 'Cart merged successfully', itemsMerged: 3 } },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
];