WIP: add HTML form for editing comics
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List, Type, AnyStr
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.log_conf import logger
|
||||
from src.db.models.comic import Artist, Comic, Issue, WorkType
|
||||
from src.schema.comics.artist import ArtistDetailResponse
|
||||
from src.schema.comics.issue import IssueDetailsResponse
|
||||
from src.schema.comics.worktype import AddWorkType
|
||||
|
||||
|
||||
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
|
||||
|
||||
def list_comics(db: Session) -> List[Type[Comic]]:
|
||||
comics = db.query(Comic).all()
|
||||
return comics
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
return response
|
||||
|
||||
def create_new_worktype(work: AddWorkType, db: Session) -> WorkType:
|
||||
worktype = WorkType()
|
||||
worktype.id = str(uuid.uuid4())
|
||||
worktype.created_date = datetime.now()
|
||||
worktype.last_modified_date = datetime.now()
|
||||
worktype.name = work.worktype
|
||||
db.add(worktype)
|
||||
db.commit()
|
||||
db.refresh(worktype)
|
||||
logger.info(f"create_new_worktype: {worktype}")
|
||||
return worktype
|
||||
|
||||
|
||||
def update_worktype(work: AddWorkType, worktype_id: AnyStr, db: Session) -> WorkType:
|
||||
logger.info("update worktype")
|
||||
worktype = db.get(WorkType, worktype_id)
|
||||
worktype.name = work.worktype
|
||||
db.add(worktype)
|
||||
db.commit()
|
||||
db.refresh(worktype)
|
||||
return worktype
|
||||
@@ -0,0 +1,19 @@
|
||||
from src.db.models.comic import Artist
|
||||
from src.schema.comics.artist import ArtistDetailResponse
|
||||
|
||||
|
||||
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,29 @@
|
||||
from typing import List, Type, AnyStr
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.log_conf import logger
|
||||
from src.db.models.comic import Comic, Issue
|
||||
from src.schema.comics.comic import ComicSchema
|
||||
from src.schema.comics.issue import IssueDetailsResponse
|
||||
|
||||
|
||||
def list_comics(db: Session) -> List[Type[Comic]]:
|
||||
comics = db.query(Comic).all()
|
||||
return comics
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def update_comic(comic: ComicSchema, comic_id: AnyStr, db: Session):
|
||||
logger.info(f"update_comic: {comic} with {comic_id}")
|
||||
@@ -0,0 +1,32 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import AnyStr
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.log_conf import logger
|
||||
from src.db.models.comic import WorkType
|
||||
from src.schema.comics.worktype import AddWorkType
|
||||
|
||||
|
||||
def create_new_worktype(work: AddWorkType, db: Session) -> WorkType:
|
||||
worktype = WorkType()
|
||||
worktype.id = str(uuid.uuid4())
|
||||
worktype.created_date = datetime.now()
|
||||
worktype.last_modified_date = datetime.now()
|
||||
worktype.name = work.worktype
|
||||
db.add(worktype)
|
||||
db.commit()
|
||||
db.refresh(worktype)
|
||||
logger.info(f"create_new_worktype: {worktype}")
|
||||
return worktype
|
||||
|
||||
|
||||
def update_worktype(work: AddWorkType, worktype_id: AnyStr, db: Session) -> WorkType:
|
||||
logger.info("update worktype")
|
||||
worktype = db.get(WorkType, worktype_id)
|
||||
worktype.name = work.worktype
|
||||
db.add(worktype)
|
||||
db.commit()
|
||||
db.refresh(worktype)
|
||||
return worktype
|
||||
Reference in New Issue
Block a user