def create_topic_schema(topic):
    if topic.topicId is None or check_fake_id(topic.topicId):
        topic.topicId = get_surrogate_key()
    if type(topic) is not dict:
        topic = topic.dict()
    save_topic(topic)
    return Topic.parse_obj(topic)
def update_topic_schema(
        topic_id,
        topic: Topic):
    if type(topic) is not dict:
        topic = topic.dict()
    update_topic(topic_id, topic)
    return Topic.parse_obj(topic)
예제 #3
0
async def update_topic(topic_id,
                       topic: Topic = Body(...),
                       current_user: User = Depends(deps.get_current_user)):
    topic = Topic.parse_obj(topic)
    data = update_topic_schema(topic_id, topic)
    # remove_presto_schema_by_name(topic.name)
    create_or_update_presto_schema_fields(data)
    return data
예제 #4
0
async def save_topic(topic: Topic, current_user: User = Depends(deps.get_current_user)):
    if check_fake_id(topic.topicId):
        result = create_topic_schema(topic)
        create_or_update_presto_schema_fields(result)
        return result
    else:
        topic = Topic.parse_obj(topic)
        data = update_topic_schema(topic.topicId, topic)
        create_or_update_presto_schema_fields(data)
        return data
def get_topic_by_id(topic_id):
    result = topics.find_one({"topicId": topic_id})
    if result is None:
        return None
    else:
        return Topic.parse_obj(result)
def get_topic(topic_name) -> Topic:
    result = topics.find_one({"name": topic_name})
    if result is None:
        return None
    else:
        return Topic.parse_obj(result)