Updates api to match the net internal data structures

This commit is contained in:
Sergi Delgado Segura
2019-08-26 16:26:53 +02:00
parent ae2cf26195
commit ebac9b003e

View File

@@ -65,22 +65,21 @@ def get_appointment():
# ToDo: #15-add-system-monitor # ToDo: #15-add-system-monitor
appointment_in_watcher = watcher.appointments.get(locator) appointment_in_watcher = watcher.locator_uuid_map.get(locator)
if appointment_in_watcher: if appointment_in_watcher:
for appointment in appointment_in_watcher: for uuid in appointment_in_watcher:
appointment_data = appointment.to_json() appointment_data = watcher.appointments[uuid].to_json()
appointment_data['status'] = "being_watched" appointment_data['status'] = "being_watched"
response.append(appointment_data) response.append(appointment_data)
if watcher.responder: if watcher.responder:
responder_jobs = watcher.responder.jobs responder_jobs = watcher.responder.jobs
for job_id, job in responder_jobs.items(): for job in responder_jobs.values():
if job.locator == locator: if job.locator == locator:
job_data = job.to_json() job_data = job.to_json()
job_data['status'] = "dispute_responded" job_data['status'] = "dispute_responded"
job_data['confirmations'] = watcher.responder.confirmation_counter.get(job_id)
response.append(job_data) response.append(job_data)
if not response: if not response:
@@ -93,22 +92,18 @@ def get_appointment():
@app.route('/get_all_appointments', methods=['GET']) @app.route('/get_all_appointments', methods=['GET'])
def get_all_appointments(): def get_all_appointments():
watcher_appointments = [] watcher_appointments = {}
responder_jobs = [] responder_jobs = {}
# ToDo: #15-add-system-monitor # ToDo: #15-add-system-monitor
if request.remote_addr in request.host or request.remote_addr == '127.0.0.1': if request.remote_addr in request.host or request.remote_addr == '127.0.0.1':
for app_id, appointment in watcher.appointments.items(): for uuid, appointment in watcher.appointments.items():
jobs_data = [job.to_json() for job in appointment] watcher_appointments[uuid] = appointment.to_json()
watcher_appointments.append({app_id: jobs_data})
if watcher.responder: if watcher.responder:
for job_id, job in watcher.responder.jobs.items(): for uuid, job in watcher.responder.jobs.items():
job_data = job.to_json() responder_jobs[uuid] = job.to_json()
job_data['confirmations'] = watcher.responder.confirmation_counter.get(job_id)
responder_jobs.append({job_id: job_data})
response = jsonify({"watcher_appointments": watcher_appointments, "responder_jobs": responder_jobs}) response = jsonify({"watcher_appointments": watcher_appointments, "responder_jobs": responder_jobs})