Exemple #1
0
def show(city_id):
    schema = CitySchema()
    city = City.get(id=city_id)

    if not city:
        abort(404)

    return schema.dumps(city)
Exemple #2
0
def delete(city_id):
    city = City.get(id=city_id)

    if not city:
        abort(404)

    city.delete()
    db.commit()

    return '', 204
Exemple #3
0
def update(city_id):
    schema = CitySchema()
    city = City.get(id=city_id)

    if not city:
        abort(404)

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

    return schema.dumps(city)