Vorbereitung Release 0.2.0 #83
@@ -2,6 +2,7 @@ from typing import List, AnyStr
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from src.apis.utils import SessionDep
|
||||
from src.core.log_conf import logger
|
||||
from src.db.repository.comics.artist import get_artist_details
|
||||
from src.db.repository.comics.comic import list_comics, get_issue_details
|
||||
from src.schema.comics.comic import ComicResponse, ComicDetailsResponse, get_comic_details, get_short_info
|
||||
@@ -26,7 +27,9 @@ def get_comic(comic_id: AnyStr, db: SessionDep) -> ComicDetailsResponse:
|
||||
comic = db.get(Comic, comic_id)
|
||||
if comic is None:
|
||||
raise HTTPException(status_code=404, detail="Comic could not be found")
|
||||
logger.info(f"create ComicDetailsResponse for {comic}")
|
||||
response: ComicDetailsResponse = get_comic_details(comic)
|
||||
logger.info(f"ComicDetailsResponse: {response}")
|
||||
return response
|
||||
|
||||
@router.get("/artists", response_model=List[ArtistResponse])
|
||||
@@ -34,7 +37,7 @@ def get_all_artists(db: SessionDep) -> List[ArtistResponse]:
|
||||
results: List[ArtistResponse] = []
|
||||
artists = db.query(Artist).all()
|
||||
for artist in artists:
|
||||
results.append(ArtistResponse(id=artist.id, name=artist.name))
|
||||
results.append(ArtistResponse(id=artist.id, name=str(artist.name)))
|
||||
return results
|
||||
|
||||
@router.get("/artists/{artist_id}", response_model=ArtistDetailResponse)
|
||||
|
||||
@@ -107,10 +107,10 @@ class Issue(Base, BaseMixin):
|
||||
story_arc = relationship("StoryArc", back_populates="issues")
|
||||
issue_works = relationship("IssueWork")
|
||||
|
||||
def get_full_title(self) -> AnyStr:
|
||||
full_title: AnyStr = self.issue_number
|
||||
def get_full_title(self) -> str:
|
||||
full_title: str = str(self.issue_number)
|
||||
if self.title:
|
||||
full_title += ": " + self.title
|
||||
full_title += str(": " + self.title)
|
||||
return full_title
|
||||
|
||||
def get_artists(self) -> Dict[Any, List[Any]]:
|
||||
@@ -186,4 +186,3 @@ class IssueWork(Base, BaseMixin):
|
||||
artist = relationship("Artist", back_populates="issue_works")
|
||||
work_type_id = Column(String, ForeignKey("worktype.id"), nullable=False)
|
||||
work_type = relationship("WorkType", back_populates="issue_works")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from src.schema.comics.comic import ComicSchema
|
||||
from src.schema.comics.issue import IssueDetailsResponse
|
||||
|
||||
|
||||
def list_comics(db: Session) -> List[Type[Comic]]:
|
||||
def list_comics(db: Session) -> List[Comic]:
|
||||
comics = db.query(Comic).all()
|
||||
return comics
|
||||
|
||||
@@ -16,16 +16,16 @@ def list_comics(db: Session) -> List[Type[Comic]]:
|
||||
def get_issue_details(issue: Issue) -> IssueDetailsResponse:
|
||||
response = IssueDetailsResponse(
|
||||
id=issue.id,
|
||||
issue_number=issue.issue_number,
|
||||
in_stock=issue.in_stock,
|
||||
is_read=issue.is_read,
|
||||
comic_id=issue.comic_id,
|
||||
volume_id=issue.volume_id
|
||||
issue_number=str(issue.issue_number),
|
||||
in_stock=bool(issue.in_stock),
|
||||
is_read=bool(issue.is_read),
|
||||
comic_id=str(issue.comic_id),
|
||||
volume_id=str(issue.volume_id)
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def update_comic(comic: ComicSchema, comic_id: AnyStr, db: Session) -> type[Comic] | None:
|
||||
logger.info(f"update_comic: {comic} with {comic_id}")
|
||||
comic = db.get(Comic, comic_id)
|
||||
return comic
|
||||
comic = db.get(Comic, comic_id) # type: ignore
|
||||
return comic # type: ignore
|
||||
|
||||
@@ -2,7 +2,11 @@ from typing import List, Dict, 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):
|
||||
@@ -10,6 +14,13 @@ class ComicResponse(BaseModel):
|
||||
title: str
|
||||
completed: bool
|
||||
|
||||
|
||||
|
||||
class ComicWorktypeArtistResponse(BaseModel):
|
||||
worktype: WorktypeResponse
|
||||
artists: List[ArtistResponse]
|
||||
|
||||
|
||||
class ComicDetailsResponse(BaseModel):
|
||||
id: str
|
||||
created: str
|
||||
@@ -18,9 +29,9 @@ class ComicDetailsResponse(BaseModel):
|
||||
current_order : bool
|
||||
weblink: str
|
||||
publisher: str
|
||||
volumes: List[str]
|
||||
works: Dict[str, List[str]]
|
||||
|
||||
volumes: List[VolumeResponse]
|
||||
works: List[ComicWorktypeArtistResponse]
|
||||
|
||||
|
||||
class ComicSchema(BaseModel):
|
||||
id: str
|
||||
@@ -33,31 +44,39 @@ class ComicSchema(BaseModel):
|
||||
def get_short_info(comic: Comic) -> ComicResponse:
|
||||
response = ComicResponse(
|
||||
id=comic.id,
|
||||
title=comic.title,
|
||||
completed=(comic.completed == 1)
|
||||
title=str(comic.title),
|
||||
completed=bool(comic.completed == 1)
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def get_comic_details(comic: Comic) -> ComicDetailsResponse | None:
|
||||
volumes = []
|
||||
def get_comic_details(comic: Comic) -> ComicDetailsResponse:
|
||||
volumes: List[VolumeResponse] = []
|
||||
for volume in comic.volumes:
|
||||
volumes.append(volume.name)
|
||||
works = {}
|
||||
volumes.append(VolumeResponse(id=volume.id, name=volume.name))
|
||||
works: List[ComicWorktypeArtistResponse] = []
|
||||
works_map: Dict[str, ComicWorktypeArtistResponse] = {}
|
||||
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)
|
||||
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[work_type] = [artist_name]
|
||||
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=comic.title,
|
||||
completed=comic.completed,
|
||||
current_order=comic.current_order,
|
||||
weblink=comic.weblink,
|
||||
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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class VolumeResponse(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
@@ -2,3 +2,8 @@ from pydantic import BaseModel
|
||||
|
||||
class AddWorkType(BaseModel):
|
||||
worktype: str
|
||||
|
||||
class WorktypeResponse(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
|
||||
|
||||
Reference in New Issue
Block a user