コード例 #1
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_sales():
    start, limit = clean_start_limit()
    sales = list()
    quantity = len( Sales.query.all() )
    for sale in Sale.query.all()[ start:start+limit ]:
        serializedSale = sale.serialize()
        serializedSale[ 'products' ] = [ {
            'id' : product.id,
            'name' : product.name,
            'description' : product.description,
            'price' : product.price
            } for product in sale.product_id ]
        sales.append( serializedSale )
    prev_link, next_link = create_next_prev_links( start, limit, quantity )
    response = {
        'quantity' : quantity,
        'paginate_link' : {
            'next' : '/products/sales' + next_link,
            'prev' : '/products/sales' + prev_link,
        },
        'sales' : sales
    }
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response )
コード例 #2
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_department( store_id, department_name ):
    start, limit = clean_start_limit()
    department = Department.query.filter( Department.store_id == store_id ).filter( Department.name == department_name ).first()
    if department is None:
        return jsonify( {
            'status_code' : 404,
            'message' : 'Department or Store does not exist'
        } )
    department_serialized = department.serialize()
    department_serialized[ 'employee' ] = [ employee.serialize( [ 'department_id' ] ) for employee in department.employee_id[ start:start+limit ] ]
    quantity = len( department.employee_id )
    prev_link, next_link = create_next_prev_links( start,limit, quantity )
    response = {
        'quantity' : quantity,
        'paginate_link' : {
            'next' : '/store/department/' + next_link,
            'prev' : '/store/department/' + prev_link
        },
        'department' : department_serialized,
        'store' : department.store.serialize( [ 'department' ] ),
    } 
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response )
コード例 #3
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_category_details( category_id ):
    start, limit = clean_start_limit()
    category = Category.query.get( category_id )
    if category is None:
        return jsonify( {
            'status_code' : 404,
            'message' : 'Category does not exist'
        } )
    categorySerialized = category.serialize()
    products = category.products[ start:start+limit ]
    quantity = len( category.products )
    categorySerialized[ 'products' ] = [ product.serialize( [ 'coupon' ] ) for product in products ]
    prev_link, next_link = create_next_prev_links( start, limit, quantity )
    response = {
        'product_quantity' : quantity,
        'paginate_link' : {
            'prev' : '/products/categories/' + str( category_id ) + prev_link,
            'next' : '/products/categories/' + str( category_id ) + next_link
        },
        'category' : categorySerialized
    }
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response )     
コード例 #4
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_clients():
    start, limit = clean_start_limit()
    clients = Client.query.all()[ start : start+limit ]
    clients = [ client.serialize() for client in clients ]
    quantity = len( Client.query.all() )
    prevLink, nextLink = create_next_prev_links( start, limit, quantity )
    response = {
        'quantity' : quantity,
        'paginate_link' : {
            'next' : '/client/' + nextLink,
            'prev' : '/client/' + prevLink
        },
        'client' : clients
    }
    return jsonify( response )
コード例 #5
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_store():
    start, limit = clean_start_limit()
    store = [ store.serialize() for store in Store.query.all()[ start:start+limit ] ]
    quantity = len(Store.query.all())
    prev_link, next_link = create_next_prev_links( start, limit, quantity )
    response = {
        'quantity' : quantity, 
        'paginate_link' : {
            'next' : '/store/' + next_link,
            'prev' : '/store/' + prev_link
        },
        'store' : store 
    }
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response ) 
コード例 #6
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_categories():
    start,limit = clean_start_limit()
    categories = [ category.serialize( [ 'products' ] ) for category in Category.query.all()[ start:start+limit ] ]
    quantity = len( Categories.query.all() ) 
    prev_link, next_link = create_next_prev_links( start, limit, quantity )
    response = {
        'quantity' : quantity,
        'paginate_link' : {
            'next' : '/products/categories/' + next_link,
            'prev' : '/products/categories/' + prev_link
        },
        'category' : categories
    }
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response )
コード例 #7
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_coupons():
    start, limit = clean_start_limit()
    quantity = len( Coupon.query.all() )
    coupons = [ coupon.serialize() for coupon in Coupon.query.all()[ start:start+limit ] ]
    prev_link, next_link = create_next_prev_links( start, limit, quantity)
    response = {
        'quantity' : len( coupons ),
        'paginate_link' : {
            'next' : '/products/coupons/' + next_link, 
            'prev' : '/products/coupons/' + prev_link
        },
        'coupons' : coupons  
    }
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response )
コード例 #8
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_employees():
    start, limit = clean_start_limit()
    employees = Employee.query.all()[ start : start+limit ]
    employeeSerialized = [ employee.serialize( [ 'department_id' ] ) for employee in employees ]
    quantity = len( Employee.query.all() )
    prev_link, next_link = create_next_prev_links( start, limit, quantity )
    response = {
        'quantity' : quantity,
        'paginate_link' : {
            'next' : '/employee/' + next_link,
            'prev' : '/employee/' + prev_link
        },
        'employee' : employeeSerialized
    }
    if prev_link == "":
        del response[ 'paginate_link' ][ 'prev' ]
    if next_link == "":
        del response[ 'paginate_link' ][ 'next' ]
    return jsonify( response )
コード例 #9
0
ファイル: controllers.py プロジェクト: thejerrybao/pronto-api
def get_products():
    start, limit = clean_start_limit()
    quantity = len(Products.query.all())
    products = [product.serialize() for product in Product.query.all()[start:start+limit]]
    prev_link, next_link = create_next_prev_links(start, limit, quantity)
    response = { 
        "quantity" : quantity,
        "paginate_link" : {
            "next" : "/products/" + next_link,
            "prev" : "/products/" + prev_link
        }
    }
    if prev_link == "":
        del response['paginate_link']['prev']
    if next_link == "":
        del response['paginate_link']['next']
    for product in products:
        del product["coupon_id"]
        product_fix(product, exclude_list = ["client", "sale"])
    response["products"] = products
    return jsonify(response)