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
|
||||
|
||||
Reference in New Issue
Block a user