def get_membership_details(meeting_uuid: str, user_uuid: str): validate_meeting_uuid(meeting_uuid) validate_user_uuid(user_uuid) meeting = find_meeting(meeting_uuid) user = find_user(user_uuid) membership = find_membership(meeting_uuid, user_uuid) return { 'uuid': meeting.uuid, 'name': meeting.name, 'description': meeting.description, 'datetime': format_datetime(meeting.datetime), 'stop_name': meeting.stop_name, 'members': [{ 'nickname': membership.nickname, 'is_owner': is_owner(membership.user, meeting), 'is_you': membership.user == user, 'stop_name': membership.stop_name, } for membership in meeting.users], 'membership': { 'is_owner': is_owner(user, meeting), 'stop_name': membership.stop_name, } }, 200
def edit_membership_details(meeting_uuid: str, user_uuid: str): validate_meeting_uuid(meeting_uuid) validate_user_uuid(user_uuid) check_json_data() stop_name = get_stop_name() membership = find_membership(meeting_uuid, user_uuid) membership.stop_name = stop_name db.session.commit() return '', 204
def leave_meeting(user_uuid: str, meeting_uuid: str): validate_user_uuid(user_uuid) validate_meeting_uuid(meeting_uuid) meeting = find_meeting(meeting_uuid) user = find_user(user_uuid) if is_owner(user, meeting): raise ApiException('Meeting owner cannot leave meeting', 403) membership = find_membership(meeting_uuid, user_uuid) db.session.delete(membership) db.session.commit() return '', 204
def get_user_meetings(user_uuid: str): validate_user_uuid(user_uuid) user = find_user(user_uuid) return { 'meetings': [ { 'uuid': membership.meeting.uuid, 'name': membership.meeting.name, 'nickname': membership.nickname, 'datetime': format_datetime(membership.meeting.datetime), 'members_count': len(membership.meeting.users), # TODO: use COUNT() } for membership in user.meetings ] }, 200
def join_meeting(meeting_uuid: str, user_uuid: str): validate_meeting_uuid(meeting_uuid) validate_user_uuid(user_uuid) check_json_data() nickname = get_nickname() meeting = find_meeting(meeting_uuid) user = find_user(user_uuid) membership = Membership(user=user, meeting=meeting, nickname=nickname) db.session.add(membership) try: db.session.commit() except (IntegrityError, FlushError): raise ApiException('Already a member', 400) return '', 204
def check_if_user_exists(user_uuid: str): validate_user_uuid(user_uuid) find_user(user_uuid) return '', 204