feat: implement backend API clients for multi-marketplace integration and frontend service layer

This commit is contained in:
2026-05-12 13:16:14 +03:00
parent 6974af486a
commit ee39a3d83b
65 changed files with 2501 additions and 33 deletions

View File

@@ -0,0 +1,34 @@
from typing import Dict, Any, List, Optional
from ..client import YMClient
class AssortmentService:
"""Service to handle Yandex Market Assortment/Products."""
def __init__(self, client: YMClient):
self.client = client
def get_offer_mappings(self, business_id: Optional[str] = None, page_token: str = None, limit: int = 100) -> Dict[str, Any]:
"""
Get list of offers (products) in the business catalog.
Endpoint: /businesses/{businessId}/offer-mappings.json
"""
bid = business_id or self.client.business_id
if not bid:
raise ValueError("business_id must be provided either in the method call or client initialization.")
payload = {"limit": limit}
if page_token:
payload["page_token"] = page_token
return self.client.post(f"/businesses/{bid}/offer-mappings.json", data=payload)
def update_offer_mappings(self, offers: List[Dict[str, Any]], business_id: Optional[str] = None) -> Dict[str, Any]:
"""
Update offers (products) in the business catalog.
Endpoint: /businesses/{businessId}/offer-mappings/update.json
"""
bid = business_id or self.client.business_id
if not bid:
raise ValueError("business_id must be provided either in the method call or client initialization.")
return self.client.post(f"/businesses/{bid}/offer-mappings/update.json", data={"offerMappings": offers})

View File

@@ -0,0 +1,45 @@
from typing import Dict, Any, Optional
from ..client import YMClient
class OrdersService:
"""Service to handle Yandex Market Orders."""
def __init__(self, client: YMClient):
self.client = client
def get_list(self, campaign_id: Optional[str] = None, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
"""
Get list of orders for a specific campaign.
Endpoint: /campaigns/{campaignId}/orders.json
"""
cid = campaign_id or self.client.campaign_id
if not cid:
raise ValueError("campaign_id must be provided either in the method call or client initialization.")
return self.client.get(f"/campaigns/{cid}/orders.json", params=params)
def get_order(self, order_id: str, campaign_id: Optional[str] = None) -> Dict[str, Any]:
"""
Get info about a specific order.
Endpoint: /campaigns/{campaignId}/orders/{orderId}.json
"""
cid = campaign_id or self.client.campaign_id
if not cid:
raise ValueError("campaign_id must be provided either in the method call or client initialization.")
return self.client.get(f"/campaigns/{cid}/orders/{order_id}.json")
def update_status(self, order_id: str, status: str, substatus: Optional[str] = None, campaign_id: Optional[str] = None) -> Dict[str, Any]:
"""
Update the status of an order.
Endpoint: /campaigns/{campaignId}/orders/{orderId}/status.json
"""
cid = campaign_id or self.client.campaign_id
if not cid:
raise ValueError("campaign_id must be provided either in the method call or client initialization.")
payload = {"order": {"status": status}}
if substatus:
payload["order"]["substatus"] = substatus
return self.client.put(f"/campaigns/{cid}/orders/{order_id}/status.json", data=payload)