mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(api): update API models to use BoardDTOs
This commit is contained in:
parent
4b32322a58
commit
dd1b3c9f35
@ -1,6 +1,6 @@
|
|||||||
from fastapi import Body, HTTPException, Path, Query
|
from fastapi import Body, HTTPException, Path, Query
|
||||||
from fastapi.routing import APIRouter
|
from fastapi.routing import APIRouter
|
||||||
from invokeai.app.services.board_record_storage import BoardRecord, BoardChanges
|
from invokeai.app.services.board_record_storage import BoardChanges
|
||||||
from invokeai.app.services.image_record_storage import OffsetPaginatedResults
|
from invokeai.app.services.image_record_storage import OffsetPaginatedResults
|
||||||
from invokeai.app.services.models.board_record import BoardDTO
|
from invokeai.app.services.models.board_record import BoardDTO
|
||||||
|
|
||||||
@ -16,32 +16,39 @@ boards_router = APIRouter(prefix="/v1/boards", tags=["boards"])
|
|||||||
201: {"description": "The board was created successfully"},
|
201: {"description": "The board was created successfully"},
|
||||||
},
|
},
|
||||||
status_code=201,
|
status_code=201,
|
||||||
|
response_model=BoardDTO,
|
||||||
)
|
)
|
||||||
async def create_board(
|
async def create_board(
|
||||||
board_name: str = Body(description="The name of the board to create"),
|
board_name: str = Body(description="The name of the board to create"),
|
||||||
):
|
) -> BoardDTO:
|
||||||
"""Creates a board"""
|
"""Creates a board"""
|
||||||
try:
|
try:
|
||||||
result = ApiDependencies.invoker.services.boards.create(board_name=board_name)
|
result = ApiDependencies.invoker.services.boards.create(board_name=board_name)
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail="Failed to create board")
|
raise HTTPException(status_code=500, detail="Failed to create board")
|
||||||
|
|
||||||
|
|
||||||
@boards_router.patch(
|
@boards_router.patch(
|
||||||
"/{board_id}",
|
"/{board_id}",
|
||||||
operation_id="update_board",
|
operation_id="update_board",
|
||||||
responses={
|
responses={
|
||||||
201: {"description": "The board was updated successfully"},
|
201: {
|
||||||
|
"description": "The board was updated successfully",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
status_code=201,
|
status_code=201,
|
||||||
|
response_model=BoardDTO,
|
||||||
)
|
)
|
||||||
async def update_board(
|
async def update_board(
|
||||||
board_id: str = Path(description="The id of board to update"),
|
board_id: str = Path(description="The id of board to update"),
|
||||||
changes: BoardChanges = Body(description="The changes to apply to the board"),
|
changes: BoardChanges = Body(description="The changes to apply to the board"),
|
||||||
):
|
) -> BoardDTO:
|
||||||
"""Creates a board"""
|
"""Updates a board"""
|
||||||
try:
|
try:
|
||||||
result = ApiDependencies.invoker.services.boards.update(board_id=board_id, changes=changes)
|
result = ApiDependencies.invoker.services.boards.update(
|
||||||
|
board_id=board_id, changes=changes
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail="Failed to update board")
|
raise HTTPException(status_code=500, detail="Failed to update board")
|
||||||
@ -63,7 +70,7 @@ async def delete_board(
|
|||||||
@boards_router.get(
|
@boards_router.get(
|
||||||
"/",
|
"/",
|
||||||
operation_id="list_boards",
|
operation_id="list_boards",
|
||||||
response_model=OffsetPaginatedResults[BoardRecord],
|
response_model=OffsetPaginatedResults[BoardDTO],
|
||||||
)
|
)
|
||||||
async def list_boards(
|
async def list_boards(
|
||||||
offset: int = Query(default=0, description="The page offset"),
|
offset: int = Query(default=0, description="The page offset"),
|
||||||
@ -76,4 +83,3 @@ async def list_boards(
|
|||||||
limit,
|
limit,
|
||||||
)
|
)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user