def create_projection(): database_url = os.environ[DATABASE_URL] database_replica_set = os.environ[DATABASE_REPLICA_SET] database_name = os.environ[DATABASE_NAME] parent_filename = request.json[PARENT_FILENAME_NAME] projection_filename = request.json[PROJECTION_FILENAME_NAME] projection_fields = request.json[FIELDS_NAME] database = Database( database_url, database_replica_set, os.environ[DATABASE_PORT], database_name, ) request_validator = UserRequest(database) request_errors = analyse_request_errors(request_validator, parent_filename, projection_filename, projection_fields) if request_errors is not None: return request_errors database_url_input = Database.collection_database_url( database_url, database_name, parent_filename, database_replica_set, ) database_url_output = Database.collection_database_url( database_url, database_name, projection_filename, database_replica_set, ) metadata_creator = Metadata(database) projection = Projection(metadata_creator, database_url_input, database_url_output) projection.create(parent_filename, projection_filename, projection_fields) return ( jsonify({ MESSAGE_RESULT: MICROSERVICE_URI_GET + projection_filename + MICROSERVICE_URI_GET_PARAMS }), HTTP_STATUS_CODE_SUCCESS_CREATED, )
def create_projection(): parent_filename = request.json[PARENT_FILENAME_NAME] projection_filename = request.json[PROJECTION_FILENAME_NAME] projection_fields = request.json[FIELDS_NAME] request_errors = analyse_request_errors(request_validator, parent_filename, projection_filename, projection_fields) if request_errors is not None: return request_errors database_url_input = Database.collection_database_url( database_url, database_name, parent_filename, database_replica_set, ) database_url_output = Database.collection_database_url( database_url, database_name, projection_filename, database_replica_set, ) metadata_creator = Metadata(database) projection = Projection(metadata_creator, database_url_input, database_url_output) projection.create(parent_filename, projection_filename, projection_fields) return ( jsonify({ MESSAGE_RESULT: f'{MICROSERVICE_URI_GET}{projection_filename}' f'{MICROSERVICE_URI_GET_PARAMS}' }), HTTP_STATUS_CODE_SUCCESS_CREATED, )