Giter Club home page Giter Club logo

reservation-service's Introduction

README

This is a demo web application that implements an endpoint that accepts reservation requests in different JSON formats for storage.

Setup

This application is a relatively standard Rails API app running against a PostgreSQL database (for JSON storage). It needs PostgreSQL to be running on localhost:5432, with a user called postgres and an empty password.

To set up and run (in development mode):

bundle

rails db:setup

rails server

This sets up the endpoint at http://localhost:3000/reservations.

Testing

Sample data using the two formats is included as payload1.json and payload2.json. This lets us test with curl as follows (from app root):

curl -H "Content-Type: application/json" -d @`pwd`/payload1.json localhost:3000/reservations
curl -H "Content-Type: application/json" -d @`pwd`/payload2.json localhost:3000/reservations

Note that the two examples have different reservation dates to avoid conflict.

Rake tasks are provided to easily inspect the records created and purge them:

rake dump:reservations
rake purge:reservations

rspec

A spec is included for the ProcessReservationRequest service, which does the bulk of the work.

rspec -fd

Notes/Caveats

  • This implementation models and stores ReservationRequest separately from the actual Reservation. This provides the flexibility to reprocess requests later, should processing requirements change or implementation issues be found.

  • Reservation requests are accepted and queued for asynchronous processing, so the /reservations endpoint is lightweight and future complex processing does not affect performance. The only validation done at the endpoint is on the JSON payload. Acceptance of a request does not guarantee that it is processed (for example, it may conflict with existing reservations.

  • Reservation models attributes common to both formats. Format-specific data is stored in individual reservations as a JSON object called misc.

  • Guest records are automatically created if they don't exist. Guest lookup is done by email.

  • Reservations are associated with guest records, but guest data from the request is also embedded as a JSON object in individual Reservation records for easy direct access. Guest records are created once, but reservations may have different data for the referenced guest. For one thing, the two formats have different phone number structures.

  • This implementation does not enforce non-overlapping reservation date ranges for a guest. It does however enforce uniqueness on (guest_id, start_date, end_date), so repeating a request will fail to create another reservation. Error reporting beyond logging is not implemented.

  • As this is a proof of concept, DB writes are intentionally called with !, so errors are immediately obvious and can be dealt with.

  • Modelling exclusivity of reservations for properties would be a nice challenge, but is not in scope.

reservation-service's People

Watchers

Paolo Veñegas 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.