async def get_available_slots_for_user( self, user_id: int, date: datetime.date) -> List[Record]: log.info('Get slots for user id {}'.format(user_id)) where = and_(slots.c.user_id == user_id, slots.c.is_available == True) if date: where = where & and_(slots.c.date == date) return await BaseCRUD().fetch_all(model=slots, where=where)
async def _add_guests_to_meeting(self, meeting_id: int, guest_emails: List[str]) -> None: log.info('Adding guests to meeting_id {}'.format(meeting_id)) values = list() for email in guest_emails: values.append(dict(meeting_id=meeting_id, email=email)) return await BaseCRUD().bulk_insert(model=meeting_guests, values=values)
async def _create_meeting(self, meeting: MeetingPayload, current_user: User) -> int: log.info('Inserting new meeting {}'.format(meeting)) return await BaseCRUD().insert(model=meetings, values=dict( slot_id=meeting.slot_id, creator_id=current_user.user_id, status=MeetingStatus.Scheduled.name, subject=meeting.subject, notes=meeting.notes))
async def define_available_slots(self, available_slots: List[AvailableSlots], current_user: User) -> None: log.info('Defining slots for {} - {}'.format(current_user.email, available_slots)) try: values = self._get_all_values_to_insert(available_slots, current_user) return await self._insert_new_slots(values) except UniqueViolationError as e: log.error('Duplicate inserts - {}'.format(e)) raise HTTPException(status_code=400, detail='Slot already exists for user')
async def _create_event_in_google_calendar(self, user_id: int, meeting: MeetingPayload, start_time: datetime, current_user) -> None: try: user = await self._get_user(user_id) calendar_id = user.get('calendar_id') if not calendar_id: return log.info( 'Creating event in Google calendar ID {}'.format(calendar_id)) end_time = start_time + timedelta(hours=1) guest_email_ids = meeting.guest_email_ids + [ current_user.email, calendar_id ] GoogleCalendarHandler().create_event( calendar_id=config.CALENDAR_ID, start_time=start_time, end_time=end_time, subject=meeting.subject, notes=meeting.notes, guest_emails=guest_email_ids) except Exception as e: log.error('Google Calendar failure {}'.format(e))
async def get_created_meetings(self, current_user: User) -> List[Record]: log.info('Get created meetings for {}'.format(current_user.email)) return await BaseCRUD().fetch_all( model=meetings, where=(current_user.user_id == meetings.c.creator_id))
async def _mark_slot_status_as_unavailable(self, slot_id: int) -> None: log.info('Mark slot as unavailable {}'.format(slot_id)) await BaseCRUD().update(model=slots, where=(slot_id == slots.c.slot_id), values=dict(is_available=False))
async def add_new_user(user: NewUser, response: Response): log.info('Adding new user {}'.format(user)) new_user = await UserManager().add_user(user=user) response.headers['Location'] = '{prefix}/users/{user_id}'.format( prefix=API_PREFIX, user_id=new_user['user_id']) return new_user