day-cohort-70 / bangazon-api-i-like-planes-api

bangazon-api-i-like-planes-api created by GitHub Classroom
0 stars 0 forks source link

Changed add item to cart logic to profile/cart path #54

Closed Justin-Acosta closed 3 days ago

Justin-Acosta commented 3 days ago

Changes

product.py view: @action add_to_order removed

profile.py view: added logic to check if product.quantity is > 0 if > 0: product is added to order, and the added product is sent back in the response body with 201 code if <= 0 : "message": 'This item is out of stock' is sent back in the response body with 400 code

Requests / Responses

Request

POST /profile/cart adds product to cart

{
    "product_id": 20
}

Response

HTTP/1.1 201 OK

{
    "id": 23,
    "product": {
        "id": 20,
        "name": "Golf",
        "price": 653.59,
        "number_sold": 0,
        "description": "1994 Volkswagen",
        "quantity": 3,
        "created_date": "2019-07-10",
        "location": "Paris",
        "image_path": "http://localhost:8000/media/products/vehicle.png",
        "average_rating": 0,
        "store_id": 1
    }
}

Related Issues