mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2026-03-03 15:10:51 +01:00
Add translators to Book serializers
This commit is contained in:
@@ -21,10 +21,13 @@ book_router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
SELECT_RELATED_FIELDS = ["source", "authors", "translators", "annotations"]
|
||||
|
||||
|
||||
@book_router.get("/", response_model=CustomPage[RemoteBook], dependencies=[Depends(Params)])
|
||||
async def get_books(book_filter: dict = Depends(get_book_filter)):
|
||||
return await paginate(
|
||||
BookDB.objects.select_related(["source", "authors", "annotations"]).filter(**book_filter)
|
||||
BookDB.objects.select_related(SELECT_RELATED_FIELDS).filter(**book_filter)
|
||||
)
|
||||
|
||||
|
||||
@@ -32,12 +35,12 @@ async def get_books(book_filter: dict = Depends(get_book_filter)):
|
||||
async def create_book(data: Union[CreateBook, CreateRemoteBook]):
|
||||
book = await BookCreator.create(data)
|
||||
|
||||
return await BookDB.objects.select_related(["source", "authors", "annotations"]).get(id=book.id)
|
||||
return await BookDB.objects.select_related(SELECT_RELATED_FIELDS).get(id=book.id)
|
||||
|
||||
|
||||
@book_router.get("/{id}", response_model=BookDetail)
|
||||
async def get_book(id: int):
|
||||
book = await BookDB.objects.select_related(["source", "authors", "annotations"]).get_or_none(id=id)
|
||||
book = await BookDB.objects.select_related(SELECT_RELATED_FIELDS).get_or_none(id=id)
|
||||
|
||||
if book is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
@@ -47,7 +50,7 @@ async def get_book(id: int):
|
||||
|
||||
@book_router.get("/remote/{source_id}/{remote_id}", response_model=Book)
|
||||
async def get_remote_book(source_id: int, remote_id: int):
|
||||
book = await BookDB.objects.select_related(["source", "authors", "annotations"]).get_or_none(
|
||||
book = await BookDB.objects.select_related(SELECT_RELATED_FIELDS).get_or_none(
|
||||
source=source_id,
|
||||
remote_id=remote_id
|
||||
)
|
||||
@@ -60,7 +63,7 @@ async def get_remote_book(source_id: int, remote_id: int):
|
||||
|
||||
@book_router.put("/{id}", response_model=Book)
|
||||
async def update_book(id: int, data: UpdateBook):
|
||||
book = await BookDB.objects.select_related(["source", "authors", "annotations"]).get_or_none(id=id)
|
||||
book = await BookDB.objects.select_related(SELECT_RELATED_FIELDS).get_or_none(id=id)
|
||||
|
||||
if book is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
|
||||
Reference in New Issue
Block a user