EventsZilla: RavenDB modeling walkthrough
I needed a simple event publishing application. I also felt like doing another RavenDB sample app and a RavenDB post on it. This is how EventsZilla came to life. EventsZilla (full sources here: https://github.com/synhershko/eventszilla) is meant to be a simple web application to announce events along with a schedule, which is also capable of viewing past and future events. People should be able to register to an event without registering with the website, and also view slides and other content when it becomes available post-event. This post is being written during development, describing each stage and the considerations leading to the next. As such, the code I link to does not necessarily work, although it should. I will probably have some fixes and amendments made to the code after publishing this post.Initial modeling
When we speak of an events publishing application, what are we looking at? The most basic items are an Event with means of registration, and a list of sessions for each Event. Each event should have a registration window, and a venue in which it takes place, and obviously title and description. For each session in an event we want to have a Presenter (possibly more than one), a title, a brief (aka abstract), and times in which each session starts and ends. We should note the start and end time of the event are going to be derived directly from the first and last sessions of the event. For now we call a session a "Schedule slot".Unlike a relational model, with RavenDB we can sketch the entire thing as one class and just use it. There is one exception though - at this stage we already know venues and presenters might be showing several times in different events (maybe even the same presenter in multiple sessions in the same event), so we don't want to store them directly under the event, but rather link to them by storing their IDs only. They could be efficiently retrieved using the Includes feature.
We end up with this Event class:
[code lang="csharp"] public class Event { public Event() { Schedule = new List<ScheduleSlot>(); } public int Id { get; set; } public string Title { get; set; } public string Slug { get; set; } public string Description { get; set; } // markdown content public string VenueId { get; set; } public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset RegistrationOpens { get; set; } public DateTimeOffset RegistrationCloses { get; set; } public int AvailableSeats { get; set; } public class ScheduleSlot { public List<string> PresenterIds { get; set; } // list of person IDs public string Title { get; set; } public string Brief { get; set; } // markdown public DateTimeOffset StartingAt { get; set; } public DateTimeOffset EndingAt { get; set; } } public List<ScheduleSlot> Schedule { get; set; } public DateTimeOffset StartsAt { get { var firstSession = Schedule.OrderBy(x => x.StartingAt).FirstOrDefault(); return firstSession == null ? DateTimeOffset.MinValue : firstSession.StartingAt; } } public DateTimeOffset EndsAt { get { var lastSession = Schedule.OrderByDescending(x => x.EndingAt).FirstOrDefault(); return lastSession == null ? DateTimeOffset.MaxValue : lastSession.EndingAt; } } } [/code]Since an event schedule has no meaning outside the scope of an event, it is best persisted there as well. It also means the whole schedule will be loaded with the event with each Load or Query operation this event will be part of. At this stage we are fine with that.
The StartsAt and EndsAt properties of the Event are persisted this way to take some pressure off the indexes we are going to create, so business logic will reside in the actual domain types instead of in the indexes as much as possible.
The Venue and Presenter classes are quite trivial ones, so won't be shown here.
The actual code for this phase is in this github commit.