update models to use string type for id fields
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
from uuid import UUID
|
||||
from typing import List
|
||||
from typing import List, AnyStr
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from sqlalchemy import select
|
||||
|
||||
from src.apis.utils import SessionDep
|
||||
from src.db.repository.comic import get_artist_details, list_comics
|
||||
from src.schema.comics.comic import ComicResponse, ComicDetailsResponse, get_comic_details, get_short_info
|
||||
from src.schema.comics.artist import ArtistCreation, ArtistDetailResponse, ArtistResponse, get_artist_details
|
||||
from src.schema.comics.artist import ArtistCreation, ArtistDetailResponse, ArtistResponse
|
||||
from src.db.models.comic import Comic, Artist
|
||||
|
||||
router = APIRouter(
|
||||
@@ -18,14 +17,14 @@ router = APIRouter(
|
||||
@router.get("/comics")
|
||||
def get_all_comics(db: SessionDep) -> List[ComicResponse]:
|
||||
results: List[ComicResponse] = []
|
||||
comics = db.scalars(select(Comic)).all()
|
||||
comics = list_comics(db)
|
||||
for comic in comics:
|
||||
response = get_short_info(comic)
|
||||
results.append(response)
|
||||
return results
|
||||
|
||||
@router.get("/comics/{comic_id}", response_model=ComicDetailsResponse)
|
||||
def get_comic(comic_id: UUID, db: SessionDep) -> ComicDetailsResponse:
|
||||
def get_comic(comic_id: AnyStr, db: SessionDep) -> ComicDetailsResponse:
|
||||
comic = db.get(Comic, comic_id)
|
||||
if comic is None:
|
||||
raise HTTPException(status_code=404, detail="Comic could not be found")
|
||||
@@ -41,7 +40,7 @@ def get_all_artists(db: SessionDep) -> List[ArtistResponse]:
|
||||
return results
|
||||
|
||||
@router.get("/artists/{artist_id}", response_model=ArtistDetailResponse)
|
||||
def get_artist(artist_id: UUID, db: SessionDep) -> ArtistDetailResponse:
|
||||
def get_artist(artist_id: AnyStr, db: SessionDep) -> ArtistDetailResponse:
|
||||
artist = db.get(Artist, artist_id)
|
||||
if artist is None:
|
||||
raise HTTPException(status_code=404, detail="Artist could not be found")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import List, AnyStr
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, status, HTTPException
|
||||
@@ -42,7 +42,7 @@ def get_all_files(db: SessionDep, review: bool = False, download: bool = False)
|
||||
return results
|
||||
|
||||
@router.get("/files/{file_id}", response_model=MediaFileResponse)
|
||||
def get_file(file_id: UUID, db: SessionDep) -> MediaFileResponse:
|
||||
def get_file(file_id: AnyStr, db: SessionDep) -> MediaFileResponse:
|
||||
mediafile = db.get(MediaFile, file_id)
|
||||
if not mediafile:
|
||||
raise HTTPException(status_code=404, detail="MediaFile could not be found")
|
||||
@@ -50,7 +50,7 @@ def get_file(file_id: UUID, db: SessionDep) -> MediaFileResponse:
|
||||
return response
|
||||
|
||||
@router.put("/files/{file_id}", response_model=MediaFileResponse)
|
||||
def update_file(file_id: UUID, db: SessionDep, info: MediaFileResponse) -> MediaFileResponse:
|
||||
def update_file(file_id: AnyStr, db: SessionDep, info: MediaFileResponse) -> MediaFileResponse:
|
||||
mediaFile = db.get(MediaFile, file_id)
|
||||
if not mediaFile:
|
||||
raise HTTPException(status_code=404, detail="MediaFile could not be found")
|
||||
|
||||
Reference in New Issue
Block a user