Example #1
0
def get_an_appointment(appointment_id):
    """
    Get An Appointments
    """
    appointment = Appointment.get_one_appointment(appointment_id)
    if not appointment:
        return custom_response({'Error': 'Appointment not found'}, 404)
    data = appointments_schema.dump(appointment).data
    return custom_response(data, 200)
Example #2
0
def delete(appointment_id):
    """
    Delete An Appointment
    """
    appointment = Appointment.get_one_appointment(appointment_id)
    if not appointment:
        return custom_response({'Error': 'Appointment not found'}, 404)

    appointment.delete()
    return custom_response({'Message': 'Appointment deleted'}, 204)
Example #3
0
def update(appointment_id):
    """
    Update An Appointment
    """
    req_data = request.get_json()
    appointment = Appointment.get_one_appointment(appointment_id)
    if not appointment:
        return custom_response({'Error': 'Appointment not found'}, 404)

    data, error = appointments_schema.load(req_data, partial=True)
    if error:
        return custom_response(error, 400)
    appointment.update(data)

    data = appointments_schema.dump(appointment).data
    return custom_response(data, 200)
Example #4
0
def get_all():
    """
    Get All Appointments
    """
    appointments = Appointment.get_all_appointments()
    data = appointments_schema.dump(appointments, many=True).data
    return custom_response(data, 200)
Example #5
0
def create():
    """
    Create an appointment
    """
    req_data = request.get_json()
    data, error = appointments_schema.load(req_data)
    if error:
        return jsonify(error), 400
    appointment = Appointment(data)
    appointment.save()
    data = appointments_schema.dump(appointment).data
    return custom_response(data, 201)