From b04d0d60d071ab5749e2c401d1d0b843f39f38df Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 30 Mar 2020 16:32:33 +0200 Subject: [PATCH] consumer and log views --- consumer_api/views/consumers_view.py | 6 +++++- consumer_api/views/log_view.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/consumer_api/views/consumers_view.py b/consumer_api/views/consumers_view.py index feb59ef..5f0c6f5 100644 --- a/consumer_api/views/consumers_view.py +++ b/consumer_api/views/consumers_view.py @@ -1,7 +1,11 @@ +import json +from flask import request, current_app, jsonify +from db import redis_client from flask_classful import FlaskView class ConsumersView(FlaskView): def get(self): - return "ConsumersView" + consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) + return [v['ip'] for k, v in consumer_list.items()] diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index fc589f4..eda8437 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -1,7 +1,9 @@ from flask_classful import FlaskView - +from flask import request, current_app, jsonify class LogView(FlaskView): def get(self): - return "LogView" \ No newline at end of file + remote_uuid = request.json['uuid'] + current_app.logger.info(f"New message from {remote_uuid}: {request.message}") + return jsonify(success = True)