Show Time is a web backend application, providing APIs to manage tickets to shows and musicals. It is built using Scala 2.13, ZIO and ZIO HTTP.
Application can be configured via application.conf. You can also override config values with following environment variables.
Variable Name | Data Type | Description | Required |
---|---|---|---|
PORT | Int | Running port of the application | No, defaults to 8080 |
SHOW_DURATION_IN_DAYS | Int | How many days do shows run | No, defaults to 100 |
MUSICAL_PRICE | Int | Ticket price for musicals | No, defaults to 70 |
COMEDY_PRICE | Int | Ticket price for comedies | No, defaults to 50 |
DRAMA_PRICE | Int | Ticket price for dramas | No, defaults to 40 |
DISCOUNT_AFTER_DAYS | Int | After how many days of a show's opening day should a discount be applied | No, defaults to 80 |
DISCOUNT_PERCENTAGE | Int | Discount percentage to apply | No, defaults to 20 |
THEATER_SIZE | Int | How many seats are there in the theater | No, defaults to 100 |
For log configuration, see logback.xml.
Application is built with SBT. So, standard SBT tasks like clean
, compile
and run
can be used. To run the application locally:
sbt run
To run automated tests, you can use test
and testOnly
tasks of SBT. To run all tests:
sbt test
To run specific test(s):
sbt 'testOnly fullyQualifiedTestClassName1 fullyQualifiedTestClassName2 ...'
There is a run.sh
script included to build and run the application in Docker. So you can just run
./run.sh
If you want to do it manually, you may use included docker-compose.yml
.
First build an image locally with
sbt clean 'Docker / publishLocal'
Then start the application with
docker-compose up
Environment variables mentioned in Configuration are passed to the container except for PORT
. PORT
variable only affects the port on host machine while running the application in Docker. The application in the container will still run on its default port which will be mapped to given PORT
on the host machine. For example, if you run
PORT=9000 ./run.sh
then the port 9000
on the host machine will be mapped to the port 8080
in the container which is the application's default port.
Here is an overview of the APIs:
Method | URL | Link |
---|---|---|
GET | /inventory/{date} | Jump |
POST | /inventory/order | Jump |
Errors return a human-readable message as plain text with a non-OK HTTP status code.
All successful responses will have 200 OK
status unless explicitly mentioned.
This endpoint can be used to list the availabilities of shows for given date
. Shows are grouped by their genre and sorted by
tickets_avaliable
in ascending order, except for sold-out tickets which would be at the end of the listprice
in ascending ordertitle
in ascending order
Parameter | Data Type | Description | Required | Example |
---|---|---|---|---|
date | LocalDate | ISO formatted date for which show availabilities will be listed | Yes | 2022-09-15 |
{
"inventory": [
{
"genre": "drama",
"shows": [
{
"price": 40,
"tickets_available": 100,
"title": "EVENING AT THE TALK HOUSE"
},
{
"price": 40,
"tickets_available": 100,
"title": "FATHER, THE"
},
{
"price": 40,
"tickets_available": 100,
"title": "LORD OF THE FLIES, THE"
},
{
"price": 40,
"tickets_available": 100,
"title": "RICHARD II"
},
{
"price": 40,
"tickets_available": 100,
"title": "THREE DAYS IN THE COUNTRY"
}
]
},
{
"genre": "musical",
"shows": [
{
"price": 70,
"tickets_available": 100,
"title": "BEAUTIFUL - THE CAROLE KING MUSICAL"
},
{
"price": 70,
"tickets_available": 100,
"title": "COMMITMENTS, THE"
},
{
"price": 70,
"tickets_available": 100,
"title": "GYPSY"
},
{
"price": 70,
"tickets_available": 100,
"title": "SINATRA AT THE LONDON PALLADIUM"
}
]
}
]
}
This endpoint can be used to place an order for a show on a date for given number of tickets. It returns a summary of the operation, including remaining available tickets if the order was successful.
{
"show": "EVENING AT THE TALK HOUSE",
"performance_date": "2022-09-15",
"tickets": 1
}
{
"performance_date": "2022-10-13",
"show": "1984",
"status": "success",
"tickets_available": 12,
"tickets_bought": 2
}
{
"message": "Cannot place order for show '1984' on date '2022-10-13', 5 tickets requested but the show has 2 tickets left",
"performance_date": "2022-10-13",
"show": "1984",
"status": "failure"
}
All contributions are welcome. Please feel free to send a pull request. Thank you.
Show Time is licensed with MIT License.