def delete(docid): if not request.method == 'DELETE': raise ApiError('Invalid request', status_code=400) try: service_container.doctor_data_service().delete( docid=int(docid.strip())) return jsonify({}), 204 except (TypeError, RuntimeError) as e: raise ApiError(e.message, status_code=400)
def create(): if not request.method == 'POST': raise ApiError('Invalid request', status_code=400) try: response = service_container.doctor_data_service().create( first_name=request.json.get('first_name'), last_name=request.json.get('last_name')) except (TypeError, RuntimeError) as e: raise ApiError(e.message, status_code=400) return jsonify({'response': response}), 201
def update(docid): if not request.method == 'PUT': raise ApiError('Invalid request', status_code=400) try: doctor = service_container.doctor_data_service().update( docid=int(docid.strip()), first_name=request.json.get('first_name'), last_name=request.json.get('last_name')) except (TypeError, RuntimeError) as e: raise ApiError(e.message, status_code=400) return jsonify({'response': doctor.to_dict()}), 200
def read(docid): if not request.method == 'GET': raise ApiError('Invalid request', status_code=400) try: doctor = service_container.doctor_data_service().read( docid=int(docid.strip())) except (TypeError, RuntimeError) as e: raise ApiError(e.message, status_code=400) if doctor is None: raise ApiError('Doctor not found', status_code=404) return jsonify({'response': doctor.to_dict()}), 200
def cancel(docid): if not request.method == 'DELETE': raise ApiError('Invalid request', status_code=400) try: appointments_service.delete( docid=int(docid.strip()), locid=request.json.get('locid'), app_datetime=request.json.get('app_datetime') ) except (TypeError, RuntimeError) as e: raise ApiError(e. message, status_code=400) return jsonify({}), 204
def create(docid): if not request.method == 'POST': raise ApiError('Invalid request', status_code=400) try: appointment = appointments_service.create( docid=int(docid.strip()), locid=request.json.get('locid'), app_datetime=request.json.get('app_datetime') ) except (TypeError, RuntimeError) as e: raise ApiError(e. message, status_code=400) return jsonify({'response': appointment.to_dict()}), 201
def index(docid): if not request.method == 'GET': raise ApiError('Invalid request', status_code=400) response = [] try: result = appointments_service.index(int(docid.strip())) except TypeError as e: raise ApiError(e.message, status_code=400) for apt in result: response.append(apt.to_dict()) return jsonify({'response': response}), 200
def index(): if not request.method == 'GET': raise ApiError('Invalid request', status_code=400) response = [] result = service_container.doctor_data_service().index() for doc in result: response.append(doc.to_dict()) return jsonify({'response': response}), 200