Last active
February 23, 2018 22:17
-
-
Save dcdanko/44e0a67941393d99363370482b1cc205 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mongoengine.errors import ValidationError | |
from app.query_results.query_result_models import QueryResultMeta | |
from app.response import Response | |
class ResultModule: | |
def name(self): | |
raise NotImplementedError() | |
def get_data(self, my_query_result): | |
raise NotImplementedError() | |
def api_call(self, result_id): | |
response = Response() | |
try: | |
query_result = QueryResultMeta.objects(id=result_id) | |
if self.name() not in query_result: | |
msg = '{} is not in this QueryResult.'.format(self.name()) | |
response.message = msg | |
elif query_result[self.name()]['status'] != 'S': | |
response.message = 'Query Result has not finished processing.' | |
else: | |
response.success() | |
response.set_data(self.get_data(query_result[self.name()])) | |
except IndexError: | |
pass | |
except ValidationError as validation_error: | |
response.message = f'{validation_error}' | |
response.code = 400 | |
return response.json_and_code() | |
def register_api_call(self, router): | |
endpt_url = '/query_results/<result_id>/{}'.format(self.name()) | |
router.add_url_rule(endpt_url, | |
self.api_call, | |
methods=['GET']) | |
def get_mongodb_embedded_docs(self): | |
raise NotImplementedError() | |
def get_query_result_wrapper(self): | |
# could get fancy and dynamically generate a class | |
raise NotImplementedError() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment