This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user