feat: add book endpoint for purchasing marketplace offers
Some checks failed
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m11s
Integration Tests / test-service-integration (push) Successful in 2m37s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Node Failover Simulation / failover-test (push) Successful in 2s
Python Tests / test-python (push) Failing after 1m6s
Security Scanning / security-scan (push) Failing after 29s
Some checks failed
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m11s
Integration Tests / test-service-integration (push) Successful in 2m37s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Node Failover Simulation / failover-test (push) Successful in 2s
Python Tests / test-python (push) Failing after 1m6s
Security Scanning / security-scan (push) Failing after 29s
- Add POST /v1/marketplace/offers/{offer_id}/book endpoint
- Implement book_offer method to create bids for offers
- Fixes 404 error when CLI tries to purchase offers
- Returns bid_id, offer_id, status, and message
This commit is contained in:
@@ -139,6 +139,23 @@ async def get_offer(
|
||||
raise
|
||||
|
||||
|
||||
@app.post("/v1/marketplace/offers/{offer_id}/book")
|
||||
async def book_offer(
|
||||
offer_id: str,
|
||||
booking_data: dict,
|
||||
svc: MarketplaceService = Depends(get_marketplace_service),
|
||||
):
|
||||
"""Book/purchase a marketplace offer"""
|
||||
try:
|
||||
logger.info(f"POST /v1/marketplace/offers/{offer_id}/book called with data keys: {booking_data.keys()}")
|
||||
result = await svc.book_offer(offer_id, booking_data)
|
||||
logger.info(f"POST /v1/marketplace/offers/{offer_id}/book completed")
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"Error in POST /v1/marketplace/offers/{offer_id}/book: {type(e).__name__}: {str(e)}")
|
||||
raise
|
||||
|
||||
|
||||
@app.post("/v1/marketplace/offers")
|
||||
async def create_offer(
|
||||
offer_data: dict,
|
||||
|
||||
@@ -76,6 +76,36 @@ class MarketplaceService:
|
||||
logger.error(f"Error in get_offer: {type(e).__name__}: {str(e)}")
|
||||
raise
|
||||
|
||||
async def book_offer(self, offer_id: str, booking_data: dict) -> dict:
|
||||
"""Book/purchase a marketplace offer"""
|
||||
try:
|
||||
logger.info(f"book_offer called with offer_id={offer_id}, data keys: {booking_data.keys()}")
|
||||
offer = await self.get_offer(offer_id)
|
||||
if not offer:
|
||||
logger.error(f"Offer not found: {offer_id}")
|
||||
raise ValueError(f"Offer not found: {offer_id}")
|
||||
|
||||
# Create a bid for the offer
|
||||
bid_data = {
|
||||
'provider': booking_data.get('wallet', 'unknown'),
|
||||
'capacity': booking_data.get('duration_hours', 1.0),
|
||||
'price': booking_data.get('price', offer.price),
|
||||
'status': 'pending',
|
||||
}
|
||||
|
||||
bid = await self.create_bid(bid_data)
|
||||
logger.info(f"Created bid for offer {offer_id}: {bid.id}")
|
||||
|
||||
return {
|
||||
'bid_id': bid.id,
|
||||
'offer_id': offer_id,
|
||||
'status': 'pending',
|
||||
'message': 'Bid created successfully'
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error in book_offer: {type(e).__name__}: {str(e)}")
|
||||
raise
|
||||
|
||||
async def create_offer(self, offer_data: dict) -> MarketplaceOffer:
|
||||
"""Create a new marketplace offer"""
|
||||
try:
|
||||
|
||||
@@ -139,6 +139,23 @@ async def get_offer(
|
||||
raise
|
||||
|
||||
|
||||
@app.post("/v1/marketplace/offers/{offer_id}/book")
|
||||
async def book_offer(
|
||||
offer_id: str,
|
||||
booking_data: dict,
|
||||
svc: MarketplaceService = Depends(get_marketplace_service),
|
||||
):
|
||||
"""Book/purchase a marketplace offer"""
|
||||
try:
|
||||
logger.info(f"POST /v1/marketplace/offers/{offer_id}/book called with data keys: {booking_data.keys()}")
|
||||
result = await svc.book_offer(offer_id, booking_data)
|
||||
logger.info(f"POST /v1/marketplace/offers/{offer_id}/book completed")
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"Error in POST /v1/marketplace/offers/{offer_id}/book: {type(e).__name__}: {str(e)}")
|
||||
raise
|
||||
|
||||
|
||||
@app.post("/v1/marketplace/offers")
|
||||
async def create_offer(
|
||||
offer_data: dict,
|
||||
|
||||
@@ -76,6 +76,36 @@ class MarketplaceService:
|
||||
logger.error(f"Error in get_offer: {type(e).__name__}: {str(e)}")
|
||||
raise
|
||||
|
||||
async def book_offer(self, offer_id: str, booking_data: dict) -> dict:
|
||||
"""Book/purchase a marketplace offer"""
|
||||
try:
|
||||
logger.info(f"book_offer called with offer_id={offer_id}, data keys: {booking_data.keys()}")
|
||||
offer = await self.get_offer(offer_id)
|
||||
if not offer:
|
||||
logger.error(f"Offer not found: {offer_id}")
|
||||
raise ValueError(f"Offer not found: {offer_id}")
|
||||
|
||||
# Create a bid for the offer
|
||||
bid_data = {
|
||||
'provider': booking_data.get('wallet', 'unknown'),
|
||||
'capacity': booking_data.get('duration_hours', 1.0),
|
||||
'price': booking_data.get('price', offer.price),
|
||||
'status': 'pending',
|
||||
}
|
||||
|
||||
bid = await self.create_bid(bid_data)
|
||||
logger.info(f"Created bid for offer {offer_id}: {bid.id}")
|
||||
|
||||
return {
|
||||
'bid_id': bid.id,
|
||||
'offer_id': offer_id,
|
||||
'status': 'pending',
|
||||
'message': 'Bid created successfully'
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Error in book_offer: {type(e).__name__}: {str(e)}")
|
||||
raise
|
||||
|
||||
async def create_offer(self, offer_data: dict) -> MarketplaceOffer:
|
||||
"""Create a new marketplace offer"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user