Пример #1
0
def get_latest_topic_by_source_id(request):
    source_id = int(request.matchdict.get('source_id'))
    latest_topic = schema_repository.get_latest_topic_of_source_id(source_id)
    if not latest_topic:
        source = schema_repository.get_source_by_id(source_id)
        if not source:
            raise exceptions_v1.source_not_found_exception()
        raise exceptions_v1.latest_topic_not_found_exception()
    return responses_v1.get_topic_response_from_topic(latest_topic)
Пример #2
0
def get_latest_topic_by_source_id(request):
    source_id = int(request.matchdict.get('source_id'))
    latest_topic = schema_repository.get_latest_topic_of_source_id(source_id)
    if not latest_topic:
        source = schema_repository.get_source_by_id(source_id)
        if not source:
            raise exceptions_v1.source_not_found_exception()
        raise exceptions_v1.latest_topic_not_found_exception()
    return responses_v1.get_topic_response_from_topic(latest_topic)
Пример #3
0
def list_refreshes_by_source_id(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(source_id)
    if not source:
        raise exceptions_v1.source_not_found_exception()
    refresh_history = schema_repository.list_refreshes_by_source_id(
        source_id
    )
    return [responses_v1.get_refresh_response_from_refresh(refresh)
            for refresh in refresh_history]
Пример #4
0
def list_refreshes_by_source_id(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(source_id)
    if not source:
        raise exceptions_v1.source_not_found_exception()
    refresh_history = schema_repository.list_refreshes_by_source_id(source_id)
    return [
        responses_v1.get_refresh_response_from_refresh(refresh)
        for refresh in refresh_history
    ]
Пример #5
0
def delete_category(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    source_category = doc_tool.get_source_category_by_source_id(source_id)
    if source_category is None:
        raise exceptions_v1.category_not_found_exception()
    doc_tool.delete_source_category_by_source_id(source_id)
    return responses_v1.get_category_response_from_source_category(
        source_category)
Пример #6
0
def delete_category(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    source_category = doc_tool.get_source_category_by_source_id(source_id)
    if source_category is None:
        raise exceptions_v1.category_not_found_exception()
    doc_tool.delete_source_category_by_source_id(source_id)
    return responses_v1.get_category_response_from_source_category(
        source_category
    )
Пример #7
0
def update_category(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    req = requests_v1.UpdateCategoryRequest(**request.json_body)
    source_category = doc_tool.get_source_category_by_source_id(source_id)
    if source_category is None:
        source_category = doc_tool.create_source_category(
            source_id, req.category)
    else:
        doc_tool.update_source_category(source_id, req.category)
    return responses_v1.get_category_response_from_source_category(
        source_category)
Пример #8
0
def create_refresh(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    req = requests_v1.CreateRefreshRequest(**request.json_body)
    refresh = schema_repository.create_refresh(
        source_id=source_id,
        offset=req.offset,
        batch_size=req.batch_size,
        priority=req.priority,
        filter_condition=req.filter_condition,
        avg_rows_per_second_cap=req.avg_rows_per_second_cap)
    return responses_v1.get_refresh_response_from_refresh(refresh)
Пример #9
0
def create_refresh(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    req = requests_v1.CreateRefreshRequest(**request.json_body)
    refresh = schema_repository.create_refresh(
        source_id=source_id,
        offset=req.offset,
        batch_size=req.batch_size,
        priority=req.priority,
        filter_condition=req.filter_condition,
        avg_rows_per_second_cap=req.avg_rows_per_second_cap
    )
    return responses_v1.get_refresh_response_from_refresh(refresh)
Пример #10
0
def update_category(request):
    source_id = int(request.matchdict.get('source_id'))
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    req = requests_v1.UpdateCategoryRequest(**request.json_body)
    source_category = doc_tool.get_source_category_by_source_id(source_id)
    if source_category is None:
        source_category = doc_tool.create_source_category(
            source_id,
            req.category
        )
    else:
        doc_tool.update_source_category(source_id, req.category)
    return responses_v1.get_category_response_from_source_category(
        source_category
    )
Пример #11
0
def list_topics_by_source_id(request):
    source_id = int(request.matchdict.get('source_id'))
    topics = schema_repository.get_topics_by_source_id(source_id)
    if not topics and not schema_repository.get_source_by_id(source_id):
        raise exceptions_v1.source_not_found_exception()
    return [responses_v1.get_topic_response_from_topic(t) for t in topics]
Пример #12
0
def get_source_by_id(request):
    source_id = request.matchdict.get('source_id')
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    return responses_v1.get_source_response_from_source(source)
Пример #13
0
def list_topics_by_source_id(request):
    source_id = int(request.matchdict.get('source_id'))
    topics = schema_repository.get_topics_by_source_id(source_id)
    if not topics and not schema_repository.get_source_by_id(source_id):
        raise exceptions_v1.source_not_found_exception()
    return [responses_v1.get_topic_response_from_topic(t) for t in topics]
Пример #14
0
def get_source_by_id(request):
    source_id = request.matchdict.get('source_id')
    source = schema_repository.get_source_by_id(int(source_id))
    if not source:
        raise exceptions_v1.source_not_found_exception()
    return responses_v1.get_source_response_from_source(source)