Try this API working in https://cinema-booking-api.herokuapp.com
.
Clone de repository, run bundle install
and copy config/database.yml.example
to config/database.yml
.
Create test and development databases, user
should be consistent with your config/database.yml
$ createuser -U postgres cinema_booking
$ createdb -U postgres -O cinema_booking cinema_booking_test
$ createdb -U postgres -O cinema_booking cinema_booking_development
Run migrations
$ bundle exec dev_up
$ bundle exec test_up
Run tests
$ bundle exec rspec
Start the development server with rerun
to get a server restart on any change of the source code:
$ rerun -- puma --port 3000 config.ru
Or, run bare server with:
$ puma --port 3000 config.ru
Then in development use the url: http://localhost:3000
for all the endpoints.
All the endpoints expect json
format, that should be set in headers via: Content-Type: application/json
. Response is sent in json
format too.
Create a new movie.
Fields:
name
: required, stringdescription
: optional, stringimage_url
: optional, string, valid url for imagedays
: required, array of strings, valid values: "Sun, Mon, Tue, Wed, Thu, Fri, Sat", defined by rubyDate::ABBR_DAYNAMES
Example:
curl -d '{"name":"Die Hard 3","days":["Mon","Sat"]}' \
-H "Content-Type: application/json" \
-X POST https://cinema-booking-api.herokuapp.com/movies
The API respond with status 201
, or JSON
error message.
List all movies for a given day. It requires one filter param: day
, which is one of the values defined by Date::ABBR_DAYNAMES
Example:
curl -X GET 'https://cinema-booking-api.herokuapp.com/movies?day=Mon' \
-H 'Content-Type: application/json'
The API respond with movies for that day, or error message if filter param is not correct.
Response for the example:
[
{
"id": 1,
"name": "Die Hard 3",
"description": null,
"days": [
"Mon",
"Sat"
],
"image_url": null,
}
]
Create a booking for a movie in a given date.
Fields:
booking_date
: required, string, format YYYY-MM-DD, should be in the futuremovie_id
: required, integer, the movie should exists with this idcustomer_name
: required, string
Example:
curl -d '{"booking_date":"2019-11-02","movie_id":1,"customer_name":"John Doe"}' \
-H "Content-Type: application/json" \
-X POST https://cinema-booking-api.herokuapp.com/bookings
The API respond with status 201
, or JSON
error message.
List bookings between dates. It requires two filter params: from
& to
, that should be in format YYYY-MM-DD
.
Example:
curl -H 'Content-Type: application/json' \
-X GET 'https://cinema-booking-api.herokuapp.com/bookings?from=2019-11-01&to=2019-11-10'
The API responds with bookings between dates or error message if filter params are not correct.
Response for the example:
[
{
"id": 1,
"booking_date": "2019-11-02",
"customer_name": "John Doe",
"movie": {
"id": 1,
"name": "Die Hard 3",
"description": null,
"days": [
"Mon",
"Sat"
],
"image_url": null,
}
}
]