from typing import List

from fastapi import APIRouter

from src.db.models.bookshelf import BookAuthor
from src.db.session import SessionDep
from src.schema.bookshelf.bookauthor import BookAuthorResponse, to_response

router = APIRouter()


@router.get("/bookauthors", response_model=List[BookAuthorResponse])
def get_all_artists(db: SessionDep) -> List[BookAuthorResponse]:
    results: List[BookAuthorResponse] = []
    bookauthors = db.query(BookAuthor).all()
    for bookauthor in bookauthors:
        response = to_response(bookauthor)
        results.append(response)
    return results
