import sources from develop/0.1.0
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from typing import List, Dict
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.db.models.comic 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
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
from typing import List, Dict
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.db.models.comic import Comic
|
||||
|
||||
|
||||
class ComicResponse(BaseModel):
|
||||
id: UUID
|
||||
title: str
|
||||
completed: bool
|
||||
|
||||
class ComicDetailsResponse(BaseModel):
|
||||
id: UUID
|
||||
created: str
|
||||
title: str
|
||||
completed : bool
|
||||
current_order : bool
|
||||
publisher: str
|
||||
volumes: List[str]
|
||||
works: Dict[str, List[str]]
|
||||
|
||||
def get_short_info(comic: Comic) -> ComicResponse:
|
||||
response = ComicResponse(
|
||||
id=comic.id,
|
||||
title=comic.title,
|
||||
completed=(comic.completed == 1)
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
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,
|
||||
created=str(comic.created_date),
|
||||
title=comic.title,
|
||||
completed=(comic.completed == 1),
|
||||
current_order=(comic.current_order == 1),
|
||||
publisher=comic.publisher.name,
|
||||
volumes=volumes,
|
||||
works=works
|
||||
)
|
||||
return response
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from src.db.models.media import MediaFile
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class MediaFileResponse(BaseModel):
|
||||
id: UUID
|
||||
title: str | None = None
|
||||
file_name: str | None = None
|
||||
cloud_link: str | None = None
|
||||
url: str
|
||||
review: bool = False
|
||||
should_download: bool = False
|
||||
|
||||
class Link(BaseModel):
|
||||
url: str
|
||||
|
||||
def get_file_details(mediafile: MediaFile) -> MediaFileResponse | None:
|
||||
response = MediaFileResponse(id=mediafile.id,
|
||||
title=mediafile.title,
|
||||
file_name=mediafile.file_name,
|
||||
cloud_link=mediafile.cloud_link,
|
||||
url=str(mediafile.url),
|
||||
review=(mediafile.review == 1),
|
||||
should_download=(mediafile.should_download == 1))
|
||||
#print(f"id: {mediafile.id}: review: {response.review} <- {mediafile.review}")
|
||||
#print(f"id: {mediafile.id}: download: {response.should_download} <- {mediafile.should_download}")
|
||||
return response
|
||||
|
||||
def set_file(model: MediaFileResponse, mediafile: MediaFile) -> None:
|
||||
mediafile.file_name = model.file_name
|
||||
mediafile.cloud_link = model.cloud_link
|
||||
mediafile.url = model.url
|
||||
mediafile.title = model.title
|
||||
mediafile.last_modified_date = datetime.now()
|
||||
if model.review:
|
||||
mediafile.review = 1
|
||||
else:
|
||||
mediafile.review = 0
|
||||
if model.should_download:
|
||||
mediafile.should_download = 1
|
||||
else:
|
||||
mediafile.should_download = 0
|
||||
@@ -0,0 +1,8 @@
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SportResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
Reference in New Issue
Block a user