コード例 #1
0
def save_console_space(console_space: ConsoleSpace):
    if console_space.connectId is None or check_fake_id(
            console_space.connectId):
        console_space.connectId = get_surrogate_key()
        return create_console_space(console_space)
    else:
        return update_console_space(console_space)
コード例 #2
0
async def connect_to_space(space_id, name, current_user: User = Depends(deps.get_current_user)):
    topic_list = load_topic_list_by_space_id(space_id)
    console_space = ConsoleSpace()
    console_space.topics = topic_list
    console_space.spaceId = space_id
    console_space.name = name
    console_space.userId = current_user.userId
    console_space.lastVisitTime = datetime.now().replace(tzinfo=None)
    return save_console_space(console_space)
コード例 #3
0
async def load_connected_space(current_user: User = Depends(
    deps.get_current_user)):
    user_id = current_user.userId
    console_space_list = load_console_space_list_by_user(user_id)
    result = []
    for data in console_space_list:
        console_space = ConsoleSpace.parse_obj(data)
        topic_list = load_topic_list_by_space_id(console_space.spaceId)
        console_space.topics = topic_list
        # topic_ids = list(map(lambda x: x["topicId"], topic_list))
        # source_relation = load_relationships_by_topic_ids(topic_ids)
        # target_relation = load_relationships_by_topic_ids_target(topic_ids)
        # console_space.topicRelations = [*source_relation, *target_relation]

        if console_space.subjectIds is not None:
            subjects = load_console_subject_list_by_ids(
                console_space.subjectIds)
            for subject in subjects:
                subject["reports"] = load_reports_by_ids(subject["reportIds"])
            console_space.subjects = subjects
        result.append(console_space)
    return result
コード例 #4
0
def load_console_space_by_subject_id(subject_id):
    result = console_spaces.find_one({"subjectIds": subject_id})
    return ConsoleSpace.parse_obj(result)
コード例 #5
0
def load_console_space_by_id(connect_id: str):
    result = console_spaces.find_one({"connectId": connect_id})
    if result is None:
        return None
    else:
        return ConsoleSpace.parse_obj(result)
コード例 #6
0
def update_console_space(console_space: ConsoleSpace):
    console_spaces.update_one({"connectId": console_space.connectId},
                              {"$set": console_space.dict()})
    return console_space
コード例 #7
0
def create_console_space(console_space: ConsoleSpace):
    console_spaces.insert(console_space.dict())
    return console_space