Created
August 29, 2014 10:03
-
-
Save SlevinBE/1b77c74c552b79de06fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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