GithubHelp home page GithubHelp logo

reservatron's Introduction

Reservatron Build Status

Reserve table service. Use redis distributed lock to guarantee reliable reservations even when multiple instances of Reservatron are running. This service uses GraphQL API via this library.

Future improvements:

  • pagination. Easy way will be integrate querydsl and compose queries in repositories to support pagination on DB level
  • filtering. Also querydsl could be used to optimise requests like getAllTables(filter: {tableId: 1})
  • unsubscribe subscriptions on connection close (due to the strange bug subscriber's onConnect is not called)
  • subscriptions in case of multiple instances. Need to send events with reservations to Kafka and publish updates for subscribed clients.

In docker

Ensure you've built Admin before.

sudo ./gradlew build docker -x test -x test_integration
sudo docker-compose up -d

In OS

export POSTGRES_HOST=localhost
export REDIS_HOST=localhost
./gradlew bootRun

Testing

./gradlew check

Protocol

Graphql is used for communication. Make introspective query to get schema for details. Endpoint for query and mutations is /graphql, for subscriptions is /subscriptions

Examples:

Make a reservation for a table

Method: POST

Body:

mutation ReserveTable
{   reserveTable(input: {tableId: 1,
                         guest: "Test",
                         from: "2018-01-04T18:00:00.000+0000",
                         to: "2018-01-04T19:00:00.000+0000",
                         clientMutationId: "uuid"})
    {status}
}

Response:

{
    "data": {
        "reserveTable": {
            "status": "CONFLICT"
        }
    },
    "errors": [],
    "extensions": null
}

Show all reservations for all tables

Method: POST

Body:

query {allTables
        {edges {node {name reservations
                              {edges {node {guest from to}}}
                     }
               }
        }
      }

Response:

{
    "data": {
        "allTables": {
            "edges": [
                {
                    "node": {
                        "name": "test",
                        "reservations": {
                            "edges": [
                                {
                                    "node": {
                                        "guest": "Test",
                                        "from": "2018-01-04T18:00:00.000+0000",
                                        "to": "2018-01-04T19:00:00.000+0000"
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    "node": {
                        "name": "test2",
                        "reservations": {
                            "edges": []
                        }
                    }
                }
            ]
        }
    },
    "errors": [],
    "extensions": null
}

Subscribe for table reservations

Websocket

Body:

subscription RealTimeReservationsSubscription {
               newReservationMade(tableId: 1) {
                 guest
                 from
                 to
               }
             }

On every new subscription to this server you will receive a Reservation. Important! This repo is just an example of graphql usage. With multiple instances of this service subscriptions won't work correctly, as one instance doesn't receive events about subscription has been made from the other. Important! Subscriptions unsubscribe feature is not working now. CompletionStageMappingPublisher's onSubscribe is not called, thus link between GraphqlSubscriber and Subscription can't be made. As a result, when connection is closed we can't cancel subscription.

reservatron's People

Contributors

comtihon 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.