Files
kontor/kontor-api/src/models/comics/comic.py
T
2025-04-21 17:39:20 +02:00

47 lines
1.1 KiB
Python

from typing import List, Dict
from uuid import UUID
from pydantic import BaseModel
from src.schema import Comic
class ComicResponse(BaseModel):
id: UUID
title: str
completed: bool
class ComicDetailsResponse(BaseModel):
id: UUID
title: str
completed : bool
current_order : bool
publisher: str
volumes: List[str]
works: Dict[str, List[str]]
def get_comic_details(comic: Comic) -> ComicDetailsResponse | None:
volumes = []
for volume in comic.volumes:
volumes.append(volume.name)
works = {}
for work in comic.comic_works:
work_type = work.work_type.name
artist_name = work.artist.name
if work_type in works:
works[work_type].append(artist_name)
else:
works[work_type] = [artist_name]
response = ComicDetailsResponse(
id=comic.id,
title=comic.title,
completed=(comic.completed == 1),
current_order=(comic.current_order == 1),
publisher=comic.publisher.name,
volumes=volumes,
works=works
)
return response