mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 15:15:36 +01:00
Add available_types handlers
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from typing import Annotated
|
from typing import Annotated, cast
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||||
|
|
||||||
@@ -110,6 +110,23 @@ async def get_author_books(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@author_router.get("/{id}/available_types", response_model=list[str])
|
||||||
|
async def get_author_books_available_types(
|
||||||
|
id: int, allowed_langs: Annotated[list[str], Depends(get_allowed_langs)]
|
||||||
|
) -> list[str]:
|
||||||
|
books = await BookDB.objects.filter(
|
||||||
|
authors__id=id, lang__in=allowed_langs, is_deleted=False
|
||||||
|
).all()
|
||||||
|
|
||||||
|
file_types: set[str] = set()
|
||||||
|
|
||||||
|
for book in books:
|
||||||
|
for file_type in cast(list[str], book.available_types):
|
||||||
|
file_types.add(file_type)
|
||||||
|
|
||||||
|
return list(file_types)
|
||||||
|
|
||||||
|
|
||||||
@author_router.get(
|
@author_router.get(
|
||||||
"/search/{query}", response_model=Page[Author], dependencies=[Depends(Params)]
|
"/search/{query}", response_model=Page[Author], dependencies=[Depends(Params)]
|
||||||
)
|
)
|
||||||
@@ -158,6 +175,25 @@ async def get_translated_books(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@translator_router.get("/{id}/available_types", response_model=list[str])
|
||||||
|
async def get_translator_books_available_types(
|
||||||
|
id: int, allowed_langs: Annotated[list[str], Depends(get_allowed_langs)]
|
||||||
|
) -> list[str]:
|
||||||
|
books = await BookDB.objects.filter(
|
||||||
|
translators__id=id,
|
||||||
|
lang__in=allowed_langs,
|
||||||
|
is_deleted=False,
|
||||||
|
).all()
|
||||||
|
|
||||||
|
file_types: set[str] = set()
|
||||||
|
|
||||||
|
for book in books:
|
||||||
|
for file_type in cast(list[str], book.available_types):
|
||||||
|
file_types.add(file_type)
|
||||||
|
|
||||||
|
return list(file_types)
|
||||||
|
|
||||||
|
|
||||||
@translator_router.get(
|
@translator_router.get(
|
||||||
"/search/{query}", response_model=Page[Author], dependencies=[Depends(Params)]
|
"/search/{query}", response_model=Page[Author], dependencies=[Depends(Params)]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Annotated
|
from typing import Annotated, cast
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||||
|
|
||||||
@@ -75,6 +75,26 @@ async def get_sequence_books(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@sequence_router.get(
|
||||||
|
"/{id}/available_types",
|
||||||
|
response_model=list[str],
|
||||||
|
)
|
||||||
|
async def sequence_available_types(
|
||||||
|
id: int, allowed_langs: Annotated[list[str], Depends(get_allowed_langs)]
|
||||||
|
) -> list[str]:
|
||||||
|
books = await BookDB.objects.filter(
|
||||||
|
sequence__id=id, lang__in=allowed_langs, is_deleted=False
|
||||||
|
).all()
|
||||||
|
|
||||||
|
file_types: set[str] = set()
|
||||||
|
|
||||||
|
for book in books:
|
||||||
|
for file_type in cast(list[str], book.available_types):
|
||||||
|
file_types.add(file_type)
|
||||||
|
|
||||||
|
return list(file_types)
|
||||||
|
|
||||||
|
|
||||||
@sequence_router.get(
|
@sequence_router.get(
|
||||||
"/search/{query}",
|
"/search/{query}",
|
||||||
response_model=Page[Sequence],
|
response_model=Page[Sequence],
|
||||||
|
|||||||
Reference in New Issue
Block a user