Partial implementation of mongo logic

This commit is contained in:
Guille Gutierrez 2024-06-21 07:50:09 +02:00
parent 7b45317d4b
commit a9af75bc3b

View File

@ -1,6 +1,7 @@
import json import json
import threading import threading
from bson.json_util import dumps
from co2_emission.co2_emission import Co2Emission from co2_emission.co2_emission import Co2Emission
from costs.cost import Cost from costs.cost import Cost
from flask import Response, request from flask import Response, request
@ -118,22 +119,26 @@ class RetrofitResults(Resource, Config):
f.join() f.join()
return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token) return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)
@staticmethod def get(self):
def get():
client = MongoClient('mongodb://localhost:27017/')
montreal_retrofit_db = client.montreal_retrofit
meb_collection = montreal_retrofit_db.meb
session_id = request.headers.get('session-id', None) session_id = request.headers.get('session-id', None)
if session_id == "deece4fa-6809-42b1-a4e6-36e9f3c6edc2": if session_id == "deece4fa-6809-42b1-a4e6-36e9f3c6edc2":
return Response(json.dumps(dic), status=200) return Response(json.dumps(dic), status=200)
token = request.headers.get('token', None) token = request.headers.get('token', None)
application_uuid = request.headers.get('application-uuid', None) application_uuid = request.headers.get('application-uuid', None)
_session = refresh_session(session_id, token, application_uuid) _session = refresh_session(session_id, token, application_uuid)
_session = {'token': 1}
results = {}
if _session is None: if _session is None:
return Response(json.dumps({'error': 'unauthorized'}), status=403) return Response(json.dumps({'error': 'unauthorized'}), status=403)
else: else:
client = MongoClient(self.mongodb)
montreal_retrofit_db = client[self.mongodb_database]
meb_collection = montreal_retrofit_db[self.mongodb_collection]
token = {'token': _session['token']} token = {'token': _session['token']}
application_id = session(session_id)['application_id'] buildings = request.get_json()['buildings']
user_id = session(session_id)['user_id'] building_query = ''
payload = request.get_json() for building in buildings:
return Response(json.dumps({'result': 'succeed', 'results': {}}), status=200, headers=token) building_query = f'{building_query} {{"alias": "{building}"}},'
query = f'{{"$or": [{building_query[:-1]}]}}'
results = dumps(meb_collection.find(json.loads(query)))
return Response(json.dumps({'result': 'succeed', 'results': results}), status=200, headers=token)