From 0c995f741251a838c63ec8a278164c53d5cc85ca Mon Sep 17 00:00:00 2001 From: aitbc Date: Tue, 28 Apr 2026 18:12:20 +0200 Subject: [PATCH] Change GPU buy/sell endpoints to avoid path conflicts --- .../src/app/routers/marketplace_gpu.py | 18 ++++++++---------- cli/handlers/market.py | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/coordinator-api/src/app/routers/marketplace_gpu.py b/apps/coordinator-api/src/app/routers/marketplace_gpu.py index 2c7d0d7e..1818f6a8 100755 --- a/apps/coordinator-api/src/app/routers/marketplace_gpu.py +++ b/apps/coordinator-api/src/app/routers/marketplace_gpu.py @@ -224,20 +224,19 @@ async def get_gpu_details(gpu_id: str, session: Annotated[Session, Depends(get_s return result -@router.post("/marketplace/gpu/{gpu_id}/purchase") +@router.post("/marketplace/gpu/purchase") async def buy_gpu( - gpu_id: str, request: GPUBuyRequest, session: Annotated[Session, Depends(get_session)], engine: DynamicPricingEngine = Depends(get_pricing_engine), ) -> dict[str, Any]: """Buy GPU compute from marketplace with blockchain payment.""" - gpu = _get_gpu_or_404(session, gpu_id) + gpu = _get_gpu_or_404(session, request.gpu_id) if gpu.status != "available": raise HTTPException( status_code=http_status.HTTP_409_CONFLICT, - detail=f"GPU {gpu_id} is not available for purchase", + detail=f"GPU {request.gpu_id} is not available for purchase", ) # Create booking for the purchase @@ -263,7 +262,7 @@ async def buy_gpu( booking_id = str(uuid4()) booking = GPUBooking( id=booking_id, - gpu_id=gpu_id, + gpu_id=request.gpu_id, job_id=f"purchase_{request.buyer_id[:8]}", duration_hours=request.duration_hours, total_cost=total_cost, @@ -282,7 +281,7 @@ async def buy_gpu( return { "purchase_id": booking_id, - "gpu_id": gpu_id, + "gpu_id": request.gpu_id, "buyer_id": request.buyer_id, "duration_hours": request.duration_hours, "total_cost": total_cost, @@ -294,14 +293,13 @@ async def buy_gpu( } -@router.post("/marketplace/gpu/{gpu_id}/list_for_sale") +@router.post("/marketplace/gpu/list_for_sale") async def sell_gpu( - gpu_id: str, request: GPUSellRequest, session: Annotated[Session, Depends(get_session)], ) -> dict[str, Any]: """List GPU for sale on marketplace with specified price.""" - gpu = _get_gpu_or_404(session, gpu_id) + gpu = _get_gpu_or_404(session, request.gpu_id) # Update GPU listing gpu.price_per_hour = request.listing_price @@ -311,7 +309,7 @@ async def sell_gpu( session.refresh(gpu) return { - "gpu_id": gpu_id, + "gpu_id": request.gpu_id, "seller_id": request.seller_id, "listing_price": request.listing_price, "status": "listed", diff --git a/cli/handlers/market.py b/cli/handlers/market.py index 7ecd166a..d3ae61ef 100644 --- a/cli/handlers/market.py +++ b/cli/handlers/market.py @@ -302,7 +302,7 @@ def handle_market_buy(args, default_coordinator_url, read_password, render_mappi print(f"Submitting purchase to {coordinator_url}...") try: - response = requests.post(f"{coordinator_url}/v1/marketplace/gpu/buy", json=purchase_data, timeout=30) + response = requests.post(f"{coordinator_url}/v1/marketplace/gpu/purchase", json=purchase_data, timeout=30) if response.status_code in (200, 201): result = response.json() print("Purchase submitted successfully")