Добавил методы для работы со слотами по id
This commit is contained in:
parent
61af375c0e
commit
ed54a0aa71
58
src/main.py
58
src/main.py
|
@ -148,8 +148,8 @@ def create_calendar_slots(datetime_start: datetime, timezone: str, slot_length_m
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
||||||
@app.post('/calendar_events/busy', response_model=List[CalendarEvent])
|
@app.get('/calendar_events/free_slots', response_model=List[CalendarEvent])
|
||||||
def mark_busy_calendar_slot(
|
def get_free_calendar_slots(
|
||||||
lower_bound: datetime = None,
|
lower_bound: datetime = None,
|
||||||
upper_bound: datetime = None,
|
upper_bound: datetime = None,
|
||||||
service: Resource = Depends(get_calendar_service)
|
service: Resource = Depends(get_calendar_service)
|
||||||
|
@ -188,6 +188,60 @@ def mark_busy_calendar_slot(
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
@app.get('/calendar_events/{slot_id}', response_model=CalendarEvent)
|
||||||
|
def get_slot_by_id(
|
||||||
|
slot_id: str,
|
||||||
|
service: Resource = Depends(get_calendar_service)
|
||||||
|
):
|
||||||
|
event_dict = service.events().get(
|
||||||
|
calendarId=CALENDAR_ID,
|
||||||
|
eventId=slot_id
|
||||||
|
)
|
||||||
|
event = CalendarEvent(**event_dict)
|
||||||
|
|
||||||
|
if not event:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Slot not found")
|
||||||
|
|
||||||
|
if event.summary != TITLE_FREE:
|
||||||
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Slot is busy")
|
||||||
|
|
||||||
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
@app.post('/calendar_events/{slot_id}/mark_busy', response_model=CalendarEvent)
|
||||||
|
def mark_busy_calendar_slot_by_id(
|
||||||
|
slot_id: str,
|
||||||
|
description: str | None = None,
|
||||||
|
service: Resource = Depends(get_calendar_service)
|
||||||
|
):
|
||||||
|
event = get_slot_by_id(slot_id=slot_id)
|
||||||
|
|
||||||
|
event.summary = TITLE_BUSY
|
||||||
|
event.colorId = COLOR_BUSY
|
||||||
|
if description:
|
||||||
|
event.description = description
|
||||||
|
|
||||||
|
service.events().update(calendarId=CALENDAR_ID, eventId=event.id, body=event.dict(exclude_unset=True)).execute()
|
||||||
|
|
||||||
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
@app.post('/calendar_events/{slot_id}/mark_free', response_model=CalendarEvent)
|
||||||
|
def mark_free_calendar_slot_by_id(
|
||||||
|
slot_id: str,
|
||||||
|
service: Resource = Depends(get_calendar_service)
|
||||||
|
):
|
||||||
|
event = get_slot_by_id(slot_id=slot_id)
|
||||||
|
|
||||||
|
event.summary = TITLE_FREE
|
||||||
|
event.colorId = COLOR_FREE
|
||||||
|
event.description = " "
|
||||||
|
|
||||||
|
service.events().update(calendarId=CALENDAR_ID, eventId=event.id, body=event.dict(exclude_unset=True)).execute()
|
||||||
|
|
||||||
|
return event
|
||||||
|
|
||||||
|
|
||||||
@app.post('/calendar_events/mark_free', response_model=CalendarEvent)
|
@app.post('/calendar_events/mark_free', response_model=CalendarEvent)
|
||||||
def mark_free_calendar_slot(
|
def mark_free_calendar_slot(
|
||||||
lower_bound: datetime = None,
|
lower_bound: datetime = None,
|
||||||
|
|
Loading…
Reference in New Issue