Exemplo n.º 1
0
def get_customer(id: int):
    customer = CustomerModel.get_by_id(id)

    if customer:
        return customer.json()

    return jsonify({'message': 'Customer not found'})
Exemplo n.º 2
0
def delete_customer(id: int):

    customer = CustomerModel.get_by_id(id)

    try:
        customer.delete()
    except Exception:
        return {"message", "Error updating the customer"}, 500

    return jsonify({'message': 'Customer deleted succesfully'})
Exemplo n.º 3
0
def update_customer(id: int):

    request_data = request.get_json()
    name = request_data['name']
    description = request_data['description']

    if CustomerModel.get_by_name(name):
        return {'message': f"customer with name '{name}' already exists"}, 400

    customer = CustomerModel.get_by_id(id)
    customer.name = name
    customer.description = description

    try:
        customer.save()
    except Exception:
        return {"message", "Error updating the customer"}, 500

    return customer.json()