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")
|
||||
|
||||
@@ -6,7 +6,7 @@ from src.db.models.base import Base, BaseMixin
|
||||
|
||||
class MetaDataTable(Base, BaseMixin):
|
||||
__tablename__ = 'meta_data_table'
|
||||
table_name = Column(String(255), unique=True)
|
||||
table_name = Column(String, unique=True)
|
||||
table_columns = relationship("MetaDataColumn")
|
||||
|
||||
def __repr__(self):
|
||||
@@ -18,15 +18,15 @@ class MetaDataTable(Base, BaseMixin):
|
||||
|
||||
class MetaDataColumn(Base, BaseMixin):
|
||||
__tablename__ = 'meta_data_column'
|
||||
column_name = Column(String(255), nullable=False)
|
||||
column_sync_name = Column(String(255))
|
||||
column_type = Column(String(255))
|
||||
column_modifier = Column(String(255), nullable=True)
|
||||
column_name = Column(String, nullable=False)
|
||||
column_sync_name = Column(String)
|
||||
column_type = Column(String)
|
||||
column_modifier = Column(String, nullable=True)
|
||||
column_order = Column(Integer)
|
||||
table_id = Column(String, ForeignKey('meta_data_table.id'))
|
||||
table = relationship("MetaDataTable", back_populates="table_columns")
|
||||
column_label = Column(String(255))
|
||||
filter_label = Column(String(255))
|
||||
column_label = Column(String)
|
||||
filter_label = Column(String)
|
||||
is_shown = Column(Boolean)
|
||||
show_filter = Column(Boolean)
|
||||
ref_column = Column(String, nullable=True)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from typing import List, Type
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.db.models.comic import Artist, Comic
|
||||
from src.schema.comics.artist import ArtistDetailResponse
|
||||
|
||||
|
||||
def get_artist_details(artist: Artist) -> ArtistDetailResponse:
|
||||
works = {}
|
||||
for work in artist.comic_works:
|
||||
work_type = work.work_type.name
|
||||
comic_title = work.comic.title
|
||||
if work_type in works:
|
||||
works[work_type].append(comic_title)
|
||||
else:
|
||||
works[work_type] = [comic_title]
|
||||
response = ArtistDetailResponse(
|
||||
id=artist.id,
|
||||
name=artist.name,
|
||||
works=works
|
||||
)
|
||||
return response
|
||||
|
||||
def list_comics(db: Session) -> List[Type[Comic]]:
|
||||
comics = db.query(Comic).all()
|
||||
return comics
|
||||
Reference in New Issue
Block a user