From 20784ddcd2b5c5d30322df2e30950c19be4a2fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Dominguez?= Date: Wed, 21 Jun 2023 15:48:23 +0200 Subject: [PATCH] =?UTF-8?q?Vuelto=20a=20a=C3=B1adir=20el=20endpoint=20en?= =?UTF-8?q?=20los=20api-*.py=20de=20datadb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vuelto a añadir el endpoint en los api-*.py de datadb Vuelto a añadir el endpoint en los api-*.py de datadb Vuelto a añadir el endpoint en los api-*.py de datadb Vuelto a añadir el endpoint en los api-*.py de datadb --- src/api-prod.py | 11 +++++++++++ src/api-test.py | 20 ++++++++++++++++++++ tests/test_database.py | 1 + 3 files changed, 32 insertions(+) diff --git a/src/api-prod.py b/src/api-prod.py index 00735e1..8572867 100644 --- a/src/api-prod.py +++ b/src/api-prod.py @@ -1,3 +1,5 @@ +import json + from flask import Flask, request from src.endpoints import Endpoints @@ -39,6 +41,15 @@ def one_off_questionnaires(): return endpoints.one_off_questionnaires_endpoint(request_data) +@app.route('/bg_data', methods=["POST"]) +def user_databg(): + """Save user background data from the app""" + request_databg0 = request.json + request_databg = json.loads(request_databg0) + logger.info(f'A request has been received with the following data: {request_databg}') + return endpoints.user_databg_endpoint(request_databg) + + # If this script is being executed and not imported, deploy the API if __name__ == '__main__': app.run(host="0.0.0.0") diff --git a/src/api-test.py b/src/api-test.py index 0e05a80..be10681 100644 --- a/src/api-test.py +++ b/src/api-test.py @@ -1,3 +1,5 @@ +import json + from flask import Flask, request from src.endpoints import Endpoints @@ -38,6 +40,24 @@ def one_off_questionnaires(): logger.info(f'A request has been received with the following data: {request_data}') return endpoints.one_off_questionnaires_endpoint(request_data) +@app.route('/bg_data', methods=["POST"]) +def user_databg(): + """Save user background data from the app""" + request_databg0 = request.json + request_databg = json.loads(request_databg0) + logger.info(f'A request has been received with the following data: {request_databg}') + return endpoints.user_databg_endpoint(request_databg) + + + +@app.route('/bg_data', methods=["POST"]) +def user_databg(): + """Save user background data from the app""" + request_databg0 = request.json + request_databg = json.loads(request_databg0) + logger.info(f'A request has been received with the following data: {request_databg}') + return endpoints.user_databg_endpoint(request_databg) + # If this script is being executed and not imported, deploy the API if __name__ == '__main__': diff --git a/tests/test_database.py b/tests/test_database.py index b02d13b..4863472 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -42,6 +42,7 @@ def testInsertOneOffQuestionnaires(self): response = self.database.insert_one_off_questionnaires(data) self.assertTrue(response.acknowledged, "ACK must be positive") self.assertIsNotNone(response.inserted_ids, "Id must be not none") + def testInsertUserDataBg(self): path = Path(__file__).parent / '../json/input' / 'user_data_full_data.json' with path.open() as json_file: