Esempio n. 1
0
def api_delete_contact(contact_id) -> Response:
    '''
    Delete a single contact.
    '''

    contact = Contact.query.get_or_404(contact_id)
    delete_contact(contact)

    return jsonify(deleted=True)
Esempio n. 2
0
def api_put_contact(contact_id):
    '''
    Update a single contact.
    '''

    request_data = request.get_json()

    contact = Contact.query.get_or_404(contact_id)
    contact.name = get_or_400(request_data, 'name')
    contact.email = get_or_400(request_data, 'email')

    try:
        save_contact(contact)
    # If a duplicate of the updated contact exists, just remove this one
    except IntegrityError:
        db.session.rollback()
        delete_contact(contact)

    return jsonify(updated=True)