mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 15:15:36 +01:00
Add linters configs
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
from app.views.source import source_router
|
||||
|
||||
from app.views.author import author_router
|
||||
from app.views.author_annotation import author_annotation_router
|
||||
|
||||
from app.views.book import book_router
|
||||
from app.views.book_annotation import book_annotation_router
|
||||
|
||||
from app.views.translation import translation_router
|
||||
|
||||
from app.views.sequence import sequence_router
|
||||
from app.views.source import source_router
|
||||
from app.views.translation import translation_router
|
||||
|
||||
|
||||
routers = [
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
from random import choice as random_choice
|
||||
|
||||
from fastapi import APIRouter, Depends, Request, HTTPException, status
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
from app.models import Author as AuthorDB, AuthorAnnotation as AuthorAnnotationDB, Book as BookDB
|
||||
from app.serializers.author import Author, CreateAuthor, UpdateAuthor, AuthorBook, TranslatedBook
|
||||
from app.depends import check_token
|
||||
from app.models import Author as AuthorDB
|
||||
from app.models import AuthorAnnotation as AuthorAnnotationDB
|
||||
from app.models import Book as BookDB
|
||||
from app.serializers.author import (
|
||||
Author,
|
||||
CreateAuthor,
|
||||
UpdateAuthor,
|
||||
AuthorBook,
|
||||
TranslatedBook,
|
||||
)
|
||||
from app.serializers.author_annotation import AuthorAnnotation
|
||||
from app.services.author import AuthorTGRMSearchService, GetRandomAuthorService
|
||||
from app.depends import check_token
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
author_router = APIRouter(
|
||||
@@ -20,22 +26,19 @@ author_router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
|
||||
PREFETCH_RELATED = ["source", "annotations"]
|
||||
|
||||
|
||||
@author_router.get("/", response_model=CustomPage[Author], dependencies=[Depends(Params)])
|
||||
@author_router.get(
|
||||
"/", response_model=CustomPage[Author], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def get_authors():
|
||||
return await paginate(
|
||||
AuthorDB.objects.prefetch_related(PREFETCH_RELATED)
|
||||
)
|
||||
return await paginate(AuthorDB.objects.prefetch_related(PREFETCH_RELATED))
|
||||
|
||||
|
||||
@author_router.post("/", response_model=Author, dependencies=[Depends(Params)])
|
||||
async def create_author(data: CreateAuthor):
|
||||
author = await AuthorDB.objects.create(
|
||||
**data.dict()
|
||||
)
|
||||
author = await AuthorDB.objects.create(**data.dict())
|
||||
|
||||
return await AuthorDB.objects.prefetch_related(PREFETCH_RELATED).get(id=author.id)
|
||||
|
||||
@@ -49,7 +52,9 @@ async def get_random_author():
|
||||
|
||||
@author_router.get("/{id}", response_model=Author)
|
||||
async def get_author(id: int):
|
||||
author = await AuthorDB.objects.prefetch_related(PREFETCH_RELATED).get_or_none(id=id)
|
||||
author = await AuthorDB.objects.prefetch_related(PREFETCH_RELATED).get_or_none(
|
||||
id=id
|
||||
)
|
||||
|
||||
if author is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
@@ -75,24 +80,32 @@ async def get_author_annotation(id: int):
|
||||
|
||||
if annotation is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
return annotation
|
||||
|
||||
|
||||
@author_router.get("/{id}/books", response_model=CustomPage[AuthorBook], dependencies=[Depends(Params)])
|
||||
@author_router.get(
|
||||
"/{id}/books", response_model=CustomPage[AuthorBook], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def get_author_books(id: int):
|
||||
return await paginate(
|
||||
BookDB.objects.select_related(["source", "annotations", "translators"]).filter(authors__id=id).order_by('title')
|
||||
BookDB.objects.select_related(["source", "annotations", "translators"])
|
||||
.filter(authors__id=id)
|
||||
.order_by("title")
|
||||
)
|
||||
|
||||
|
||||
@author_router.get("/{id}/translated_books", response_model=CustomPage[TranslatedBook])
|
||||
async def get_translated_books(id: int):
|
||||
return await paginate(
|
||||
BookDB.objects.select_related(["source", "annotations", "translators"]).filter(translations__translator__id=id)
|
||||
BookDB.objects.select_related(["source", "annotations", "translators"]).filter(
|
||||
translations__translator__id=id
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@author_router.get("/search/{query}", response_model=CustomPage[Author], dependencies=[Depends(Params)])
|
||||
@author_router.get(
|
||||
"/search/{query}", response_model=CustomPage[Author], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def search_authors(query: str, request: Request):
|
||||
return await AuthorTGRMSearchService.get(query, request.app.state.redis)
|
||||
|
||||
@@ -3,9 +3,13 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.models import AuthorAnnotation as AuthorAnnotationDB
|
||||
from app.serializers.author_annotation import AuthorAnnotation, CreateAuthorAnnotation, UpdateAuthorAnnotation
|
||||
from app.depends import check_token
|
||||
from app.models import AuthorAnnotation as AuthorAnnotationDB
|
||||
from app.serializers.author_annotation import (
|
||||
AuthorAnnotation,
|
||||
CreateAuthorAnnotation,
|
||||
UpdateAuthorAnnotation,
|
||||
)
|
||||
|
||||
|
||||
author_annotation_router = APIRouter(
|
||||
@@ -15,18 +19,16 @@ author_annotation_router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
@author_annotation_router.get("/", response_model=Page[AuthorAnnotation], dependencies=[Depends(Params)])
|
||||
@author_annotation_router.get(
|
||||
"/", response_model=Page[AuthorAnnotation], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def get_author_annotations():
|
||||
return await paginate(
|
||||
AuthorAnnotationDB.objects
|
||||
)
|
||||
return await paginate(AuthorAnnotationDB.objects)
|
||||
|
||||
|
||||
@author_annotation_router.post("/", response_model=AuthorAnnotation)
|
||||
async def create_author_annotation(data: CreateAuthorAnnotation):
|
||||
return await AuthorAnnotationDB.objects.create(
|
||||
**data.dict()
|
||||
)
|
||||
return await AuthorAnnotationDB.objects.create(**data.dict())
|
||||
|
||||
|
||||
@author_annotation_router.get("/{id}", response_model=AuthorAnnotation)
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
from typing import Union
|
||||
from random import choice as random_choice
|
||||
|
||||
from fastapi import APIRouter, Depends, Request, HTTPException, status
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
from app.models import Book as BookDB, Author as AuthorDB, BookAnnotation as BookAnnotationDB
|
||||
from app.serializers.book import Book, RemoteBook, BookDetail, CreateBook, UpdateBook, CreateRemoteBook
|
||||
from app.depends import check_token
|
||||
from app.filters.book import get_book_filter
|
||||
from app.models import Author as AuthorDB
|
||||
from app.models import Book as BookDB
|
||||
from app.models import BookAnnotation as BookAnnotationDB
|
||||
from app.serializers.book import (
|
||||
Book,
|
||||
RemoteBook,
|
||||
BookDetail,
|
||||
CreateBook,
|
||||
UpdateBook,
|
||||
CreateRemoteBook,
|
||||
)
|
||||
from app.serializers.book_annotation import BookAnnotation
|
||||
from app.services.book import BookTGRMSearchService, GetRandomBookService, BookCreator
|
||||
from app.filters.book import get_book_filter
|
||||
from app.depends import check_token
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
book_router = APIRouter(
|
||||
@@ -22,10 +30,12 @@ book_router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
SELECT_RELATED_FIELDS = ["source", "authors", "translators", "annotations"]
|
||||
SELECT_RELATED_FIELDS = ["source", "authors", "translators", "annotations"]
|
||||
|
||||
|
||||
@book_router.get("/", response_model=CustomPage[RemoteBook], dependencies=[Depends(Params)])
|
||||
@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(SELECT_RELATED_FIELDS).filter(**book_filter)
|
||||
@@ -49,7 +59,7 @@ async def get_random_book():
|
||||
@book_router.get("/{id}", response_model=BookDetail)
|
||||
async def get_book(id: int):
|
||||
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)
|
||||
|
||||
@@ -59,8 +69,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(SELECT_RELATED_FIELDS).get_or_none(
|
||||
source=source_id,
|
||||
remote_id=remote_id
|
||||
source=source_id, remote_id=remote_id
|
||||
)
|
||||
|
||||
if book is None:
|
||||
@@ -84,9 +93,7 @@ async def update_book(id: int, data: UpdateBook):
|
||||
author_ids = data_dict.pop("authors", [])
|
||||
authors = await AuthorDB.objects.filter(id__in=author_ids).all()
|
||||
|
||||
book = await BookDB.objects.create(
|
||||
**data_dict
|
||||
)
|
||||
book = await BookDB.objects.create(**data_dict)
|
||||
|
||||
for author in authors:
|
||||
await book.authors.add(author)
|
||||
@@ -104,6 +111,8 @@ async def get_book_annotation(id: int):
|
||||
return annotation
|
||||
|
||||
|
||||
@book_router.get("/search/{query}", response_model=CustomPage[Book], dependencies=[Depends(Params)])
|
||||
@book_router.get(
|
||||
"/search/{query}", response_model=CustomPage[Book], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def search_books(query: str, request: Request):
|
||||
return await BookTGRMSearchService.get(query, request.app.state.redis)
|
||||
|
||||
@@ -3,30 +3,32 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.models import BookAnnotation as BookAnnotationDB
|
||||
from app.serializers.book_annotation import BookAnnotation, CreateBookAnnotation, UpdateBookAnnotation
|
||||
from app.depends import check_token
|
||||
from app.models import BookAnnotation as BookAnnotationDB
|
||||
from app.serializers.book_annotation import (
|
||||
BookAnnotation,
|
||||
CreateBookAnnotation,
|
||||
UpdateBookAnnotation,
|
||||
)
|
||||
|
||||
|
||||
book_annotation_router = APIRouter(
|
||||
prefix="/api/v1/book_annotations",
|
||||
tags=["book_annotation"],
|
||||
dependencies=[Depends(check_token)]
|
||||
dependencies=[Depends(check_token)],
|
||||
)
|
||||
|
||||
|
||||
@book_annotation_router.get("/", response_model=Page[BookAnnotation], dependencies=[Depends(Params)])
|
||||
@book_annotation_router.get(
|
||||
"/", response_model=Page[BookAnnotation], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def get_book_annotations():
|
||||
return await paginate(
|
||||
BookAnnotationDB.objects
|
||||
)
|
||||
return await paginate(BookAnnotationDB.objects)
|
||||
|
||||
|
||||
@book_annotation_router.post("/", response_model=BookAnnotation)
|
||||
async def create_book_annotation(data: CreateBookAnnotation):
|
||||
return await BookAnnotationDB.objects.create(
|
||||
**data.dict()
|
||||
)
|
||||
return await BookAnnotationDB.objects.create(**data.dict())
|
||||
|
||||
|
||||
@book_annotation_router.get("/{id}", response_model=BookAnnotation)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
from random import choice as random_choice
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
from app.models import Sequence as SequenceDB, Book as BookDB, BookSequences as BookSequencesDB
|
||||
from app.serializers.sequence import Sequence, CreateSequence, Book as SequenceBook
|
||||
from app.services.sequence import SequenceTGRMSearchService, GetRandomSequenceService
|
||||
from app.depends import check_token
|
||||
from app.models import Book as BookDB
|
||||
from app.models import Sequence as SequenceDB
|
||||
from app.serializers.sequence import Book as SequenceBook
|
||||
from app.serializers.sequence import Sequence, CreateSequence
|
||||
from app.services.sequence import SequenceTGRMSearchService, GetRandomSequenceService
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
sequence_router = APIRouter(
|
||||
@@ -19,11 +19,11 @@ sequence_router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
@sequence_router.get("/", response_model=CustomPage[Sequence], dependencies=[Depends(Params)])
|
||||
@sequence_router.get(
|
||||
"/", response_model=CustomPage[Sequence], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def get_sequences():
|
||||
return await paginate(
|
||||
SequenceDB.objects
|
||||
)
|
||||
return await paginate(SequenceDB.objects)
|
||||
|
||||
|
||||
@sequence_router.get("/random", response_model=Sequence)
|
||||
@@ -38,21 +38,30 @@ async def get_sequence(id: int):
|
||||
return await SequenceDB.objects.get(id=id)
|
||||
|
||||
|
||||
@sequence_router.get("/{id}/books", response_model=CustomPage[SequenceBook], dependencies=[Depends(Params)])
|
||||
@sequence_router.get(
|
||||
"/{id}/books",
|
||||
response_model=CustomPage[SequenceBook],
|
||||
dependencies=[Depends(Params)],
|
||||
)
|
||||
async def get_sequence_books(id: int):
|
||||
return await paginate(
|
||||
BookDB.objects.select_related(["source", "annotations", "authors", "translators"])
|
||||
.filter(sequences__id=id).order_by("sequences__booksequences__position")
|
||||
BookDB.objects.select_related(
|
||||
["source", "annotations", "authors", "translators"]
|
||||
)
|
||||
.filter(sequences__id=id)
|
||||
.order_by("sequences__booksequences__position")
|
||||
)
|
||||
|
||||
|
||||
@sequence_router.post("/", response_model=Sequence)
|
||||
async def create_sequence(data: CreateSequence):
|
||||
return await SequenceDB.objects.create(
|
||||
**data.dict()
|
||||
)
|
||||
return await SequenceDB.objects.create(**data.dict())
|
||||
|
||||
|
||||
@sequence_router.get("/search/{query}", response_model=CustomPage[Sequence], dependencies=[Depends(Params)])
|
||||
@sequence_router.get(
|
||||
"/search/{query}",
|
||||
response_model=CustomPage[Sequence],
|
||||
dependencies=[Depends(Params)],
|
||||
)
|
||||
async def search_sequences(query: str, request: Request):
|
||||
return await SequenceTGRMSearchService.get(query, request.app.state.redis)
|
||||
|
||||
@@ -3,9 +3,9 @@ from fastapi import APIRouter, Depends
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.depends import check_token
|
||||
from app.models import Source as SourceDB
|
||||
from app.serializers.source import Source, CreateSource
|
||||
from app.depends import check_token
|
||||
|
||||
|
||||
source_router = APIRouter(
|
||||
@@ -22,6 +22,4 @@ async def get_sources():
|
||||
|
||||
@source_router.post("", response_model=Source)
|
||||
async def create_source(data: CreateSource):
|
||||
return await SourceDB.objects.create(
|
||||
**data.dict()
|
||||
)
|
||||
return await SourceDB.objects.create(**data.dict())
|
||||
|
||||
@@ -4,12 +4,16 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
from app.models import Translation as TranslationDB
|
||||
from app.serializers.translation import Translation, CreateTranslation, CreateRemoteTranslation
|
||||
from app.services.translation import TranslationCreator
|
||||
from app.depends import check_token
|
||||
from app.models import Translation as TranslationDB
|
||||
from app.serializers.translation import (
|
||||
Translation,
|
||||
CreateTranslation,
|
||||
CreateRemoteTranslation,
|
||||
)
|
||||
from app.services.translation import TranslationCreator
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
translation_router = APIRouter(
|
||||
@@ -19,23 +23,27 @@ translation_router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
@translation_router.get("/", response_model=CustomPage[Translation], dependencies=[Depends(Params)])
|
||||
@translation_router.get(
|
||||
"/", response_model=CustomPage[Translation], dependencies=[Depends(Params)]
|
||||
)
|
||||
async def get_translations():
|
||||
return await paginate(
|
||||
TranslationDB.objects.prefetch_related(["book", "author"])
|
||||
)
|
||||
return await paginate(TranslationDB.objects.prefetch_related(["book", "author"]))
|
||||
|
||||
|
||||
@translation_router.post("/", response_model=Translation)
|
||||
async def create_translation(data: Union[CreateTranslation, CreateRemoteTranslation]):
|
||||
translation = await TranslationCreator.create(data)
|
||||
|
||||
return await TranslationDB.objects.prefetch_related(["book", "author"]).get(id=translation.id)
|
||||
return await TranslationDB.objects.prefetch_related(["book", "author"]).get(
|
||||
id=translation.id
|
||||
)
|
||||
|
||||
|
||||
@translation_router.delete("/{id}", response_model=Translation)
|
||||
async def delete_translation(id: int):
|
||||
translation = await TranslationDB.objects.prefetch_related(["book", "author"]).get_or_none(id=id)
|
||||
translation = await TranslationDB.objects.prefetch_related(
|
||||
["book", "author"]
|
||||
).get_or_none(id=id)
|
||||
|
||||
if translation is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
|
||||
Reference in New Issue
Block a user