mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 07:05:36 +01:00
Use orjson in serializers
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from typing import Optional
|
||||
from datetime import date
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class Author(BaseModel):
|
||||
id: int
|
||||
@@ -11,6 +12,9 @@ class Author(BaseModel):
|
||||
last_name: str
|
||||
middle_name: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateAuthor(BaseModel):
|
||||
source: int
|
||||
@@ -20,12 +24,18 @@ class CreateAuthor(BaseModel):
|
||||
last_name: str
|
||||
middle_name: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class UpdateAuthor(BaseModel):
|
||||
first_name: str
|
||||
last_name: str
|
||||
middle_name: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class AuthorBook(BaseModel):
|
||||
id: int
|
||||
@@ -33,11 +43,17 @@ class AuthorBook(BaseModel):
|
||||
lang: str
|
||||
file_type: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class Translation(BaseModel):
|
||||
translator: Author
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class TranslatedBook(BaseModel):
|
||||
id: int
|
||||
@@ -46,3 +62,6 @@ class TranslatedBook(BaseModel):
|
||||
file_type: str
|
||||
authors: list[Author]
|
||||
translations: list[Translation]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
@@ -2,6 +2,8 @@ from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class AuthorAnnotation(BaseModel):
|
||||
id: int
|
||||
@@ -9,6 +11,9 @@ class AuthorAnnotation(BaseModel):
|
||||
text: str
|
||||
file: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateAuthorAnnotation(BaseModel):
|
||||
author: int
|
||||
@@ -16,8 +21,14 @@ class CreateAuthorAnnotation(BaseModel):
|
||||
text: str
|
||||
file: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class UpdateAuthorAnnotation(BaseModel):
|
||||
title: str
|
||||
text: str
|
||||
file: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import date
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.author import Author
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class Book(BaseModel):
|
||||
@@ -14,6 +15,9 @@ class Book(BaseModel):
|
||||
uploaded: date
|
||||
authors: list[Author]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateBook(BaseModel):
|
||||
source: int
|
||||
@@ -24,6 +28,9 @@ class CreateBook(BaseModel):
|
||||
uploaded: date
|
||||
authors: list[int]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class UpdateBook(BaseModel):
|
||||
title: str
|
||||
@@ -32,6 +39,9 @@ class UpdateBook(BaseModel):
|
||||
uploaded: date
|
||||
authors: list[int]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateRemoteBook(BaseModel):
|
||||
source: int
|
||||
@@ -41,3 +51,6 @@ class CreateRemoteBook(BaseModel):
|
||||
file_type: str
|
||||
uploaded: date
|
||||
remote_authors: list[int]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
@@ -2,6 +2,8 @@ from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class BookAnnotation(BaseModel):
|
||||
id: int
|
||||
@@ -9,6 +11,9 @@ class BookAnnotation(BaseModel):
|
||||
text: str
|
||||
file: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateBookAnnotation(BaseModel):
|
||||
id: int
|
||||
@@ -16,9 +21,15 @@ class CreateBookAnnotation(BaseModel):
|
||||
text: str
|
||||
file: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class UpdateBookAnnotation(BaseModel):
|
||||
id: int
|
||||
title: str
|
||||
text: str
|
||||
file: Optional[str]
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
10
fastapi_book_server/app/serializers/orjson_config.py
Normal file
10
fastapi_book_server/app/serializers/orjson_config.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import orjson
|
||||
|
||||
|
||||
def orjson_dumps(v, *, default):
|
||||
return orjson.dumps(v, default=default).decode()
|
||||
|
||||
|
||||
class ORJSONConfig:
|
||||
json_loads = orjson.loads
|
||||
json_dumps = orjson_dumps
|
||||
@@ -1,12 +1,20 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class Sequence(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateSequence(BaseModel):
|
||||
source: int
|
||||
remote_id: int
|
||||
name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class SequenceBookAuthor(BaseModel):
|
||||
id: int
|
||||
@@ -7,6 +9,9 @@ class SequenceBookAuthor(BaseModel):
|
||||
last_name: str
|
||||
middle_name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class SeqTranslationTranslator(BaseModel):
|
||||
id: int
|
||||
@@ -14,11 +19,17 @@ class SeqTranslationTranslator(BaseModel):
|
||||
last_name: str
|
||||
middle_name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class SequenceBookTranslation(BaseModel):
|
||||
id: int
|
||||
translator: SeqTranslationTranslator
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class SequenceBook(BaseModel):
|
||||
id: int
|
||||
@@ -28,11 +39,17 @@ class SequenceBook(BaseModel):
|
||||
authors: SequenceBookAuthor
|
||||
translation: SequenceBookTranslation
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class Sequence(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class SequenceInfo(BaseModel):
|
||||
id: int
|
||||
@@ -40,15 +57,24 @@ class SequenceInfo(BaseModel):
|
||||
sequence: Sequence
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateSequenceInfo(BaseModel):
|
||||
book: int
|
||||
sequence: int
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateRemoteSequenceInfo(BaseModel):
|
||||
source: int
|
||||
remote_book: int
|
||||
remote_sequence: int
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class Source(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateSource(BaseModel):
|
||||
name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.serializers.orjson_config import ORJSONConfig
|
||||
|
||||
|
||||
class TranslationBook(BaseModel):
|
||||
id: int
|
||||
@@ -7,6 +9,9 @@ class TranslationBook(BaseModel):
|
||||
lang: str
|
||||
file_type: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class TranslationTranslator(BaseModel):
|
||||
id: int
|
||||
@@ -14,21 +19,33 @@ class TranslationTranslator(BaseModel):
|
||||
last_name: str
|
||||
middle_name: str
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class Translation(BaseModel):
|
||||
book: TranslationBook
|
||||
translator: TranslationTranslator
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateTranslation(BaseModel):
|
||||
book: int
|
||||
translator: int
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
|
||||
class CreateRemoteTranslation(BaseModel):
|
||||
source: int
|
||||
remote_book: int
|
||||
remote_translator: int
|
||||
position: int
|
||||
|
||||
class Config(ORJSONConfig):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user