Files
weather-info/app/classes/weather_response.py
2025-11-13 19:54:51 +01:00

48 lines
1.6 KiB
Python

from .weather import Weather
from .response_status import ResponseStatus
class WeatherResponse:
_response_status: ResponseStatus
_weather: Weather
def __init__(self):
self._weather = None
self._response_status = None
# Weather property with getter and setter
@property
def weather(self)->Weather:
"""Get the weather data"""
return self._weather
@weather.setter
def weather(self, value:Weather)->None:
"""Set the weather data with validation"""
if value is not None and not isinstance(value, Weather):
raise TypeError("weather must be an instance of Weather class")
self._weather = value
# ResponseStatus property with getter and setter
@property
def response_status(self)->ResponseStatus:
"""Get the response status"""
return self._response_status
@response_status.setter
def response_status(self, value:ResponseStatus)->None:
"""Set the response status with validation"""
if value is not None and not isinstance(value, ResponseStatus):
raise TypeError("response_status must be an instance of ResponseStatus class")
self._response_status = value
# Additional utility methods
def is_successful(self)->bool:
"""Check if the response was successful"""
return self._response_status is not None
def has_weather_data(self)->bool:
"""Check if weather data is available"""
return self._weather is not None
def __str__(self)->str:
return f"WeatherResponse(weather={self._weather}, status={self._response_status})"