Esempio n. 1
0
def query_wishlist(cust_id):
    # """ List the wishlist with the provided name"""
    """
    Retrieve a list of Wishlists
    This endpoint will return all Wishlists based on the customer ID specified in the path and the optional wishlist name
    ---
    tags:
      - Wishlists
    description: The Wishlists endpoint allows you to query Wishlists
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to view a list of his/her Wishlists
        required: true
        type: integer
      - name: name
        in: query
        description: Name of the wishlist the customer wants to view
        required: false
        type: string
    responses:
      200:
        description: A list of Wishlists retrieved
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: array
              items:
                type: object
                properties:
                  wishlist name:
                    type: string
                    description: the Wishlists's name
                  Product list:
                    type: array
                    items:
                      type: string
                    description: the list of products in a Wishlist
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    if Customer.check_custid(cust_id):
        query_name = request.args.get('name')
        if query_name:
            message = Customer.find_by_name(cust_id,query_name)
            if message:
                return make_response(jsonify(message),status.HTTP_200_OK)
            else:
                message = {'Error' : 'Wishlist with the given name not found'}
                return make_response(jsonify(message),status.HTTP_404_NOT_FOUND)
        else:
            message = Customer.find_by_custid(cust_id)
            return make_response(jsonify(message),status.HTTP_200_OK)
    else:
        message = {'Invalid' : 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
Esempio n. 2
0
def delete_product(cust_id,wishlist_id,pid):
    # """ delete product ID to a wishlist """
    """
    Delete a product from a Wishlist
    This endpoint will delete a product from a wishlist based on the customer ID, Wishlist ID, an product ID specified in the path
    ---
    tags:
      - Wishlists
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to delete a product from his/her wishlist
        required: true
        type: integer
      - name: wishlist_id
        in: path
        description: ID of wishlist to be updated
        required: true
        type: integer
      - name: pid
        in: path
        description: ID of product to be deleted
        required: true
        type: integer
    responses:
      200:
        description: Product deleted from a wishlist
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: object
              properties:
                wishlist name:
                  type: string
                  description: the Wishlists's name
                Product list:
                  type: array
                  items:
                    type: string
                  description: the list of products in a Wishlist
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    # TODO add products changes as well, for now just asses the wishlists
    if Customer.check_custid(cust_id):
        message = Customer.find_by_id(cust_id,wishlist_id)
        if message:
            result = Customer.deleteProduct(cust_id,wishlist_id,pid)
            res = Customer.find_by_id(cust_id,wishlist_id)
            return make_response(jsonify(res), status.HTTP_200_OK)
        else:
            message = {'Error': 'Wishlist with given ID not found'}
            return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
    else:
        message = {'Invalid' : 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
Esempio n. 3
0
def clear_wishlist(cust_id,wishlist_id):
    # """ Clear the contents of the wishlist with the given id"""
    """
    Clear all products of a Wishlist
    This endpoint will clear all products of a Wishlist based on the customer id and Wishlist id specified in the path
    ---
    tags:
      - Wishlists
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to view his/her wishlist
        required: true
        type: integer
      - name: wishlist_id
        in: path
        description: ID of wishlist to be retrieved
        required: true
        type: integer
    responses:
      200:
        description: Wishlist cleared
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: object
              properties:
                wishlist name:
                  type: string
                  description: the Wishlists's name
                Product list:
                  type: array
                  items:
                    type: string
                  description: the list of products in a Wishlist
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    if Customer.check_custid(cust_id):
        message = Customer.find_by_id(cust_id,wishlist_id)
        if message:
            res = Customer.clear_list(cust_id,wishlist_id)
            return make_response(jsonify(message),status.HTTP_200_OK)
        else:
            message = {'Error' : 'Wishlist with the given ID not found'}
            return make_response(jsonify(message),status.HTTP_404_NOT_FOUND)
    else:
        message = {'Invalid' : 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
Esempio n. 4
0
def delete_wishlist(cust_id, wishlist_id):
    # """ Delete the wishlist with the provided id"""
    """
    Delete a Wishlist
    This endpoint will delete a Wishlist based on the customer id and Wishlist id specified in the path
    ---
    tags:
      - Wishlists
    description: Deletes a wishlist from the database
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to delete his/her wishlist
        required: true
        type: integer
      - name: wishlist_id
        in: path
        description: ID of wishlist to be deleted
        required: true
        type: integer
    responses:
      204:
        description: Wishlist deleted
    """
    success = Customer.delete_by_id(cust_id, wishlist_id)
    return make_response('', status.HTTP_204_NO_CONTENT)
Esempio n. 5
0
def display_all_wishlists():
    # """ Display wishlists of all customers if created"""
    """
    Retrieve a list of Wishlists of all customers
    This endpoint will return all Wishlists of all customers
    ---
    tags:
      - Wishlists
    description: The Wishlists endpoint allows you to query all Wishlists of all customers
    responses:
      200:
        description: All Wishlists retrieved
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: array
              items:
                type: object
                properties:
                  wishlist name:
                    type: string
                    description: the Wishlists's name
                  Product list:
                    type: array
                    items:
                      type: string
                    description: the list of products in a Wishlist
      404:
        description: Not Found (No wishlist created for any customer)
    """
    if Customer.display_all():
        message = [Customer.find_by_custid(k) for k in Customer.redis.keys()]
        return make_response(jsonify(message),status.HTTP_200_OK)
    else:
        message = {'Error' : 'No wishlist created for any customer'}
        return make_response(jsonify(message),status.HTTP_404_NOT_FOUND)
Esempio n. 6
0
 def on_post(self, req, res):
     session = req.context['session']
     rawData = req.context['data']
     format_str = '%d/%m/%Y'  # The format
     if rawData['email'] and rawData['name']:
         isExistedEmailCus = session.query(Customer).filter(
             Customer.email == rawData['email']).first()
         LOG.debug(isExistedEmailCus)
         if isExistedEmailCus:
             raise InvalidParameterError('Email is used in system!')
         else:
             cus = Customer()
             cus.email = rawData['email']
             cus.name = rawData['name']
             cus.dob = datetime.datetime.strptime(
                 rawData['dob'], format_str)  #dob format dd/mm/yyyy
             session.add(cus)
             newCus = session.query(Customer).filter(
                 Customer.email == cus.email).one()
             self.on_success(res, newCus.to_dict())
     else:
         raise InvalidParameterError('email and name are required!')
Esempio n. 7
0
async def create_customer(customer: Customer):
    query = customers_table.insert().values(name=customer.name,
                                            age=customer.age)
    last_record_id = await database.execute(query)
    return {**customer.dict(), "id": last_record_id}
Esempio n. 8
0
def create_wishlist(cust_id):
    # """ create the wishlist with the provided id"""
    """
    Create a Wishlist
    This endpoint will create a Wishlist based on the customer id specified in the path
    ---
    tags:
      - Wishlists
    consumes:
      - application/json
    produces:
      - application/json
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to create his/her wishlist
        required: true
        type: integer
      - in: body
        name: body
        required: true
        schema:
          type: object
          required:
            - name
            - Product List
          properties:
            name:
              type: string
              description: name for the Wishlist
            Product List:
              type: array
              items:
                type: string
              description: the list of products in a Wishlist
    responses:
      201:
        description: Wishlist created
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: object
              properties:
                wishlist name:
                  type: string
                  description: the Wishlists's name
                Product list:
                  type: array
                  items:
                    type: string
                  description: the list of products in a Wishlist
      400:
        description: Bad Request (the posted data was not valid)
    """
    wishlist = Customer(cust_id,"",[])
    wishlist.deserialize(request.get_json())
    message = wishlist.save()

    location_url = url_for('create_wishlist', cust_id=wishlist.cust_id)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {
                             'Location': location_url
                         })
Esempio n. 9
0
def data_reset():
    Customer.remove_all()
Esempio n. 10
0
def init_db(redis=None):
    """ Initlialize the model """
    Customer.init_db(redis)
Esempio n. 11
0
def update_wishlist(cust_id,wishlist_id):
    # """ Update the wishlist name if it exists, otherwise returns not found """
    """
    Update a Wishlist
    This endpoint will update a Wishlist based on the customer id and Wishlist id specified in the path
    ---
    tags:
      - Wishlists
    consumes:
      - application/json
    produces:
      - application/json
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to update his/her wishlist
        required: true
        type: integer
      - name: wishlist_id
        in: path
        description: ID of wishlist to be updated
        required: true
        type: integer
      - in: body
        name: body
        required: true
        schema:
          type: object
          required:
            - name
          properties:
            name:
              type: string
              description: name for the Wishlist
    responses:
      200:
        description: Wishlist updated
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: object
              properties:
                wishlist name:
                  type: string
                  description: the Wishlists's name
                Product list:
                  type: array
                  items:
                    type: string
                  description: the list of products in a Wishlist
      400:
        description: Bad Request (the put data was not valid)
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    # TODO add products changes as well, for now just asses the wishlists
    if Customer.check_custid(cust_id):
        message = Customer.find_by_id(cust_id,wishlist_id)
        if message:
            result = Customer.update(cust_id,wishlist_id,request.get_json())
            res = Customer.find_by_id(cust_id,wishlist_id)
            return make_response(jsonify(res), status.HTTP_200_OK)
        else:
            message = {'Error': 'Wishlist with given ID not found'}
            return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
    else:
        message = {'Invalid' : 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)