To assess your ability to build a simple API.
The scenario and requirements will be provided separately.
Although an infant cannot be assigned a seat that ticket type still counts as a ticket when calculating the total number of tickets so they are included in the 25 tickets.
As an infant will be sitting on an Adults lap. The number of adults must be greater than or equal to the number of infants. you cannot have 1 adult and 25 infants.
An account can make multiple purchases even if the total tickets are over 25 as long as each purchase has 25 or less. So no need to keep track of accounts and tickets purchased after the current transaction is complete.
I decided to use the TicketService as a "Generic" service this means that in the future this could be used for other services. As long as they configure the 2 new config properties.
Although the ENUM would have to be changed to allow new types the code will be able to handle them as long as they are also included in the cinema.ticket-prices config.
Most of the hard coded business rules are related to validation so they are all in the CinemaValidator class.
Even though infant tickets cost Zero we still calculate the cost in case it changes therefore the code will not have to change.
To allow the prices to be set without having to change the code ticket prices can be set in the application.properties:
- cinema.ticket-prices.ADULT=25.00
- cinema.ticket-prices.CHILD=15.00
- cinema.ticket-prices.INFANT=0.00
If the cinema decided that infants have to have a seat they can be added to the cinema.seat-required-types. This means this can be configured without needing a code change.
A ticket request is deemed invalid if any of the following are true:
- The type is valid e.g. not null
- The ID is less than 1
- Any of the ticket types contain a negative QTY
- The total number of tickets requested is Greater than 25
- The total number of tickets is less than one.
- There are no adult tickets requested
- The number of infant tickets are more than the number of adults
Errors are returned as pipe("|") delimited string, each error has a Code and String seperated by a Tilde ("~") to allow them to be easily understood by the caller/calling system
For the unit test I have created tests using "//Given//When//Then" to ensure the tests are clear and ensure the requirement are implemented. I created an integration test to ensure the application works for one successful call and one unsuccessful call. If i were to do more development on this i would ensure there is more integration test coverage to ensure the