This commit is contained in:
@@ -5,7 +5,7 @@ from fastapi import APIRouter, HTTPException, status
|
||||
from src.db.models.comic import Artist
|
||||
from src.db.repository.comics.artist import get_artist_details
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.artist import ArtistCreation, ArtistResponse
|
||||
from src.schema.comics.artist import ArtistCreation, ArtistResponse, artist_to_response
|
||||
from src.schema.comics.artist_details import ArtistDetailResponse
|
||||
|
||||
|
||||
@@ -17,12 +17,22 @@ 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)))
|
||||
response = artist_to_response(artist)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/artists/{artist_id}", response_model=ArtistDetailResponse)
|
||||
def get_artist(artist_id: str, db: SessionDep) -> ArtistDetailResponse:
|
||||
@router.get("/artists/{artist_id}", response_model=ArtistResponse)
|
||||
def get_artist(artist_id: str, db: SessionDep) -> ArtistResponse:
|
||||
artist = db.get(Artist, artist_id)
|
||||
if artist is None:
|
||||
raise HTTPException(status_code=404, detail="Artist could not be found")
|
||||
response: ArtistResponse = artist_to_response(artist)
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/artists/details/{artist_id}", response_model=ArtistDetailResponse)
|
||||
def get_artist_details_by_id(artist_id: str, db: SessionDep) -> ArtistDetailResponse:
|
||||
artist = db.get(Artist, artist_id)
|
||||
if artist is None:
|
||||
raise HTTPException(status_code=404, detail="Artist could not be found")
|
||||
@@ -39,5 +49,5 @@ def add_artist(db: SessionDep, artist_creation: ArtistCreation) -> ArtistRespons
|
||||
db.commit()
|
||||
except:
|
||||
raise HTTPException(status_code=409, detail="Artist already added")
|
||||
response = ArtistResponse(id=artist.id, name=str(artist.name))
|
||||
response = artist_to_response(artist)
|
||||
return response
|
||||
|
||||
@@ -3,20 +3,13 @@ from typing import List
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.core.log_conf import logger
|
||||
from src.db.models.comic import Comic, Publisher
|
||||
from src.db.repository.comics.artist import get_artist_details
|
||||
from src.db.models.comic import Comic
|
||||
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.db.session import SessionDep
|
||||
from src.schema.comics.comic import ComicResponse
|
||||
from src.schema.comics.comic import ComicResponse, comic_to_response
|
||||
from src.schema.comics.comic_details import ComicDetailsResponse
|
||||
from src.schema.comics.publisher import PublisherResponse
|
||||
from src.schema.comics.publisher_details import PublisherDetailsResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -24,15 +17,24 @@ router = APIRouter()
|
||||
@router.get("/comics")
|
||||
def get_all_comics(db: SessionDep) -> List[ComicResponse]:
|
||||
results: List[ComicResponse] = []
|
||||
comics = list_comics(db)
|
||||
comics = db.query(Comic).all()
|
||||
for comic in comics:
|
||||
response = get_short_info(comic)
|
||||
response = comic_to_response(comic)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/comics/{comic_id}", response_model=ComicDetailsResponse)
|
||||
def get_comic(comic_id: str, db: SessionDep) -> ComicDetailsResponse:
|
||||
@router.get("/comics/{comic_id}", response_model=ComicResponse)
|
||||
def get_comic(comic_id: str, db: SessionDep) -> ComicResponse:
|
||||
comic = db.get(Comic, comic_id)
|
||||
if comic is None:
|
||||
raise HTTPException(status_code=404, detail="Comic could not be found")
|
||||
response: ComicResponse = comic_to_response(comic)
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/comics/details/{comic_id}", response_model=ComicDetailsResponse)
|
||||
def get_comic_details_by_id(comic_id: str, db: SessionDep) -> ComicDetailsResponse:
|
||||
comic = db.get(Comic, comic_id)
|
||||
if comic is None:
|
||||
raise HTTPException(status_code=404, detail="Comic could not be found")
|
||||
@@ -40,24 +42,3 @@ def get_comic(comic_id: str, db: SessionDep) -> ComicDetailsResponse:
|
||||
response: ComicDetailsResponse = get_comic_details(comic)
|
||||
logger.info(f"ComicDetailsResponse: {response}")
|
||||
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
|
||||
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import ComicWork
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.comicwork import ComicWorkResponse, to_response
|
||||
from src.schema.comics.comicwork import ComicWorkResponse, comicwork_to_response
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/comicworks", response_model=List[ComicWorkResponse])
|
||||
def get_comicworks(db: SessionDep) -> List[ComicWorkResponse]:
|
||||
results: List[ComicWorkResponse] = []
|
||||
worktypes = db.query(ComicWork).all()
|
||||
for worktype in worktypes:
|
||||
response = to_response(worktype)
|
||||
response = comicwork_to_response(worktype)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/comicworks/{comicwork_id}", response_model=ComicWorkResponse)
|
||||
def get_comicwork(comicwork_id: str, db: SessionDep) -> ComicWorkResponse:
|
||||
worktype = db.get(ComicWork, comicwork_id)
|
||||
if worktype is None:
|
||||
raise HTTPException(status_code=404, detail="Comicwork could not be found")
|
||||
response = comicwork_to_response(worktype)
|
||||
return response
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import Issue
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.issue import IssueResponse, to_response
|
||||
from src.schema.comics.issue import IssueResponse, issue_to_response
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@@ -14,6 +14,14 @@ def get_issues(db: SessionDep) -> List[IssueResponse]:
|
||||
results: List[IssueResponse] = []
|
||||
issues = db.query(Issue).all()
|
||||
for issue in issues:
|
||||
response = to_response(issue)
|
||||
response = issue_to_response(issue)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/issues/{issue_id}", response_model=IssueResponse)
|
||||
def get_issue(issue_id: str, db: SessionDep) -> IssueResponse:
|
||||
issue = db.get(Issue, issue_id)
|
||||
if issue is None:
|
||||
raise HTTPException(status_code=404, detail="Issue could not be found")
|
||||
response = issue_to_response(issue)
|
||||
return response
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import IssueWork
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.issuework import IssueWorkResponse, to_response
|
||||
from src.schema.comics.issuework import IssueWorkResponse, issuework_to_response
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/issueworks", response_model=List[IssueWorkResponse])
|
||||
def get_issueworks(db: SessionDep) -> List[IssueWorkResponse]:
|
||||
results: List[IssueWorkResponse] = []
|
||||
worktypes = db.query(IssueWork).all()
|
||||
for worktype in worktypes:
|
||||
response = to_response(worktype)
|
||||
response = issuework_to_response(worktype)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/issueworks/{issuework_id}", response_model=IssueWorkResponse)
|
||||
def get_issuework(issuework_id: str, db: SessionDep) -> IssueWorkResponse:
|
||||
worktype = db.get(IssueWork, issuework_id)
|
||||
if worktype is None:
|
||||
raise HTTPException(status_code=404, detail="Issuework could not be found")
|
||||
response = issuework_to_response(worktype)
|
||||
return response
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import Publisher
|
||||
from src.db.repository.comics.publisher import get_publisher_details
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.publisher import PublisherResponse, publisher_to_response
|
||||
from src.schema.comics.publisher_details import PublisherDetailsResponse
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@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:
|
||||
response: PublisherResponse = publisher_to_response(publisher)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/publishers/{publisher_id}", response_model=PublisherResponse)
|
||||
def get_publisher(publisher_id: str, db: SessionDep) -> PublisherResponse:
|
||||
publisher = db.get(Publisher, publisher_id)
|
||||
if publisher is None:
|
||||
raise HTTPException(status_code=404, detail="Publisher could not be found")
|
||||
response: PublisherResponse = publisher_to_response(publisher)
|
||||
return response
|
||||
|
||||
@router.get("/publishers/details/{publisher_id}", response_model=PublisherDetailsResponse)
|
||||
def get_publisher_details_by_id(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
|
||||
@@ -1,18 +1,26 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import StoryArc
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.storyarc import StoryArcResponse, to_response
|
||||
from src.schema.comics.storyarc import StoryArcResponse, storyarc_to_response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/storyarcs", response_model=List[StoryArcResponse])
|
||||
def get_issues(db: SessionDep) -> List[StoryArcResponse]:
|
||||
def get_storyarcs(db: SessionDep) -> List[StoryArcResponse]:
|
||||
results: List[StoryArcResponse] = []
|
||||
storyarcs = db.query(StoryArc).all()
|
||||
for storyarc in storyarcs:
|
||||
response = to_response(storyarc)
|
||||
response = storyarc_to_response(storyarc)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/storyarcs/{storyarc_id}", response_model=StoryArcResponse)
|
||||
def get_storyarc(story_arc_id: str, db: SessionDep) -> StoryArcResponse:
|
||||
storyarc = db.get(StoryArc, story_arc_id)
|
||||
if storyarc is None:
|
||||
raise HTTPException(status_code=404, detail="Storyarc could not be found")
|
||||
response = storyarc_to_response(storyarc)
|
||||
return response
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import Volume
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.volume import VolumeResponse, to_response
|
||||
from src.schema.comics.volume import VolumeResponse, volume_to_response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/volumes", response_model=List[VolumeResponse])
|
||||
def get_issues(db: SessionDep) -> List[VolumeResponse]:
|
||||
def volumes(db: SessionDep) -> List[VolumeResponse]:
|
||||
results: List[VolumeResponse] = []
|
||||
worktypes = db.query(Volume).all()
|
||||
for worktype in worktypes:
|
||||
response = to_response(worktype)
|
||||
response = volume_to_response(worktype)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/volumes/{volume_id}", response_model=VolumeResponse)
|
||||
def get_volume(volume_id: str, db: SessionDep) -> VolumeResponse:
|
||||
worktype = db.get(Volume, volume_id)
|
||||
if worktype is None:
|
||||
raise HTTPException(status_code=404, detail="Volume could not be found")
|
||||
response = volume_to_response(worktype)
|
||||
return response
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from src.db.models.comic import WorkType
|
||||
from src.db.session import SessionDep
|
||||
from src.schema.comics.worktype import WorktypeResponse, to_response
|
||||
from src.schema.comics.worktype import WorktypeResponse, worktype_to_response
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@@ -14,6 +14,14 @@ def get_issues(db: SessionDep) -> List[WorktypeResponse]:
|
||||
results: List[WorktypeResponse] = []
|
||||
worktypes = db.query(WorkType).all()
|
||||
for worktype in worktypes:
|
||||
response = to_response(worktype)
|
||||
response = worktype_to_response(worktype)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/worktypes/{worktype_id}", response_model=WorktypeResponse)
|
||||
def get_issue(worktype_id: str, db: SessionDep) -> WorktypeResponse:
|
||||
worktype = db.get(WorkType, worktype_id)
|
||||
if worktype is None:
|
||||
raise HTTPException(status_code=404, detail="Worktype could not be found")
|
||||
response = worktype_to_response(worktype)
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user