Skip to content

Commit

Permalink
add all delete routes (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
chennisden authored Jun 7, 2024
1 parent f2d0923 commit 4e32c63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions store/app/api/crud/robots.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ async def get_part(self, part_id: str) -> Part | None:
if "Item" not in part_dict:
return None
return Part.model_validate(part_dict["Item"])

async def delete_part(self, part_id: str) -> None:
table = await self.db.Table("Parts")
await table.delete_item(Key={"part_id": part_id})
16 changes: 16 additions & 0 deletions store/app/api/routers/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ async def add_part(
part.part_id = str(get_new_user_id())
await crud.add_part(part)
return True


@parts_router.delete("/delete/{part_id}")
async def delete_part(
part_id: str,
data: Annotated[ApiKeyData, Depends(get_api_key)],
crud: Annotated[Crud, Depends(Crud.get)],
) -> bool:
part = await crud.get_part(part_id)
if part is None:
raise HTTPException(status_code=404, detail="Part not found")
user_id = await crud.get_user_id_from_api_key(data.api_key)
if part.owner != user_id:
raise HTTPException(status_code=403, detail="You do not own this part")
await crud.delete_part(part_id)
return True
2 changes: 1 addition & 1 deletion store/app/api/routers/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ async def delete_robot(
raise HTTPException(status_code=404, detail="Robot not found")
user_id = await crud.get_user_id_from_api_key(data.api_key)
if robot.owner != user_id:
raise HTTPException(status_code=401, detail="You do not own this robot")
raise HTTPException(status_code=403, detail="You do not own this robot")
await crud.delete_robot(robot_id)
return True

0 comments on commit 4e32c63

Please sign in to comment.