add comic artists

This commit is contained in:
Thomas Peetz
2025-09-21 20:09:46 +02:00
parent 64ed4876a5
commit 6d88b87f93
30 changed files with 366 additions and 107 deletions
-9
View File
@@ -1,9 +1,6 @@
from typing import List, Dict
from pydantic import BaseModel
class ArtistCreation(BaseModel):
id: str
name: str
@@ -11,9 +8,3 @@ class ArtistCreation(BaseModel):
class ArtistResponse(BaseModel):
id: str
name: str
class ArtistDetailResponse(BaseModel):
id: str
name: str
weblink: str
works: Dict[str, List[str]]
@@ -0,0 +1,16 @@
from typing import List
from pydantic import BaseModel
from src.schema.comics.comic import ComicResponse
from src.schema.comics.worktype import WorktypeResponse
class ArtistWorktypeComicResponse(BaseModel):
worktype: WorktypeResponse
comics: List[ComicResponse]
class ArtistDetailResponse(BaseModel):
id: str
name: str
weblink: str
works: List[ArtistWorktypeComicResponse]
+1 -68
View File
@@ -1,12 +1,6 @@
from typing import List, Dict, Optional
from typing import Optional
from pydantic import BaseModel, AnyUrl
from src.core.log_conf import logger
from src.db.models.comic import Comic
from src.schema.comics.artist import ArtistResponse
from src.schema.comics.volume import VolumeResponse
from src.schema.comics.worktype import WorktypeResponse
class ComicResponse(BaseModel):
@@ -15,70 +9,9 @@ class ComicResponse(BaseModel):
completed: bool
class ComicWorktypeArtistResponse(BaseModel):
worktype: WorktypeResponse
artists: List[ArtistResponse]
class ComicDetailsResponse(BaseModel):
id: str
created: str
title: str
completed : bool
current_order : bool
weblink: str
publisher: str
volumes: List[VolumeResponse]
works: List[ComicWorktypeArtistResponse]
class ComicSchema(BaseModel):
id: str
title: str
weblink: Optional[AnyUrl]
completed: Optional[bool]
current_order: Optional[bool]
def get_short_info(comic: Comic) -> ComicResponse:
response = ComicResponse(
id=comic.id,
title=str(comic.title),
completed=bool(comic.completed == 1)
)
return response
def get_comic_details(comic: Comic) -> ComicDetailsResponse:
volumes: List[VolumeResponse] = []
for volume in comic.volumes:
volumes.append(VolumeResponse(id=volume.id, name=volume.name))
works: List[ComicWorktypeArtistResponse] = []
works_map: Dict[str, ComicWorktypeArtistResponse] = {}
for work in comic.comic_works:
worktype_id = work.work_type.id
if worktype_id in works_map:
artist = ArtistResponse(id=work.artist.id, name=work.artist.name)
works_map[worktype_id].artists.append(artist)
logger.info(f"add artist to response map: {artist} -> {works_map}")
print(f"add artist to response map: {artist} -> {works_map}")
else:
works_map[worktype_id] = ComicWorktypeArtistResponse(
worktype=WorktypeResponse(id=worktype_id, name=work.work_type.name),
artists=[ArtistResponse(id=work.artist.id, name=work.artist.name)]
)
for value in works_map.values():
works.append(value)
response = ComicDetailsResponse(
id=comic.id,
created=str(comic.created_date),
title=str(comic.title),
completed=bool(comic.completed),
current_order=bool(comic.current_order),
weblink=str(comic.weblink),
publisher=comic.publisher.name,
volumes=volumes,
works=works
)
return response
@@ -0,0 +1,23 @@
from typing import List
from pydantic import BaseModel
from src.schema.comics.artist import ArtistResponse
from src.schema.comics.volume import VolumeResponse
from src.schema.comics.worktype import WorktypeResponse
class ComicWorktypeArtistResponse(BaseModel):
worktype: WorktypeResponse
artists: List[ArtistResponse]
class ComicDetailsResponse(BaseModel):
id: str
created: str
title: str
completed : bool
current_order : bool
weblink: str
publisher: str
volumes: List[VolumeResponse]
works: List[ComicWorktypeArtistResponse]