from src.storage.storage_prototype import storage_prototype from src.export.exporter_factory import exporter_factory from src.logic.process_factory import process_factory from src.storage.storage import storage from src.validation.validator import validator import json class storage_service: __data = [] def __init__(self, data: list): self.__data = data self.__vtor = validator() @staticmethod def create_response(data, app): """Создать JSON""" data = exporter_factory().create("json").export_models(data) data = json.dumps(data, indent=4, ensure_ascii=False) result = app.response_class( response=data, status=200, mimetype="application/json; charset=utf-8" ) return result def create_turns_nomen(self, strg, nomen, **kwargs): """Отфильтровать по номенклатуре""" prototype = storage_prototype(self.__data) transactions = prototype.filter_nom(nomen).data processing = process_factory().create(storage.process_turn_key(), strg) rests = processing.create(transactions) return rests def create_turns_dt(self, strg, from_dt, to_dt, **kwargs): """Отфильтровать по временному диапазону""" prototype = storage_prototype(self.__data) transactions = prototype.filter_dt(from_dt, to_dt).data processing = process_factory().create(storage.process_turn_key(), strg) rests = processing.create(transactions) return rests def create_turns_recipe(self, strg, recipe, **kwargs): """Отфильтровать по рецепту""" prototype = storage_prototype(self.__data) transactions = prototype.filter_recipe(recipe).data processing = process_factory().create(storage.process_turn_key(), strg) rests = processing.create(transactions) return rests @property def data(self) -> list: return self.__data