49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
"""
|
|
Pydantic schemas for tweets.
|
|
|
|
This module defines request and response schemas for tweet-related operations.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
|
|
class TweetBase(BaseModel):
|
|
"""Base schema for tweet data."""
|
|
tweet_id: str = Field(..., description="Unique identifier from the source platform")
|
|
text: str = Field(..., min_length=1, max_length=1000, description="Tweet content")
|
|
created_at: datetime = Field(..., description="Timestamp when the tweet was created")
|
|
retweet_count: int = Field(default=0, ge=0, description="Number of retweets")
|
|
like_count: int = Field(default=0, ge=0, description="Number of likes")
|
|
match_id: Optional[int] = Field(None, description="Foreign key to matches table")
|
|
source: str = Field(default="twitter", description="Source platform (twitter, reddit, rss)")
|
|
|
|
|
|
class TweetCreate(TweetBase):
|
|
"""Schema for creating a new tweet."""
|
|
pass
|
|
|
|
|
|
class TweetResponse(TweetBase):
|
|
"""Schema for tweet response."""
|
|
id: int = Field(..., description="Primary key")
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class TweetListResponse(BaseModel):
|
|
"""Schema for a list of tweets."""
|
|
data: list[TweetResponse]
|
|
count: int = Field(..., description="Total number of tweets")
|
|
meta: dict = Field(default_factory=dict, description="Additional metadata")
|
|
|
|
|
|
class TweetStatsResponse(BaseModel):
|
|
"""Schema for tweet statistics."""
|
|
total_tweets: int = Field(..., description="Total number of tweets")
|
|
tweets_by_source: dict = Field(..., description="Breakdown by source platform")
|
|
tweets_by_match: dict = Field(..., description="Breakdown by match")
|
|
avg_retweet_count: float = Field(..., description="Average retweet count")
|
|
avg_like_count: float = Field(..., description="Average like count")
|