fix(nodes): handle intermediates during images.get_many()

This commit is contained in:
psychedelicious 2023-05-27 09:17:06 +10:00 committed by Kent Keirsey
parent 33a0af4637
commit ee0225f4ba
3 changed files with 12 additions and 4 deletions

View File

@ -230,6 +230,9 @@ async def get_image_urls(
async def list_images_with_metadata(
image_type: ImageType = Query(description="The type of images to list"),
image_category: ImageCategory = Query(description="The kind of images to list"),
is_intermediate: bool = Query(
default=False, description="The kind of images to list"
),
page: int = Query(default=0, description="The page of image metadata to get"),
per_page: int = Query(
default=10, description="The number of image metadata per page"
@ -240,6 +243,7 @@ async def list_images_with_metadata(
image_dtos = ApiDependencies.invoker.services.images.get_many(
image_type,
image_category,
is_intermediate,
page,
per_page,
)

View File

@ -65,6 +65,7 @@ class ImageRecordStorageBase(ABC):
self,
image_type: ImageType,
image_category: ImageCategory,
is_intermediate: bool = False,
page: int = 0,
per_page: int = 10,
) -> PaginatedResults[ImageRecord]:
@ -245,6 +246,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
self,
image_type: ImageType,
image_category: ImageCategory,
is_intermediate: bool = False,
page: int = 0,
per_page: int = 10,
) -> PaginatedResults[ImageRecord]:
@ -254,11 +256,11 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
self._cursor.execute(
f"""--sql
SELECT * FROM images
WHERE image_type = ? AND image_category = ?
WHERE image_type = ? AND image_category = ? AND is_intermediate = ?
ORDER BY created_at DESC
LIMIT ? OFFSET ?;
""",
(image_type.value, image_category.value, per_page, page * per_page),
(image_type.value, image_category.value, is_intermediate, per_page, page * per_page),
)
result = cast(list[sqlite3.Row], self._cursor.fetchall())
@ -268,9 +270,9 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
self._cursor.execute(
"""--sql
SELECT count(*) FROM images
WHERE image_type = ? AND image_category = ?
WHERE image_type = ? AND image_category = ? AND is_intermediate = ?
""",
(image_type.value, image_category.value),
(image_type.value, image_category.value, is_intermediate),
)
count = self._cursor.fetchone()[0]

View File

@ -330,6 +330,7 @@ class ImageService(ImageServiceABC):
self,
image_type: ImageType,
image_category: ImageCategory,
is_intermediate: bool = False,
page: int = 0,
per_page: int = 10,
) -> PaginatedResults[ImageDTO]:
@ -337,6 +338,7 @@ class ImageService(ImageServiceABC):
results = self._services.records.get_many(
image_type,
image_category,
is_intermediate,
page,
per_page,
)