
- Set up FastAPI project structure - Create database models for locations and weather data - Implement OpenWeatherMap API integration - Create API endpoints for current weather and history - Add health endpoint - Set up database migrations with Alembic - Update README with documentation generated with BackendIM... (backend.im)
81 lines
1.5 KiB
Python
81 lines
1.5 KiB
Python
from pydantic import BaseModel, Field
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
|
|
|
|
class LocationBase(BaseModel):
|
|
name: str
|
|
country: str
|
|
latitude: float
|
|
longitude: float
|
|
|
|
|
|
class LocationCreate(LocationBase):
|
|
pass
|
|
|
|
|
|
class LocationUpdate(LocationBase):
|
|
name: Optional[str] = None
|
|
country: Optional[str] = None
|
|
latitude: Optional[float] = None
|
|
longitude: Optional[float] = None
|
|
|
|
|
|
class LocationInDBBase(LocationBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class Location(LocationInDBBase):
|
|
pass
|
|
|
|
|
|
class WeatherDataBase(BaseModel):
|
|
temperature: float
|
|
feels_like: float
|
|
humidity: int
|
|
pressure: int
|
|
wind_speed: float
|
|
wind_direction: int
|
|
weather_condition: str
|
|
weather_description: str
|
|
clouds: int
|
|
timestamp: datetime
|
|
|
|
|
|
class WeatherDataCreate(WeatherDataBase):
|
|
location_id: int
|
|
|
|
|
|
class WeatherDataInDBBase(WeatherDataBase):
|
|
id: int
|
|
location_id: int
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class WeatherData(WeatherDataInDBBase):
|
|
pass
|
|
|
|
|
|
class WeatherResponse(BaseModel):
|
|
location: Location
|
|
current_weather: WeatherData
|
|
|
|
|
|
class WeatherHistoryResponse(BaseModel):
|
|
location: Location
|
|
history: List[WeatherData]
|
|
|
|
|
|
class WeatherRequest(BaseModel):
|
|
city: Optional[str] = None
|
|
country: Optional[str] = None
|
|
lat: Optional[float] = None
|
|
lon: Optional[float] = None |