mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(api): add archived query param to board list endpoint to include them in the response
This commit is contained in:
parent
c33111468e
commit
38a948ac9f
@ -119,14 +119,16 @@ async def list_boards(
|
|||||||
all: Optional[bool] = Query(default=None, description="Whether to list all boards"),
|
all: Optional[bool] = Query(default=None, description="Whether to list all boards"),
|
||||||
offset: Optional[int] = Query(default=None, description="The page offset"),
|
offset: Optional[int] = Query(default=None, description="The page offset"),
|
||||||
limit: Optional[int] = Query(default=None, description="The number of boards per page"),
|
limit: Optional[int] = Query(default=None, description="The number of boards per page"),
|
||||||
|
archived: bool = Query(default=False, description="Whether or not to include archived boards in list"),
|
||||||
) -> Union[OffsetPaginatedResults[BoardDTO], list[BoardDTO]]:
|
) -> Union[OffsetPaginatedResults[BoardDTO], list[BoardDTO]]:
|
||||||
"""Gets a list of boards"""
|
"""Gets a list of boards"""
|
||||||
if all:
|
if all:
|
||||||
return ApiDependencies.invoker.services.boards.get_all()
|
return ApiDependencies.invoker.services.boards.get_all(archived)
|
||||||
elif offset is not None and limit is not None:
|
elif offset is not None and limit is not None:
|
||||||
return ApiDependencies.invoker.services.boards.get_many(
|
return ApiDependencies.invoker.services.boards.get_many(
|
||||||
offset,
|
offset,
|
||||||
limit,
|
limit,
|
||||||
|
archived
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -43,6 +43,7 @@ class BoardRecordStorageBase(ABC):
|
|||||||
self,
|
self,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
|
archived: bool = False
|
||||||
) -> OffsetPaginatedResults[BoardRecord]:
|
) -> OffsetPaginatedResults[BoardRecord]:
|
||||||
"""Gets many board records."""
|
"""Gets many board records."""
|
||||||
pass
|
pass
|
||||||
@ -50,6 +51,7 @@ class BoardRecordStorageBase(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_all(
|
def get_all(
|
||||||
self,
|
self,
|
||||||
|
archived: bool = False
|
||||||
) -> list[BoardRecord]:
|
) -> list[BoardRecord]:
|
||||||
"""Gets all board records."""
|
"""Gets all board records."""
|
||||||
pass
|
pass
|
||||||
|
@ -148,33 +148,50 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase):
|
|||||||
def get_many(
|
def get_many(
|
||||||
self,
|
self,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
limit: int = 10
|
limit: int = 10,
|
||||||
|
archived: bool = False
|
||||||
) -> OffsetPaginatedResults[BoardRecord]:
|
) -> OffsetPaginatedResults[BoardRecord]:
|
||||||
try:
|
try:
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
|
|
||||||
# Get all the boards
|
# Build base query
|
||||||
self._cursor.execute(
|
base_query = """
|
||||||
"""--sql
|
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM boards
|
FROM boards
|
||||||
|
{archived_filter}
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT ? OFFSET ?;
|
LIMIT ? OFFSET ?;
|
||||||
""",
|
"""
|
||||||
(limit, offset),
|
|
||||||
)
|
# Determine archived filter condition
|
||||||
|
if archived:
|
||||||
|
archived_filter = ""
|
||||||
|
else:
|
||||||
|
archived_filter = "WHERE archived = 0"
|
||||||
|
|
||||||
|
final_query = base_query.format(archived_filter=archived_filter)
|
||||||
|
|
||||||
|
# Execute query to fetch boards
|
||||||
|
self._cursor.execute(final_query, (limit, offset))
|
||||||
|
|
||||||
result = cast(list[sqlite3.Row], self._cursor.fetchall())
|
result = cast(list[sqlite3.Row], self._cursor.fetchall())
|
||||||
boards = [deserialize_board_record(dict(r)) for r in result]
|
boards = [deserialize_board_record(dict(r)) for r in result]
|
||||||
|
|
||||||
# Get the total number of boards
|
# Determine count query
|
||||||
self._cursor.execute(
|
if archived:
|
||||||
"""--sql
|
count_query = """
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM boards;
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
count_query = """
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM boards
|
FROM boards
|
||||||
WHERE 1=1;
|
WHERE archived = 0;
|
||||||
"""
|
"""
|
||||||
)
|
|
||||||
|
# Execute count query
|
||||||
|
self._cursor.execute(count_query)
|
||||||
|
|
||||||
count = cast(int, self._cursor.fetchone()[0])
|
count = cast(int, self._cursor.fetchone()[0])
|
||||||
|
|
||||||
@ -188,18 +205,26 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase):
|
|||||||
|
|
||||||
def get_all(
|
def get_all(
|
||||||
self,
|
self,
|
||||||
|
archived: bool = False
|
||||||
) -> list[BoardRecord]:
|
) -> list[BoardRecord]:
|
||||||
try:
|
try:
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
|
|
||||||
# Get all the boards
|
base_query = """
|
||||||
self._cursor.execute(
|
|
||||||
"""--sql
|
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM boards
|
FROM boards
|
||||||
|
{archived_filter}
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
"""
|
"""
|
||||||
)
|
|
||||||
|
if archived:
|
||||||
|
archived_filter = ""
|
||||||
|
else:
|
||||||
|
archived_filter = "WHERE archived = 0"
|
||||||
|
|
||||||
|
final_query = base_query.format(archived_filter=archived_filter)
|
||||||
|
|
||||||
|
self._cursor.execute(final_query)
|
||||||
|
|
||||||
result = cast(list[sqlite3.Row], self._cursor.fetchall())
|
result = cast(list[sqlite3.Row], self._cursor.fetchall())
|
||||||
boards = [deserialize_board_record(dict(r)) for r in result]
|
boards = [deserialize_board_record(dict(r)) for r in result]
|
||||||
|
@ -47,6 +47,7 @@ class BoardServiceABC(ABC):
|
|||||||
self,
|
self,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
|
archived: bool = False
|
||||||
) -> OffsetPaginatedResults[BoardDTO]:
|
) -> OffsetPaginatedResults[BoardDTO]:
|
||||||
"""Gets many boards."""
|
"""Gets many boards."""
|
||||||
pass
|
pass
|
||||||
@ -54,6 +55,7 @@ class BoardServiceABC(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_all(
|
def get_all(
|
||||||
self,
|
self,
|
||||||
|
archived: bool = False
|
||||||
) -> list[BoardDTO]:
|
) -> list[BoardDTO]:
|
||||||
"""Gets all boards."""
|
"""Gets all boards."""
|
||||||
pass
|
pass
|
||||||
|
@ -48,8 +48,8 @@ class BoardService(BoardServiceABC):
|
|||||||
def delete(self, board_id: str) -> None:
|
def delete(self, board_id: str) -> None:
|
||||||
self.__invoker.services.board_records.delete(board_id)
|
self.__invoker.services.board_records.delete(board_id)
|
||||||
|
|
||||||
def get_many(self, offset: int = 0, limit: int = 10) -> OffsetPaginatedResults[BoardDTO]:
|
def get_many(self, offset: int = 0, limit: int = 10, archived: bool = False) -> OffsetPaginatedResults[BoardDTO]:
|
||||||
board_records = self.__invoker.services.board_records.get_many(offset, limit)
|
board_records = self.__invoker.services.board_records.get_many(offset, limit, archived)
|
||||||
board_dtos = []
|
board_dtos = []
|
||||||
for r in board_records.items:
|
for r in board_records.items:
|
||||||
cover_image = self.__invoker.services.image_records.get_most_recent_image_for_board(r.board_id)
|
cover_image = self.__invoker.services.image_records.get_most_recent_image_for_board(r.board_id)
|
||||||
@ -63,8 +63,8 @@ class BoardService(BoardServiceABC):
|
|||||||
|
|
||||||
return OffsetPaginatedResults[BoardDTO](items=board_dtos, offset=offset, limit=limit, total=len(board_dtos))
|
return OffsetPaginatedResults[BoardDTO](items=board_dtos, offset=offset, limit=limit, total=len(board_dtos))
|
||||||
|
|
||||||
def get_all(self) -> list[BoardDTO]:
|
def get_all(self, archived: bool = False) -> list[BoardDTO]:
|
||||||
board_records = self.__invoker.services.board_records.get_all()
|
board_records = self.__invoker.services.board_records.get_all(archived)
|
||||||
board_dtos = []
|
board_dtos = []
|
||||||
for r in board_records:
|
for r in board_records:
|
||||||
cover_image = self.__invoker.services.image_records.get_most_recent_image_for_board(r.board_id)
|
cover_image = self.__invoker.services.image_records.get_most_recent_image_for_board(r.board_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user