fix: resolve JSON serialization in list_bids and add orders endpoint
Some checks failed
Deploy to Testnet / deploy-testnet (push) Successful in 1m13s
Integration Tests / test-service-integration (push) Successful in 2m38s
Python Tests / test-python (push) Failing after 1m5s
Security Scanning / security-scan (push) Failing after 17s
Node Failover Simulation / failover-test (push) Successful in 2s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s

- Convert SQLAlchemy objects to dictionaries in list_bids method
- Add GET /v1/marketplace/orders endpoint for CLI compatibility
- Fixes 500 error when listing bids
- Fixes 404 error when CLI calls orders endpoint
- Orders endpoint returns bids in expected format
This commit is contained in:
aitbc
2026-05-08 19:54:02 +02:00
parent 587841935e
commit fb09022e84
4 changed files with 68 additions and 4 deletions

View File

@@ -205,6 +205,23 @@ async def create_bid(
raise
@app.get("/v1/marketplace/orders")
async def get_orders(
wallet: str | None = None,
svc: MarketplaceService = Depends(get_marketplace_service),
):
"""Get marketplace orders (alias for bids for CLI compatibility)"""
try:
logger.info(f"GET /v1/marketplace/orders called with wallet={wallet}")
# Use list_bids with provider filter as orders are stored as bids
result = await svc.list_bids(provider=wallet)
# Return in format expected by CLI
return {"orders": result}
except Exception as e:
logger.error(f"Error in GET /v1/marketplace/orders: {type(e).__name__}: {str(e)}")
raise
@app.get("/v1/marketplace/analytics")
async def get_analytics(
period_type: str = "daily",

View File

@@ -128,7 +128,7 @@ class MarketplaceService:
self,
status: str | None = None,
provider: str | None = None,
) -> list[MarketplaceBid]:
) -> list[dict]:
"""List marketplace bids"""
try:
logger.info(f"list_bids called with filters: status={status}, provider={provider}")
@@ -140,7 +140,22 @@ class MarketplaceService:
logger.info("Executing database query for bids")
result = list((await self.session.execute(stmt)).all())
logger.info(f"Retrieved {len(result)} bids")
return result
# Convert SQLAlchemy model objects to dictionaries for JSON serialization
bids_list = []
for row in result:
bid = row[0] if row else None
if bid:
bids_list.append({
'id': bid.id,
'provider': bid.provider,
'capacity': bid.capacity,
'price': bid.price,
'notes': bid.notes,
'status': bid.status,
'submitted_at': bid.submitted_at.isoformat() if bid.submitted_at else None,
})
logger.info(f"Converted {len(bids_list)} bids to dictionaries")
return bids_list
except Exception as e:
logger.error(f"Error in list_bids: {type(e).__name__}: {str(e)}")
raise

View File

@@ -205,6 +205,23 @@ async def create_bid(
raise
@app.get("/v1/marketplace/orders")
async def get_orders(
wallet: str | None = None,
svc: MarketplaceService = Depends(get_marketplace_service),
):
"""Get marketplace orders (alias for bids for CLI compatibility)"""
try:
logger.info(f"GET /v1/marketplace/orders called with wallet={wallet}")
# Use list_bids with provider filter as orders are stored as bids
result = await svc.list_bids(provider=wallet)
# Return in format expected by CLI
return {"orders": result}
except Exception as e:
logger.error(f"Error in GET /v1/marketplace/orders: {type(e).__name__}: {str(e)}")
raise
@app.get("/v1/marketplace/analytics")
async def get_analytics(
period_type: str = "daily",

View File

@@ -128,7 +128,7 @@ class MarketplaceService:
self,
status: str | None = None,
provider: str | None = None,
) -> list[MarketplaceBid]:
) -> list[dict]:
"""List marketplace bids"""
try:
logger.info(f"list_bids called with filters: status={status}, provider={provider}")
@@ -140,7 +140,22 @@ class MarketplaceService:
logger.info("Executing database query for bids")
result = list((await self.session.execute(stmt)).all())
logger.info(f"Retrieved {len(result)} bids")
return result
# Convert SQLAlchemy model objects to dictionaries for JSON serialization
bids_list = []
for row in result:
bid = row[0] if row else None
if bid:
bids_list.append({
'id': bid.id,
'provider': bid.provider,
'capacity': bid.capacity,
'price': bid.price,
'notes': bid.notes,
'status': bid.status,
'submitted_at': bid.submitted_at.isoformat() if bid.submitted_at else None,
})
logger.info(f"Converted {len(bids_list)} bids to dictionaries")
return bids_list
except Exception as e:
logger.error(f"Error in list_bids: {type(e).__name__}: {str(e)}")
raise