def create_space(space: Space):
    if space.spaceId is None or check_fake_id(space.spaceId):
        space.spaceId = get_surrogate_key()
    if type(space) is not dict:
        space = space.dict()

    insert_space_to_storage(space)
    return space
def add_topic_to_space(topic: Topic, space: Space):
    topic_list = space.topic_list
    if topic_list is None:
        topic_list = []
    topic_list.append(topic)
    space.topic_list = topic_list
    return update_space_to_storage(space)
async def load_space_list_by_user(current_user: User = Depends(deps.get_current_user)):
    space_list = load_space_by_user(current_user.groupIds)
    available_space_list = []
    for space in list(space_list):
        space = Space.parse_obj(space)
        available_space = AvailableSpace()
        available_space.spaceId = space.spaceId
        available_space.name = space.name
        available_space.description = space.description
        available_space.topicIds = space.topicIds
        available_space_list.append(available_space)
    return available_space_list
def update_space_by_id(space_id: str, space: Space) -> Space:
    if type(space) is not dict:
        space = space.dict()
    return update_space_to_storage(space_id, space)
def update_topic_in_space(topic: Topic, space: Space):
    topic_list = __merge_topic_list(space.topic_list, topic)
    space.topic_list = topic_list
    return update_space_to_storage(space)
def update_space_by_id(space_id: int, space: Space):
    if type(space) is not dict:
        space = space.dict()
    update_space_to_storage(space_id, space)
    return space
Exemple #7
0
def get_space_by_id(space_id: str):
    result = spaces.find_one({"spaceId": space_id})
    if result is None:
        return None
    else:
        return Space.parse_obj(result)