Extend display of comics publishers
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from src.apis.utils import SessionDep
|
||||
from src.core.log_conf import logger
|
||||
from src.db.models.comic import Artist, Comic, Issue, Publisher
|
||||
from src.db.repository.comics.artist import get_artist_details
|
||||
from src.db.repository.comics.comic import get_comic_details, get_short_info, list_comics, get_issue_details
|
||||
from src.schema.comics.artist_details import ArtistDetailResponse
|
||||
from src.schema.comics.comic import ComicResponse
|
||||
from src.db.repository.comics.comic import (
|
||||
get_comic_details,
|
||||
get_issue_details,
|
||||
get_short_info,
|
||||
list_comics,
|
||||
)
|
||||
from src.db.repository.comics.publisher import get_publisher_details
|
||||
from src.schema.comics.artist import ArtistCreation, ArtistResponse
|
||||
from src.db.models.comic import Comic, Artist, Issue
|
||||
from src.schema.comics.artist_details import ArtistDetailResponse
|
||||
from src.schema.comics.comic import ComicResponse
|
||||
from src.schema.comics.comic_details import ComicDetailsResponse
|
||||
from src.schema.comics.issue_details import IssueDetailsResponse
|
||||
from src.schema.comics.publisher import PublisherResponse
|
||||
from src.schema.comics.publisher_details import PublisherDetailsResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -24,6 +33,7 @@ def get_all_comics(db: SessionDep) -> List[ComicResponse]:
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/comics/{comic_id}", response_model=ComicDetailsResponse)
|
||||
def get_comic(comic_id: str, db: SessionDep) -> ComicDetailsResponse:
|
||||
comic = db.get(Comic, comic_id)
|
||||
@@ -34,14 +44,16 @@ def get_comic(comic_id: str, db: SessionDep) -> ComicDetailsResponse:
|
||||
logger.info(f"ComicDetailsResponse: {response}")
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/artists", response_model=List[ArtistResponse])
|
||||
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=str(artist.name)))
|
||||
results.append(ArtistResponse(id=artist.id, name=str(artist.name))) # type: ignore
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/artists/{artist_id}", response_model=ArtistDetailResponse)
|
||||
def get_artist(artist_id: str, db: SessionDep) -> ArtistDetailResponse:
|
||||
artist = db.get(Artist, artist_id)
|
||||
@@ -50,6 +62,7 @@ def get_artist(artist_id: str, db: SessionDep) -> ArtistDetailResponse:
|
||||
response: ArtistDetailResponse = get_artist_details(artist)
|
||||
return response
|
||||
|
||||
|
||||
@router.post("/artists", status_code=status.HTTP_201_CREATED)
|
||||
def add_artist(db: SessionDep, artist_creation: ArtistCreation) -> ArtistResponse:
|
||||
artist: Artist = Artist()
|
||||
@@ -62,6 +75,25 @@ def add_artist(db: SessionDep, artist_creation: ArtistCreation) -> ArtistRespons
|
||||
response = ArtistResponse(id=artist.id, name=str(artist.name))
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/publishers", response_model=List[PublisherResponse])
|
||||
def get_all_publishers(db: SessionDep) -> List[PublisherResponse]:
|
||||
results: List[PublisherResponse] = []
|
||||
publishers = db.query(Publisher).all()
|
||||
for publisher in publishers:
|
||||
results.append(PublisherResponse(id=publisher.id, name=str(publisher.name)))
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/publishers/{publisher_id}", response_model=PublisherDetailsResponse)
|
||||
def get_publisher(publisher_id: str, db: SessionDep) -> PublisherDetailsResponse:
|
||||
publisher = db.get(Publisher, publisher_id)
|
||||
if publisher is None:
|
||||
raise HTTPException(status_code=404, detail="Publisher could not be found")
|
||||
response: PublisherDetailsResponse = get_publisher_details(publisher)
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/issues", response_model=List[IssueDetailsResponse])
|
||||
def get_issues(db: SessionDep) -> List[IssueDetailsResponse]:
|
||||
results: List[IssueDetailsResponse] = []
|
||||
|
||||
Reference in New Issue
Block a user