-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.api.api_v2.endpoints import delete, list_videos, patch_video, upload | ||
from app.api.api_v2.endpoints import delete, list_videos, patch_video, tags, upload | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(list_videos.router, tags=['files']) | ||
api_router.include_router(upload.router, tags=['files']) | ||
api_router.include_router(delete.router, tags=['files']) | ||
api_router.include_router(patch_video.router, tags=['files']) | ||
api_router.include_router(tags.router, tags=['tags']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import asyncio | ||
|
||
from fastapi import APIRouter, Depends, Query | ||
from sqlalchemy import desc, func | ||
from sqlmodel import select | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
||
from app.api.dependencies import yield_db_session | ||
from app.api.security import cognito_scheme_or_anonymous | ||
from app.models.klepp import ListResponse, Tag, TagRead | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get('/tags', response_model=ListResponse[TagRead], dependencies=[Depends(cognito_scheme_or_anonymous)]) | ||
async def get_all_tags( | ||
session: AsyncSession = Depends(yield_db_session), | ||
offset: int = 0, | ||
limit: int = Query(default=100, lte=100), | ||
) -> dict[str, int | list]: | ||
""" | ||
Get a list of all non-hidden files, unless you're the owner of the file, then you can request | ||
hidden files. | ||
Works both as anonymous user and as a signed in user. | ||
""" | ||
# Video query | ||
tag_statement = select(Tag).order_by(desc(Tag.name)) | ||
# Total count query based on query params, without pagination | ||
count_statement = select(func.count('*')).select_from(tag_statement) # type: ignore | ||
|
||
# Add pagination | ||
tag_statement = tag_statement.offset(offset=offset).limit(limit=limit) | ||
# Do DB requests async | ||
tasks = [ | ||
asyncio.create_task(session.exec(tag_statement)), # type: ignore | ||
asyncio.create_task(session.exec(count_statement)), | ||
] | ||
results, count = await asyncio.gather(*tasks) | ||
count_number = count.first() | ||
return {'total_count': count_number, 'response': results.all()} |