Skip to content
Snippets Groups Projects
Commit 6e5a03d5 authored by Tim Repke's avatar Tim Repke
Browse files

Partially resolves nacsos-web#39

parent f677df5a
No related branches found
No related tags found
1 merge request!36Master
Pipeline #1254 failed
This commit is part of merge request !36. Comments created here will be created in the context of that merge request.
from fastapi import APIRouter, Depends, HTTPException, status, Query
from nacsos_data.db.schemas import Project, ItemTypeLiteral, GenericItem, AcademicItem, ItemType
from nacsos_data.db.schemas import Project, ItemTypeLiteral, GenericItem, AcademicItem, ItemType, Item
from nacsos_data.models.items import AnyItemModel, GenericItemModel, AcademicItemModel, AnyItemModelList
from nacsos_data.models.items.twitter import TwitterItemModel
......@@ -13,6 +13,7 @@ from nacsos_data.db.crud.items.twitter import \
read_all_twitter_items_for_project_paged, \
read_twitter_item_by_item_id, \
import_tweet
from sqlalchemy import select
from server.api.errors import ItemNotFoundError
from server.data import db_engine
......@@ -86,6 +87,16 @@ async def get_detail_for_item(item_id: str,
raise ItemNotFoundError(f'No item found with type {item_type} with the id {item_id}')
@router.get('/text/{item_id}', response_model=str)
async def get_text_for_item(item_id: str, permission=Depends(UserPermissionChecker('dataset_read'))) -> str:
async with db_engine.session() as session:
stmt = select(Item.text).where(Item.item_id==item_id)
text = await session.scalar(stmt)
if text is None:
raise ItemNotFoundError(f'No text available for item with ID: {item_id}')
return text
@router.get('/count', response_model=int)
async def count_project_items(permission=Depends(UserPermissionChecker('dataset_read'))) -> int:
tweets = await read_item_count_for_project(project_id=permission.permissions.project_id, engine=db_engine)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment