add testing to fastapi
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from typing import List, Dict
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.schema import Artist
|
||||
|
||||
|
||||
class ArtistCreation(BaseModel):
|
||||
name: str
|
||||
|
||||
class ArtistResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
|
||||
class ArtistDetailResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
works: Dict[str, List[str]]
|
||||
|
||||
def get_artist_details(artist: Artist) -> ArtistDetailResponse:
|
||||
works = {}
|
||||
for work in artist.comic_works:
|
||||
work_type = work.work_type.name
|
||||
comic_title = work.comic.title
|
||||
if work_type in works:
|
||||
works[work_type].append(comic_title)
|
||||
else:
|
||||
works[work_type] = [comic_title]
|
||||
response = ArtistDetailResponse(
|
||||
id=artist.id,
|
||||
name=artist.name,
|
||||
works=works
|
||||
)
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user