Commit 9c67dcd3 authored by David Mendez's avatar David Mendez
Browse files

Add controller and service for the separator identifier

parent abf77aed
......@@ -15,6 +15,7 @@ from app.blueprints.search_parser.controllers.search_parser_controller import SE
from app.blueprints.url_shortening.controllers.url_shortening_controller import URL_SHORTENING_BLUEPRINT
from app.blueprints.element_usage_blueprint.controllers.element_usage_controller import ELEMENT_USAGE_BLUEPRINT
from app.blueprints.visualisation_data.controllers.visualisation_data_controller import VISUALISATION_DATA_BLUEPRINT
from app.blueprints.utils.controllers.utils_controller import UTILS_BLUEPRINT
def create_app():
......@@ -50,6 +51,7 @@ def create_app():
flask_app.register_blueprint(URL_SHORTENING_BLUEPRINT, url_prefix=f'{base_path}/url_shortening')
flask_app.register_blueprint(ELEMENT_USAGE_BLUEPRINT, url_prefix=f'{base_path}/frontend_element_usage')
flask_app.register_blueprint(VISUALISATION_DATA_BLUEPRINT, url_prefix=f'{base_path}/visualisations')
flask_app.register_blueprint(UTILS_BLUEPRINT, url_prefix=f'{base_path}/utils')
return flask_app
......
"""
Schemas to validate the utils endpoints
"""
from marshmallow import Schema, fields
class IdentifySeparatorQuery(Schema):
"""
Class that the schema for identifying a separator
"""
type_of_ids = fields.String(required=True)
text = fields.String(required=True)
"""
Module with the controller for the utils endpoints
"""
from flask import Blueprint, jsonify, abort, request
from app.request_validation.decorators import validate_form_with
from app.blueprints.utils.controllers import marshmallow_schemas
from app import app_logging
from app.blueprints.utils.services import utils_service
UTILS_BLUEPRINT = Blueprint('utils', __name__)
@UTILS_BLUEPRINT.route('/identify_separator', methods=['POST'])
@validate_form_with(marshmallow_schemas.IdentifySeparatorQuery)
def get_es_data():
"""
:return: the json response with the separator identified in the text
"""
form_data = request.form
type_of_ids = form_data.get('type_of_ids')
text = form_data.get('text')
app_logging.debug(f'type_of_ids: {type_of_ids}')
app_logging.debug(f'text: {text}')
try:
dict_response = utils_service.identify_separator(type_of_ids, text)
return jsonify(dict_response)
except utils_service.UtilsError as error:
abort(500, msg=f'Internal server error: {str(error)}')
"""
Module with the utils services
"""
class UtilsError(Exception):
"""
Class for errors in this module
"""
def identify_separator(type_of_ids, text):
"""
Identifies the separator for the ids entered in text
:param type_of_ids: type of the ids entered
:param text: text to process
:return: a dict with the separator identified
"""
return {
'separator': 'hola'
}
......@@ -479,7 +479,8 @@ paths:
required: true
type: 'string'
default: 'chembl'
enum: ['chembl']
enum: ['MOLECULE_CHEMBL_IDS', 'TARGET_CHEMBL_IDS', 'ASSAY_CHEMBL_IDS', 'DOCUMENT_CHEMBL_IDS',
'CELL_LINE_CHEMBL_IDS', 'TISSUE_CHEMBL_IDS']
- name: 'text'
in: 'formData'
description: 'Text for which to identify the separator'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment