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

Merge branch 'master' into 'production'

Master

See merge request !36
parents 6fc4ec5a f6a52edb
No related branches found
No related tags found
1 merge request!36Master
Pipeline #1256 passed
from fastapi import APIRouter, Depends, HTTPException, status, Query 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 import AnyItemModel, GenericItemModel, AcademicItemModel, AnyItemModelList
from nacsos_data.models.items.twitter import TwitterItemModel from nacsos_data.models.items.twitter import TwitterItemModel
...@@ -13,6 +13,7 @@ from nacsos_data.db.crud.items.twitter import \ ...@@ -13,6 +13,7 @@ from nacsos_data.db.crud.items.twitter import \
read_all_twitter_items_for_project_paged, \ read_all_twitter_items_for_project_paged, \
read_twitter_item_by_item_id, \ read_twitter_item_by_item_id, \
import_tweet import_tweet
from sqlalchemy import select
from server.api.errors import ItemNotFoundError from server.api.errors import ItemNotFoundError
from server.data import db_engine from server.data import db_engine
...@@ -86,6 +87,16 @@ async def get_detail_for_item(item_id: str, ...@@ -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}') 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: str | None = 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) @router.get('/count', response_model=int)
async def count_project_items(permission=Depends(UserPermissionChecker('dataset_read'))) -> 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) 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