コード例 #1
0
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)
コード例 #2
0
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
コード例 #5
0
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)
コード例 #6
0
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)