Compare commits
No commits in common. "bruh" and "master" have entirely different histories.
51
src/main.py
51
src/main.py
|
@ -209,51 +209,25 @@ def get_slot_by_id(
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
class MarkBusyByIdResponse(SQLModel):
|
@app.post('/calendar_events/{slot_id}/mark_busy', response_model=CalendarEvent, tags=['Calendar'])
|
||||||
target_slot: CalendarEvent
|
|
||||||
target_slot_is_busy: bool
|
|
||||||
closest_free_slot: CalendarEvent | None
|
|
||||||
closest_free_slot_same_time: bool
|
|
||||||
closest_free_slot_same_day: bool
|
|
||||||
|
|
||||||
|
|
||||||
@app.post('/calendar_events/{slot_id}/mark_busy', response_model=MarkBusyByIdResponse, tags=['Calendar'])
|
|
||||||
def mark_busy_calendar_slot_by_id(
|
def mark_busy_calendar_slot_by_id(
|
||||||
slot_id: str,
|
slot_id: str,
|
||||||
description: str | None = None,
|
description: str | None = None,
|
||||||
service: Resource = Depends(get_calendar_service)
|
service: Resource = Depends(get_calendar_service)
|
||||||
):
|
):
|
||||||
event = get_slot_by_id(slot_id=slot_id, service=service)
|
event = get_slot_by_id(slot_id=slot_id, service=service)
|
||||||
target_event_start_time = datetime.fromisoformat(event.start.dateTime)
|
|
||||||
|
|
||||||
free_slots = get_free_calendar_slots(lower_bound=target_event_start_time, service=service)
|
if event.summary != TITLE_FREE:
|
||||||
free_slots = list(filter(lambda slot: slot.id != event.id, free_slots))
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Slot is busy")
|
||||||
closest_free_slot = free_slots[0] if free_slots else None
|
|
||||||
closest_free_slot_same_time = False
|
|
||||||
closest_free_slot_same_day = False
|
|
||||||
if closest_free_slot:
|
|
||||||
closest_free_slot_start_time = datetime.fromisoformat(closest_free_slot.start.dateTime)
|
|
||||||
closest_free_slot_same_time = closest_free_slot_start_time == target_event_start_time
|
|
||||||
closest_free_slot_same_day = closest_free_slot_start_time.date() == target_event_start_time.date()
|
|
||||||
|
|
||||||
target_slot_is_busy = False
|
event.summary = TITLE_BUSY
|
||||||
if event.summary == TITLE_FREE:
|
event.colorId = COLOR_BUSY
|
||||||
event.summary = TITLE_BUSY
|
if description:
|
||||||
event.colorId = COLOR_BUSY
|
event.description = description
|
||||||
if description:
|
|
||||||
event.description = description
|
|
||||||
|
|
||||||
service.events().update(calendarId=CALENDAR_ID, eventId=event.id, body=event.dict(exclude_unset=True)).execute()
|
service.events().update(calendarId=CALENDAR_ID, eventId=event.id, body=event.dict(exclude_unset=True)).execute()
|
||||||
else:
|
|
||||||
target_slot_is_busy = True
|
|
||||||
|
|
||||||
return MarkBusyByIdResponse(
|
return event
|
||||||
target_slot=event,
|
|
||||||
target_slot_is_busy=target_slot_is_busy,
|
|
||||||
closest_free_slot=closest_free_slot,
|
|
||||||
closest_free_slot_same_time=closest_free_slot_same_time,
|
|
||||||
closest_free_slot_same_day=closest_free_slot_same_day
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.post('/calendar_events/{slot_id}/mark_free', response_model=CalendarEvent, tags=['Calendar'])
|
@app.post('/calendar_events/{slot_id}/mark_free', response_model=CalendarEvent, tags=['Calendar'])
|
||||||
|
@ -339,15 +313,16 @@ class FormatDateRequest(BaseModel):
|
||||||
{
|
{
|
||||||
'date': "10.07.2023 15:33:08"
|
'date': "10.07.2023 15:33:08"
|
||||||
}
|
}
|
||||||
|
# '2023-07-10T15:33:08+07:00',
|
||||||
|
# '2023-07-10 15:33:08',
|
||||||
|
# '10.07.2023 15:33:08'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@validator('date', pre=True)
|
@validator('date', pre=True)
|
||||||
def validate_date(cls, val):
|
def validate_date(cls, val):
|
||||||
try:
|
try:
|
||||||
if type(val) == datetime:
|
if re.match(r'^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})$', val):
|
||||||
return val
|
|
||||||
elif re.match(r'^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})$', val):
|
|
||||||
return datetime.strptime(val, "%Y-%m-%d %H:%M:%S")
|
return datetime.strptime(val, "%Y-%m-%d %H:%M:%S")
|
||||||
elif re.match(r'^(\d{2}.\d{2}.\d{4}) (\d{2}:\d{2}:\d{2})$', val):
|
elif re.match(r'^(\d{2}.\d{2}.\d{4}) (\d{2}:\d{2}:\d{2})$', val):
|
||||||
return datetime.strptime(val, "%d.%m.%Y %H:%M:%S")
|
return datetime.strptime(val, "%d.%m.%Y %H:%M:%S")
|
||||||
|
|
Loading…
Reference in New Issue