GithubHelp home page GithubHelp logo

seat_reservation_service's Introduction

Seat Reservation Services

This is a simple seat reservation services. It is implemented as a spring boot project.

How to build and run this service

In project root directory, assuming you have gradle installed already, simply do:

gradle bootRun

The service will be built and running on localhost:8080

How to run unit tests

In project root directory, do:

gradle test

It will run through unit tests for controller.

APIs

  • GET /api/seats[?level=1]

This API will return all available seats or, if level is specified as parameter, available seats in that level.

This API will hold certain numbers of seats based on parameters. numSeats is the number of seats user wants to hold. minLevel is the minimum level number. maxLevel is the maximum level number. customerEmail is user's email address. Depends on the available seats numbers, user may or may not get all seats he wants. For example if there are only 10 seats available in level 1 and level 2, but user asked for 20 seats, then he still just gets 10 seats in this case. The holding seat is only valid for certain time. Once the holding seats expire, they become available again.

This API will reserve the seats held by user in previous API call. seatHoldId is returned ID from previous API call for a seat holding request. customerEmail is user's email address.

Design and implementation notes

The project follows standard spring boot project convention. It includes model, service, and controller layers. JPA repository is used for database query. h2database is used as embedded database to store Seat and Reservation information.

Since seat holding will expire after certain time, it is a short-living object, so it is not stored in database. Instead Ehcache is used to store seat holding objects. Since Ehcache has built-in expiry support, it is more robust than other solutions such as timer thread etc.

Every time when SeatService needs to retrieve available seats, it will query database to get all un-reserved seats, then it will check ehcache to filter out those on-holding but not reserved seats.

Database initialization and configurations

Two tables: seats and reservations are created in schema.sql. 3 levels and 10 seats for each level. Seat holding time is set to 10 seconds in application.properties file for testing purpose.

Regarding tests

Basic unit tests are implemented for controller methods. More unit tests for service layer could be added as future improvements. To test functions, a Postman test collection "seat_reservation_collection.json" is created for this purpose. This collection does following tests:

  1. Get all available seats at level 1
  2. Hold 15 seats from level 1 to level 2
  3. reserve these 15 seats, check result.
  4. Hold 5 seats from level 1 to level 2 and wait until it expires.
  5. try to reserve this expired holding, it should receive "Hold expires" message

To run this collection. Simply import the json file into Postman app and run it. You need to set up an environment to run collection. For more information, please go to Postman website

seat_reservation_service's People

Contributors

cloud3chuan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.