27 lines
977 B
Python
27 lines
977 B
Python
from typing import List
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from kontor_model.db.models.comic import StoryArc
|
|
from src.db.session import SessionDep
|
|
from kontor_model.schema.comics.storyarc import StoryArcResponse, storyarc_to_response
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/storyarcs", response_model=List[StoryArcResponse])
|
|
def get_storyarcs(db: SessionDep) -> List[StoryArcResponse]:
|
|
results: List[StoryArcResponse] = []
|
|
storyarcs = db.query(StoryArc).all()
|
|
for storyarc in storyarcs:
|
|
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
|