style:use restful api
This commit is contained in:
+23
-5
@@ -4,9 +4,11 @@ from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class WeatherDataIn(BaseModel):
|
||||
"""Payload accepted by POST /data."""
|
||||
"""Payload accepted by POST /stations/{station_name}/observations.
|
||||
|
||||
station_name is taken from the URL path, not the request body.
|
||||
"""
|
||||
|
||||
station_name: str = Field(..., description="Name of the weather station")
|
||||
temperature: float | None = Field(None, description="Temperature in Celsius")
|
||||
pressure: float | None = Field(None, description="Atmospheric pressure in hPa")
|
||||
relative_humidity: float | None = Field(
|
||||
@@ -15,7 +17,7 @@ class WeatherDataIn(BaseModel):
|
||||
|
||||
|
||||
class WeatherRecordOut(BaseModel):
|
||||
"""Record returned by the API (includes server-assigned fields)."""
|
||||
"""A single observation record (includes server-assigned fields)."""
|
||||
|
||||
id: int
|
||||
station_name: str
|
||||
@@ -25,8 +27,24 @@ class WeatherRecordOut(BaseModel):
|
||||
received_at: datetime
|
||||
|
||||
|
||||
class WeatherHistoryResponse(BaseModel):
|
||||
"""Wrapper for history queries — always returns a list (empty if no data)."""
|
||||
class ObservationListResponse(BaseModel):
|
||||
"""Response for GET /stations/{station_name}/observations."""
|
||||
|
||||
station_name: str
|
||||
count: int
|
||||
records: list[WeatherRecordOut]
|
||||
|
||||
|
||||
class StationInfo(BaseModel):
|
||||
"""Summary of a known weather station."""
|
||||
|
||||
name: str
|
||||
observation_count: int
|
||||
latest_observation_at: datetime | None
|
||||
|
||||
|
||||
class StationListResponse(BaseModel):
|
||||
"""Response for GET /stations."""
|
||||
|
||||
stations: list[StationInfo]
|
||||
count: int
|
||||
|
||||
Reference in New Issue
Block a user