Skip to content

Instantly share code, notes, and snippets.

@SlevinBE
Created August 29, 2014 10:03
Show Gist options
  • Save SlevinBE/1b77c74c552b79de06fa to your computer and use it in GitHub Desktop.
Save SlevinBE/1b77c74c552b79de06fa to your computer and use it in GitHub Desktop.
//load all relevant meetings with their attendees
meetings
.leftJoin(attendeeLinks).on { case (meeting, attendeeLink) =>
meeting.id === attendeeLink.meetingId
}
.leftJoin(users).on { case ((meeting, attendeeLink), user) =>
attendeeLink.userId === user.id
}
.where { case ((meeting, attendeeLink), user) =>
meeting.id in meetingIds
}
.sortBy { case ((meeting, attendeeLink), user) =>
meeting.startTime.desc
}
.map { case ((meeting, attendeeLink), attendee) =>
(meeting, attendee.?)
}
//for every result row, put the attendee on the meeting
.mapResult { case (meeting: Meeting, attendeeOption: Option[User]) =>
meeting.attendees = attendeeOption.map(Set(_)).orElse(Some(Set.empty[User]))
meeting
}
//merge meetings with the same id
.list.groupBy(_.id).mapValues { meetingsWithSameId =>
meetingsWithSameId.reduce { (previousMeeting, meeting) =>
previousMeeting.attendees = Some(previousMeeting.attendees.get ++ meeting.attendees.get)
previousMeeting
}
}.values.toList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment