Exemplo n.º 1
0
def update(event, context):
    id = event['pathParameters']['id']

    location = LocationModel.get(id)

    if location is None:
        raise Exception('Not found')
        return

    data = json.loads(event['body'])

    try:
        location.name = data.get('name', location.name)
        location.street_1 = data.get('street_1', location.street_1)
        location.street_2 = data.get('street_2', location.street_2)
        location.city = data.get('city', location.city)
        location.state = data.get('state', location.state)
        location.zip_code = data.get('zip_code', location.zip_code)
        location.type_id = data.get('type_id', location.type_id)

        location.save()

        response = {'statusCode': 200, 'body': json.dumps(dict(location))}
    except Exception as ex:
        response = {
            'statusCode': 500,
            'body': json.dumps({'errorMessage': 'There was a problem saving'})
        }

    return response
Exemplo n.º 2
0
def get(event, context):
    id = event['pathParameters']['id']

    try:
        location = LocationModel.get(id)

        response = {'statusCode': 200, 'body': json.dumps(dict(location))}
    except Exception as ex:
        response = {
            'statusCode': 500,
            'body':
            json.dumps({'errorMessage': 'There was a problem deleting'})
        }

    return response