Skip to content

Commit

Permalink
KClip router create and complete request types
Browse files Browse the repository at this point in the history
  • Loading branch information
Winston-Hsiao committed Nov 20, 2024
1 parent 6e2998c commit 8243c72
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion store/app/crud/kclips.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def create_kclip(
user_id: str,
robot_id: str,
name: str,
description: str,
description: str | None = None,
file_size: int | None = None,
part_size: int | None = None,
) -> tuple[KClip, MultipartUploadDetails]:
Expand Down
31 changes: 23 additions & 8 deletions store/app/routers/kclips.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
router = APIRouter()


class CreateKClipRequest(BaseModel):
name: str
robot_id: str
description: str | None = None
file_size: int | None = None
part_size: int | None = None


class NewKClipResponse(BaseModel):
kclip_id: str
upload_details: MultipartUploadDetails
Expand All @@ -22,29 +30,36 @@ class NewKClipResponse(BaseModel):
@router.post("/create")
async def create_kclip(
user: Annotated[User, Depends(get_session_user_with_write_permission)],
robot_id: str,
name: str,
description: str,
kclip_data: CreateKClipRequest,
crud: Annotated[Crud, Depends(Crud.get)],
) -> NewKClipResponse:
kclip, upload_details = await crud.create_kclip(
user_id=user.id, robot_id=robot_id, name=name, description=description
user_id=user.id,
robot_id=kclip_data.robot_id,
name=kclip_data.name,
description=kclip_data.description,
file_size=kclip_data.file_size,
part_size=kclip_data.part_size,
)

return NewKClipResponse(kclip_id=kclip.id, upload_details=upload_details)


class CompletedKClipUploadRequest(BaseModel):
kclip_id: str
upload_id: str
parts: list[KClipPartCompleted]


class CompletedKClipUploadResponse(BaseModel):
status: str


@router.post("/{kclip_id}/complete")
async def complete_upload(
kclip_id: str,
upload_id: str,
parts: list[KClipPartCompleted],
kclip_data: CompletedKClipUploadRequest,
user: Annotated[User, Depends(get_session_user_with_write_permission)],
crud: Annotated[Crud, Depends(Crud.get)],
) -> CompletedKClipUploadResponse:
await crud.complete_upload(kclip_id, upload_id, parts)
await crud.complete_upload(kclip_data.kclip_id, kclip_data.upload_id, kclip_data.parts)
return CompletedKClipUploadResponse(status="completed")

0 comments on commit 8243c72

Please sign in to comment.