Improve the frontend 5
This commit is contained in:
@@ -61,5 +61,72 @@ class DataClient:
|
||||
logger.error(f"Error fetching weather data: {e}", tenant_id=tenant_id)
|
||||
return []
|
||||
|
||||
async def fetch_tenant_calendar(
|
||||
self,
|
||||
tenant_id: str
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Fetch tenant's assigned school calendar
|
||||
Returns None if no calendar assigned
|
||||
"""
|
||||
try:
|
||||
location_context = await self.external_client.get_tenant_location_context(
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
|
||||
if location_context and location_context.get("calendar"):
|
||||
logger.info(
|
||||
"Fetched calendar for tenant",
|
||||
tenant_id=tenant_id,
|
||||
calendar_name=location_context["calendar"].get("calendar_name")
|
||||
)
|
||||
return location_context["calendar"]
|
||||
else:
|
||||
logger.info("No calendar assigned to tenant", tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching calendar: {e}", tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
async def check_school_holiday(
|
||||
self,
|
||||
calendar_id: str,
|
||||
check_date: str,
|
||||
tenant_id: str
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a date is a school holiday
|
||||
|
||||
Args:
|
||||
calendar_id: School calendar UUID
|
||||
check_date: Date in ISO format (YYYY-MM-DD)
|
||||
tenant_id: Tenant ID for auth
|
||||
|
||||
Returns:
|
||||
True if school holiday, False otherwise
|
||||
"""
|
||||
try:
|
||||
result = await self.external_client.check_is_school_holiday(
|
||||
calendar_id=calendar_id,
|
||||
check_date=check_date,
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
|
||||
if result:
|
||||
is_holiday = result.get("is_holiday", False)
|
||||
if is_holiday:
|
||||
logger.debug(
|
||||
"School holiday detected",
|
||||
date=check_date,
|
||||
holiday_name=result.get("holiday_name")
|
||||
)
|
||||
return is_holiday
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking school holiday: {e}", date=check_date)
|
||||
return False
|
||||
|
||||
# Global instance - same as before, but much simpler implementation
|
||||
data_client = DataClient()
|
||||
Reference in New Issue
Block a user