File size: 2,458 Bytes
643d1b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Response models for API endpoints"""
from pydantic import BaseModel, Field
from typing import List, Optional
from datetime import datetime


class Product(BaseModel):
    """Individual product model"""
    
    id: str = Field(..., description="Product ID")
    name: str = Field(..., description="Product name")
    price: str = Field(..., description="Product price")
    url: str = Field(..., description="Product URL")
    image_url: Optional[str] = Field(None, description="Product image URL")
    

class ScrapeResponse(BaseModel):
    """Response model for scraping endpoint"""
    
    success: bool = Field(..., description="Whether the scraping was successful")
    search_term: str = Field(..., description="Search term used")
    total_expected: Optional[int] = Field(None, description="Total products expected")
    total_extracted: int = Field(..., description="Total products extracted")
    extraction_rate: Optional[float] = Field(None, description="Extraction success rate (%)")
    products: List[Product] = Field(..., description="List of extracted products")
    execution_time: float = Field(..., description="Execution time in seconds")
    timestamp: datetime = Field(default_factory=datetime.now, description="Timestamp of extraction")
    error: Optional[str] = Field(None, description="Error message if failed")
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "success": True,
                "search_term": "bags",
                "total_expected": 200,
                "total_extracted": 198,
                "extraction_rate": 99.0,
                "products": [
                    {
                        "id": "product_001",
                        "name": "Birkin 25",
                        "price": "1,500,000 JPY",
                        "url": "https://www.hermes.com/jp/ja/product/...",
                        "image_url": "https://assets.hermes.com/..."
                    }
                ],
                "execution_time": 35.2,
                "timestamp": "2025-01-24T10:00:00",
                "error": None
            }
        }
    }


class HealthResponse(BaseModel):
    """Health check response"""
    
    status: str = Field(..., description="Service status")
    version: str = Field(..., description="API version")
    uptime: float = Field(..., description="Uptime in seconds")
    timestamp: datetime = Field(default_factory=datetime.now)