Ejemplo n.º 1
0
def show(building_id):
    schema = BuildingSchema()
    building = Building.get(id=building_id)

    if not building:
        abort(404)

    return schema.dumps(building)
Ejemplo n.º 2
0
def delete(building_id):
    building = Building.get(id=building_id)

    if not building:
        abort(404)

    building.delete()
    db.commit()

    return '', 204
Ejemplo n.º 3
0
def update(building_id):
    schema = BuildingSchema()
    building = Building.get(id=building_id)

    if not building:
        abort(404)

    try:
        data = schema.load(request.get_json())
        building.set(**data)
        db.commit()
    except ValidationError as err:
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    return schema.dumps(building)