class Component(): def __init__(self): self.__component_group_entity = ComponentGroupEntity() self.__component_entity = ComponentEntity() def get_one_by_id(self, id): component = self.__component_entity.get_one_by_id(id) if not component: return False return { "id": component.id, "name": component.name, "description": component.description, "uptime": component.uptime, "group_id": "" if component.group is None else component.group.id, "group_name": "" if component.group is None else component.group.name } def get_one_by_name(self, name): component = self.__component_entity.get_one_by_name(name) if not component: return False return { "id": component.id, "name": component.name, "description": component.description, "uptime": component.uptime, "group_id": "" if component.group is None else component.group.id, "group_name": "" if component.group is None else component.group.name } def insert_one(self, component): return self.__component_entity.insert_one(component) def update_one_by_id(self, id, component_data): return self.__component_entity.update_one_by_id(id, component_data) def count_all(self): return self.__component_entity.count_all() def get_all(self, offset=None, limit=None): return self.__component_entity.get_all(offset, limit) def get_all_groups(self): return self.__component_group_entity.get_all() def delete_one_by_id(self, id): return self.__component_entity.delete_one_by_id(id)
class ComponentGroup(): def __init__(self): self.__component_group_entity = ComponentGroupEntity() self.__component_entity = ComponentEntity() def get_one_by_id(self, id): group = self.__component_group_entity.get_one_by_id(id) if not group: return False return { "id": group.id, "name": group.name, "uptime": group.uptime, "description": group.description, } def get_one_by_name(self, name): group = self.__component_group_entity.get_one_by_name(name) if not group: return False return { "id": group.id, "name": group.name, "uptime": group.uptime, "description": group.description, } def insert_one(self, group): return self.__component_group_entity.insert_one(group) def update_one_by_id(self, id, group_data): return self.__component_group_entity.update_one_by_id(id, group_data) def count_all(self): return self.__component_group_entity.count_all() def count_components(self, group_id): return self.__component_entity.count(group_id) def get_all(self, offset=None, limit=None): return self.__component_group_entity.get_all(offset, limit) def delete_one_by_id(self, id): self.__component_entity.clear_group(id) return self.__component_group_entity.delete_one_by_id(id)