improve timezone discovery
This commit is contained in:
@@ -70,7 +70,7 @@ async def calculate_availability(
|
||||
participants = {p.id: p for p in participants_result.scalars().all()}
|
||||
|
||||
days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
|
||||
hours = list(range(9, 18))
|
||||
hours = list(range(0, 24))
|
||||
slots = []
|
||||
|
||||
for day_offset, day_name in enumerate(days):
|
||||
@@ -98,6 +98,7 @@ async def calculate_availability(
|
||||
slots.append({
|
||||
"day": slot_start.strftime("%Y-%m-%d"),
|
||||
"hour": hour,
|
||||
"start_time": slot_start,
|
||||
"availability": availability,
|
||||
"availableParticipants": available_participants,
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@ from app.schemas import (
|
||||
AvailabilityRequest,
|
||||
AvailabilityResponse,
|
||||
ParticipantCreate,
|
||||
ParticipantUpdate,
|
||||
ParticipantResponse,
|
||||
SyncResponse,
|
||||
ScheduleRequest,
|
||||
@@ -63,6 +64,7 @@ async def create_participant(
|
||||
participant = Participant(
|
||||
name=data.name,
|
||||
email=data.email,
|
||||
timezone=data.timezone,
|
||||
ics_url=data.ics_url,
|
||||
)
|
||||
db.add(participant)
|
||||
@@ -95,6 +97,35 @@ async def get_participant(participant_id: UUID, db: AsyncSession = Depends(get_d
|
||||
return participant
|
||||
|
||||
|
||||
@app.patch("/api/participants/{participant_id}", response_model=ParticipantResponse)
|
||||
async def update_participant(
|
||||
participant_id: UUID, data: ParticipantUpdate, db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
result = await db.execute(
|
||||
select(Participant).where(Participant.id == participant_id)
|
||||
)
|
||||
participant = result.scalar_one_or_none()
|
||||
if not participant:
|
||||
raise HTTPException(status_code=404, detail="Participant not found")
|
||||
|
||||
if data.timezone is not None:
|
||||
participant.timezone = data.timezone
|
||||
if data.ics_url is not None:
|
||||
participant.ics_url = data.ics_url if data.ics_url else None
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(participant)
|
||||
|
||||
# Re-sync calendar if ICS URL was updated
|
||||
if data.ics_url is not None and participant.ics_url:
|
||||
try:
|
||||
await sync_participant_calendar(db, participant)
|
||||
except Exception as e:
|
||||
logger.warning(f"Calendar sync failed for {participant.email}: {e}")
|
||||
|
||||
return participant
|
||||
|
||||
|
||||
@app.delete("/api/participants/{participant_id}")
|
||||
async def delete_participant(participant_id: UUID, db: AsyncSession = Depends(get_db)):
|
||||
result = await db.execute(
|
||||
|
||||
@@ -18,6 +18,7 @@ class Participant(Base):
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
||||
timezone: Mapped[str] = mapped_column(String(50), nullable=False, default="America/Toronto")
|
||||
ics_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, nullable=False
|
||||
|
||||
@@ -7,6 +7,12 @@ from pydantic import BaseModel, EmailStr
|
||||
class ParticipantCreate(BaseModel):
|
||||
name: str
|
||||
email: EmailStr
|
||||
timezone: str = "America/Toronto"
|
||||
ics_url: str | None = None
|
||||
|
||||
|
||||
class ParticipantUpdate(BaseModel):
|
||||
timezone: str | None = None
|
||||
ics_url: str | None = None
|
||||
|
||||
|
||||
@@ -14,6 +20,7 @@ class ParticipantResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
email: str
|
||||
timezone: str
|
||||
ics_url: str | None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
@@ -25,6 +32,7 @@ class ParticipantResponse(BaseModel):
|
||||
class TimeSlot(BaseModel):
|
||||
day: str
|
||||
hour: int
|
||||
start_time: datetime
|
||||
availability: str
|
||||
availableParticipants: list[str]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user