Skip to main content
Version: v0.14

Cinema Ticket Booking

This is a beginner-friendly tutorial intended to familiarize developers with the creation and utilization of custom schemas in a simple ticket booking application.

This tutorial makes use of Conduit's REST API for CRUD operations.

Prerequisites

Following this tutorial requires that you have already read the Database module's Getting Started guide.
Please make sure you understand the basics before resuming.

Make sure your schemas' CRUD operations are enabled.
That should generate CRUD application-level routes, as long as the Router module is available.
While doing so, do not enable authentication as this goes beyond the scope of this basic tutorial.


Scenario

You are a building a ticket booking website for a cinema.
You need a fast, yet efficient way to build your application's backend.

Requirements

Your website needs to keep track of movies, halls and projections.
It should also be aware of ticket availability for the latter.
In order to represent each one of these through types, we need to figure out their specifications.

A movie should have a name, a director, a duration and a release date.
A hall needs a name, a number of seats and a class.
A projection has relation fields to a movie and a hall, as well as a datetime field and a counter for the tickets sold for it.

Head to the admin panel's Database page so we can begin creating our schemas.


Building our Backend

Movies Schema:

Create a new schema and name it Movies.
A movie's name is a string, so drag a text field element into the schema fields area.
After the field edit pane is brought up, set its name to name and make it required.

Drag another text field, name it director, make it required and save that too.
We are going to represent duration in minutes, so use a number field, name it duration and make that too required.
At last, drag a date field into the schema area, name it releaseDate. Yeap, that's also required.

Movies Schema Created

CRUD Operations Configuration

Verify that your schema's CRUD endpoints are enabled and do not require authentication.

With that out of the way, our schema looks solid. Hit that save button 💾.

Note how we used a text type for the Movies schema's director field in order to keep the tutorial's complexity at check.
Ideally, we would be storing the directors on a separate schema and using a relation field instead.
Feel free to play around and improve on the original design after you're done.

Halls Schema:

Create a Halls schema, adding three required fields.
A name text field, a seats number field and a class enum field (of type text).
Enum options are separated via new lines.

Halls Class Enum

Damn, you're getting good at this.

Projections Schema:

Last but not least, create a Projections schema to combine these two.
Add two required relation fields. Name the first one movie and select Movies from the relation type dropdown.
Now create a required hall field, setting its relation type to Halls.

Projections Movie Relation

Use a date field to represent the startTime and make it required.
At last, throw in a required ticketsSold number field with a default value of 0.

We are going to use that last one to calculate the number of tickets available for sale based on the hall's seats down the road.


Testing our CRUD Endpoints

Wait that's it?
Yeap. Your schemas are already exposed through Conduit's REST API.
GraphQL is also supported out of the box, but we're focusing on REST for this tutorial.