Exemplo n.º 1
0
def get_structures(region: str, system: str = None):
    if not system:
        return only_alive(
            table.query_index('structure_index', {'region_id': region}))
    else:
        schemas.validate_system(system)
        structures = table.query_index('structure_index',
                                       {'region_id': region}, {'sk': system})
        return only_alive(structures)
Exemplo n.º 2
0
def create_structure(structure: schemas.StructureCreate):
    schemas.validate_system(structure.sk)
    if not structure.region_id:
        setattr(structure, 'region_id', str(get_region(structure.sk)))
    db_str = schemas.Structure(structure_id=str(uuid.uuid4()),
                               system_id=structure.sk,
                               **structure.dict())
    table.put(db_str)
    return db_str
Exemplo n.º 3
0
def update_structure(structure_id: str, structure: schemas.StructureCreate):
    schemas.validate_system(structure.sk)
    current_structure = get_structure(structure_id, structure.sk)
    print(structure.dict())
    for k, v in structure.dict().items():
        print(f"checking {k}")
        curr = getattr(current_structure, k)
        new = getattr(structure, k)
        if (not new) and curr:
            setattr(structure, k, curr)
    print(structure.dict())
    new_structure = Structure(structure_id=structure_id,
                              system_id=structure.sk,
                              **structure.dict())
    table.put(new_structure)
    return new_structure
Exemplo n.º 4
0
def get_structure(structure_id: str, system_id: str):
    schemas.validate_system(system_id)
    db_structure = crud.get_structure(structure_id, system_id)
    return db_structure
Exemplo n.º 5
0
def get_structure(structure_id: str, system_id: str) -> Structure:
    schemas.validate_system(system_id)
    structure = table.get(structure_id, system_id)
    return form_structure(structure)