Exemple #1
0
def delete_wishlist(wishlist_id):
    """
    Delete a Wishlist

    This endpoint will delete a Wishlist based on the id specified in
    the path
    
    ---
    tags:
      - Wishlist

    parameters:
      - name: wishlist_id
        in: path
        description: the id of the wishlist
        type: integer
        required: true

    responses:
        204:
            description: returns no content

    """
    wishlist = Wishlist.get(wishlist_id)
    if wishlist:
        items = Item.find_by_wishlist_id(wishlist_id)
        for item in items:
            item.delete()
        wishlist.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Exemple #2
0
def get_wishlist(wishlist_id):

    """
    Retrieve a single Wishlist 

    This endpoint will return a Wishlist based on it's ID

    ---
    tags:
      - Wishlist
    produces:
        - application/json
    parameters:
      - name: wishlist_id
        in: path
        type: integer
        required: true

    definitions:
        Wishlist:
            type: object
            properties:
                id:
                    type: integer
                customer_id:
                    type: integer
                wishlist_name:
                    type: string

    definitions:
        Item:
            type: object
            properties:
                id:
                    type: integer
                wishlist_id:
                    type: integer
                product_id:
                    type: integer
                name:
                    type: string
                description:
                    type: string

    responses:
        200:
            description: List of items in the wishlist
            schema:
                $ref: '#/definitions/Wishlist'
        404:
                description: Wishlist with id wishlist_id not found

    """

    wishlist = Wishlist.get(wishlist_id)
    if not wishlist:
        raise NotFound("Wishlist with id '{}' was not found.".format(wishlist_id))
    return make_response(jsonify(wishlist.serialize()), status.HTTP_200_OK)
Exemple #3
0
def add_item_to_wishlist(wishlist_id):
    """
    Add an Item to an existing wishlist
    This endpoint will add a wishlist item based on the data in the body that is posted

    ---
    tags:
        - Wishlist

    consumes:
        application/json

    parameters:
        - name: wishlist_id
          in: path
          type: integer
          description: the id of the Wishlist to add an item
          required: true
        - name: body
          in: body
          required: true
          schema:
            $ref: '#/definitions/Item'

    responses:
      201:
        description: Successfully added Item to wishlist
      404:
        description: Wishlist with id not found

    """
    check_content_type('application/json')
    wishlist = Wishlist.get(wishlist_id)
    if not wishlist:
        raise NotFound("Wishlist with id '{}' was not found.".format(wishlist_id))
    
    item = Item()
    json_post = request.get_json()
    item.deserialize(json_post,wishlist_id)
    item.save()
    message = item.serialize()
    """
    check if the item.wishlist_id equals to the wishlist.id
    """
    check_wishlist_id = item.wishlist_id

    location_url = url_for('get_wishlist', wishlist_id=wishlist.id, _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {
                            'Location': location_url
                         })
Exemple #4
0
def update_wishlists(wishlist_id):
    """
    Update a Wishlist

    This endpoint will update a Wishlist based the body that is posted
    """
    check_content_type('application/json')
    wishlist = Wishlist.get(wishlist_id)
    if not wishlist:
        raise NotFound("Wishlist with id '{}' was not found.".format(wishlist_id))
    wishlist.deserialize(request.get_json())
    wishlist.id = wishlist_id
    wishlist.save()
    return make_response(jsonify(wishlist.serialize()), status.HTTP_200_OK)
Exemple #5
0
def update_wishlists(wishlist_id):
    """
    Update a Wishlist

    This endpoint will update a Wishlist based the body that is posted

    ---
    tags:
        - Wishlist

    parameters:
        - name: wishlist_id
          in: path
          type: integer
          required: true
        - name: body
          in: body
          schema:
            id: wishlist_entries
            required: true
                - customer_id
                - wishlist_name
            properties:
                customer_id:
                    type: integer
                    description: customer_id
                    default: "345"
                wishlist_name:
                    type: string
                    description: name of the wishlist 
                    default: "new name of the wishlist"

    responses:
      200:
        description: Update was successful
      404:
        description: Did not find item with the given id in the wishlist
    """

    check_content_type('application/json')
    wishlist = Wishlist.get(wishlist_id)
    if not wishlist:
        raise NotFound("Wishlist with id '{}' was not found.".format(wishlist_id))
    wishlist.deserialize(request.get_json())
    wishlist.id = wishlist_id
    wishlist.save()
    return make_response(jsonify(wishlist.serialize()), status.HTTP_200_OK)