Exemplo n.º 1
0
def post_people():
    ppl = get_people()
    person = request.get_json()
    person_id = len(ppl['people'])
    ppl['people'].append({"id": person_id, **person})
    to_json(ppl)
    return jsonify({"id": person_id})
Exemplo n.º 2
0
def update_person(id):
    ppl = get_people()
    try:
        ppl['people'][int(id)].update(request.get_json())
        to_json(ppl)
        return Response(status=204)
    except IndexError:
        return Response("Not Found", status=404)
Exemplo n.º 3
0
def delete_person(id):
    ppl = get_people()
    try:
        ppl['people'][int(id)] = None
        to_json(ppl)
        return Response(status=204)
    except IndexError:
        return Response('Not Found', status=404)
Exemplo n.º 4
0
def get_people_():
    ppl = get_people()
    country = request.args.get('country')
    if country is not None:
        return jsonify([p for p in ppl['people'] if p['country'] == country])
    return jsonify(ppl['people'])
Exemplo n.º 5
0
def get_person(id):
    ppl = get_people()
    try:
        return ppl['people'][int(id)]
    except IndexError:
        return Response('Not found', status=404)