예제 #1
0
def get_shipment(shipment_id):
    """
    Retrieve a single shipment object.

    :param shipment_id:   The shipment's id

    :return: {
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "123",
        "toId:": "123",
        "items": [{LineItem}]
    }

    """
    include_items = request.args.get('include_items')
    check_null_input((shipment_id, 'shipment to retrieve'))

    shipment = shipment_service.get_shipment(token=g.auth['loopback_token'],
                                             shipment_id=shipment_id,
                                             include_items=include_items)

    return Response(shipment, status=200, mimetype='application/json')
예제 #2
0
def create_demo():
    """
    Create a new demo resource.

    :param {
        "name": "Example Demo Name",
        "email": "*****@*****.**"
    }

    :return: {
        "id": "123",
        "name": "Example Demo Name",
        "guid": "JDJhJDEdTRUR...VBrbW9vcj3k4L2sy",
        "createdAt": "2015-11-05T22:00:51.692765",
        "users": [{User}...{User}]
    }

    """

    # Get inputs and make sure required params are not null
    data = web_utils.get_json_data(request)
    demo_name = data.get('name')
    user_email = data.get('email')
    web_utils.check_null_input(
        (demo_name, 'demo name for the new demo session'))

    demo = demo_service.create_demo(demo_name, user_email)
    return Response(demo, status=201, mimetype='application/json')
예제 #3
0
def demo_login(guid):
    """
    Login to a demo as a specific user

    :param {
        "userId": "123"
    }

    :return: {
        "token": "eyJhbGciOi...WT2aGgjY5JHvCsbA"
    }
    """
    data = request.get_json()
    user_id = data.get('userId')
    web_utils.check_null_input((user_id, 'username when logging in'),
                               (guid, 'demo guid when logging in'))

    # Login through the ERP system and create a JWT valid for 2 weeks
    auth_data = user_service.login(guid, user_id)
    auth_data['exp'] = datetime.utcnow() + timedelta(days=14)
    token = web_utils.tokenize(auth_data)
    resp = Response(json.dumps({'token': token}),
                    status=200,
                    mimetype='application/json')

    resp.set_cookie('auth_token', token, httponly=True)
    return resp
예제 #4
0
def create_demo():
    """
    Create a new demo resource.

    :param {
        "name": "Example Demo Name",
        "email": "*****@*****.**"
    }

    :return: {
        "id": "123",
        "name": "Example Demo Name",
        "guid": "JDJhJDEdTRUR...VBrbW9vcj3k4L2sy",
        "createdAt": "2015-11-05T22:00:51.692765",
        "users": [{User}...{User}]
    }

    """

    # Get inputs and make sure required params are not null
    data = web_utils.get_json_data(request)
    demo_name = data.get('name')
    user_email = data.get('email')
    web_utils.check_null_input((demo_name, 'demo name for the new demo session'))

    demo = demo_service.create_demo(demo_name, user_email)
    return Response(demo,
                    status=201,
                    mimetype='application/json')
예제 #5
0
def create_demo_user(guid):
    """
    Create a new user for a single demo

    :param guid:   The demo's guid
    :param {
        "retailerId": "123"
    }

    :return: {
        "id": "123",
        "demoId": "123",
        "username": "******",
        "email": "*****@*****.**"
    }
    """

    # Get inputs and make sure required params are not null
    data = web_utils.get_json_data(request)
    retailer_id = data.get('retailerId')
    web_utils.check_null_input(
        (guid, 'demo for which to create a user'),
        (retailer_id, 'retailer to make a user for the demo'))

    user = user_service.create_user(guid, retailer_id)
    return Response(user, status=201, mimetype='application/json')
예제 #6
0
def create_demo_user(guid):
    """
    Create a new user for a single demo

    :param guid:   The demo's guid
    :param {
        "retailerId": "123"
    }

    :return: {
        "id": "123",
        "demoId": "123",
        "username": "******",
        "email": "*****@*****.**"
    }
    """

    # Get inputs and make sure required params are not null
    data = web_utils.get_json_data(request)
    retailer_id = data.get('retailerId')
    web_utils.check_null_input((guid, 'demo for which to create a user'),
                               (retailer_id, 'retailer to make a user for the demo'))

    user = user_service.create_user(guid, retailer_id)
    return Response(user,
                    status=201,
                    mimetype='application/json')
예제 #7
0
def demo_login(guid):
    """
    Login to a demo as a specific user

    :param {
        "userId": "123"
    }

    :return: {
        "token": "eyJhbGciOi...WT2aGgjY5JHvCsbA"
    }
    """
    data = request.get_json()
    user_id = data.get('userId')
    web_utils.check_null_input((user_id, 'username when logging in'),
                               (guid, 'demo guid when logging in'))

    # Login through the ERP system and create a JWT valid for 2 weeks
    auth_data = user_service.login(guid, user_id)
    auth_data['exp'] = datetime.utcnow() + timedelta(days=14)
    token = web_utils.tokenize(auth_data)
    resp = Response(json.dumps({'token': token}),
                    status=200,
                    mimetype='application/json')

    resp.set_cookie('auth_token', token, httponly=True)
    return resp
def get_distribution_centers_shipments(dc_id):
    """
    Retrieve all shipments originating from the specified distribution center.

    :param dc_id:   The distribution center's id

    :return: [{
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "123",
        "toId:": "123"
    }, {...}]

    """
    check_null_input((dc_id, 'distribution center whose shipments you want to retrieve'))
    status = request.args.get('status')

    shipments = shipment_service.get_shipments(token=g.auth['loopback_token'],
                                               dc_id=dc_id,
                                               status=status)
    return Response(shipments,
                    status=200,
                    mimetype='application/json')
예제 #9
0
def get_shipment(shipment_id):
    """
    Retrieve a single shipment object.

    :param shipment_id:   The shipment's id

    :return: {
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "123",
        "toId:": "123",
        "items": [{LineItem}]
    }

    """
    include_items = request.args.get('include_items')
    check_null_input((shipment_id, 'shipment to retrieve'))

    shipment = shipment_service.get_shipment(token=g.auth['loopback_token'],
                                             shipment_id=shipment_id,
                                             include_items=include_items)

    return Response(shipment,
                    status=200,
                    mimetype='application/json')
예제 #10
0
def delete_demo(guid):
    """
    Delete a demo object and all its children.

    :param guid:   The demo's guid
    :return:
    """
    web_utils.check_null_input((guid, 'demo to delete'))

    demo_service.delete_demo_by_guid(guid)
    return '', 204
예제 #11
0
def delete_demo(guid):
    """
    Delete a demo object and all its children.

    :param guid:   The demo's guid
    :return:
    """
    web_utils.check_null_input((guid, 'demo to delete'))

    demo_service.delete_demo_by_guid(guid)
    return '', 204
예제 #12
0
def delete_shipment(shipment_id):
    """
    Retrieve a single shipment object.

    :param shipment_id:   The shipment's id
    :return:

    """
    check_null_input((shipment_id, 'shipment to delete'))

    shipment_service.delete_shipment(token=g.auth['loopback_token'], shipment_id=shipment_id)
    return '', 204
예제 #13
0
def delete_shipment(shipment_id):
    """
    Retrieve a single shipment object.

    :param shipment_id:   The shipment's id
    :return:

    """
    check_null_input((shipment_id, 'shipment to delete'))

    shipment_service.delete_shipment(token=g.auth['loopback_token'],
                                     shipment_id=shipment_id)
    return '', 204
예제 #14
0
def get_retailer(retailer_id):
    """
    Retrieve a single retailer object.

    :param retailer_id:   The retailer's id

    :return: {
        "id": "123",
        "address": {Address}
    }

    """
    check_null_input((retailer_id, 'retailer to retrieve'))

    retailer = retailer_service.get_retailer(token=g.auth['loopback_token'],
                                             retailer_id=retailer_id)
    return Response(retailer, status=200, mimetype='application/json')
예제 #15
0
def get_demo(guid):
    """
    Retrieve a single demo object.

    :param guid:   The demo's guid

    :return: {
        "id": "123",
        "name": "Example Demo Name",
        "guid": "JDJhJDEdTRUR...VBrbW9vcj3k4L2sy",
        "createdAt": "2015-11-05T22:00:51.692765",
        "users": [{User}...{User}]
    }
    """
    web_utils.check_null_input((guid, 'demo to retrieve'))

    demo = demo_service.get_demo_by_guid(guid)
    return Response(demo, status=200, mimetype='application/json')
def get_distribution_center(dc_id):
    """
    Retrieve a single distribution center object.

    :param dc_id:   The distribution center's id

    :return: {
        "id": "D2",
        "address": {Address},
        "contact": {Contact}
    }

    """
    check_null_input((dc_id, 'distribution center to retrieve'))

    distribution_center = distribution_center_service.get_distribution_center(token=g.auth['loopback_token'],
                                                                              dc_id=dc_id)
    return Response(distribution_center,
                    status=200,
                    mimetype='application/json')
예제 #17
0
def get_demo(guid):
    """
    Retrieve a single demo object.

    :param guid:   The demo's guid

    :return: {
        "id": "123",
        "name": "Example Demo Name",
        "guid": "JDJhJDEdTRUR...VBrbW9vcj3k4L2sy",
        "createdAt": "2015-11-05T22:00:51.692765",
        "users": [{User}...{User}]
    }
    """
    web_utils.check_null_input((guid, 'demo to retrieve'))

    demo = demo_service.get_demo_by_guid(guid)
    return Response(demo,
                    status=200,
                    mimetype='application/json')
예제 #18
0
def get_retailer_inventory(retailer_id):
    """
    Retrieve all inventory at the specified retailer.

    :param retailer_id:   The retailer's id

    :return: [{
        "id": "123",
        "quantity": 10,
        "productId": "123",
        "locationId": "123",
        "locationType": "Retailer"
    }, {...}]
    """
    check_null_input(
        (retailer_id, 'retailer whose inventory you want to retrieve'))

    inventory = retailer_service.get_retailer_inventory(
        token=g.auth['loopback_token'], retailer_id=retailer_id)
    return Response(inventory, status=200, mimetype='application/json')
def get_distribution_center_inventory(dc_id):
    """
    Retrieve all inventory at the specified distribution center.

    :param dc_id:   The distribution center's id

    :return: [{
        "id": "123",
        "quantity": 10,
        "productId": "123",
        "locationId": "123",
        "locationType": "DistributionCenter"
    }, {...}]
    """
    check_null_input((dc_id, 'distribution center whose inventory you want to retrieve'))

    inventory = distribution_center_service.get_distribution_center_inventory(token=g.auth['loopback_token'],
                                                                              dc_id=dc_id)
    return Response(inventory,
                    status=200,
                    mimetype='application/json')
예제 #20
0
def get_demo_retailers(guid):
    """
    Retrieve a single demo's list of retailers.

    :param guid:   The demo's guid

    :return: [{
        "id": "123",
        "address": {
          "city": "Raleigh",
          "state": "North Carolina",
          "country": "US",
          "latitude": 35.71,
          "longitude": -78.63
        },
        "managerId": "123"
    }, {...}]
    """
    web_utils.check_null_input((guid, 'demo for which to retrieve retailers'))

    retailers = demo_service.get_demo_retailers(guid)
    return Response(retailers, status=200, mimetype='application/json')
예제 #21
0
def update_shipment(shipment_id):
    """
    Update a single shipment object.

    :param shipment_id:   The shipment's id
    :param  {
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "D2",
        "toId:": "123"
    }

    :return: {
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "D2",
        "toId:": "123"
    }

    """
    check_null_input((shipment_id, 'shipment to update'))

    updated_shipment = get_json_data(request)
    shipment = shipment_service.update_shipment(token=g.auth['loopback_token'],
                                                shipment_id=shipment_id, shipment=updated_shipment)
    return Response(shipment,
                    status=200,
                    mimetype='application/json')
예제 #22
0
def update_shipment(shipment_id):
    """
    Update a single shipment object.

    :param shipment_id:   The shipment's id
    :param  {
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "D2",
        "toId:": "123"
    }

    :return: {
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "D2",
        "toId:": "123"
    }

    """
    check_null_input((shipment_id, 'shipment to update'))

    updated_shipment = get_json_data(request)
    shipment = shipment_service.update_shipment(token=g.auth['loopback_token'],
                                                shipment_id=shipment_id,
                                                shipment=updated_shipment)
    return Response(shipment, status=200, mimetype='application/json')
예제 #23
0
def get_demo_retailers(guid):
    """
    Retrieve a single demo's list of retailers.

    :param guid:   The demo's guid

    :return: [{
        "id": "123",
        "address": {
          "city": "Raleigh",
          "state": "North Carolina",
          "country": "US",
          "latitude": 35.71,
          "longitude": -78.63
        },
        "managerId": "123"
    }, {...}]
    """
    web_utils.check_null_input((guid, 'demo for which to retrieve retailers'))

    retailers = demo_service.get_demo_retailers(guid)
    return Response(retailers,
                    status=200,
                    mimetype='application/json')