Giter VIP home page Giter VIP logo

evolution-game-service's Introduction

Game Service

Starting the application

To start and stop the application you can use standard spring-boot maven goals: mvn spring-boot:start and mvn spring-boot:stop

You can also run the project's main class GameServiceApplication directly from your IDE.

Project structure

Project structure follows the Hexagonal Architecture rules.

package perczynski.kamil.evolution.gameservice
│
├── api (controllers, requests)
├── domain (domain logic, port definitions)
├── infra (classes needed to for spring integration, ports' implementations)
└── libs (shared classes, possibly between multiple projects, eligible for distrubution as the separate artifact)

Limitations & design decisions

For handling the monetary operations there has been introduced a Money class which performs the math on the minor units (eurocents in the case for euro).

The class also assumes the only currency in the application is Euro.

For readability when manually playing around with the API the Money class redundant field formatted which shows the monetary amount in the human-readable format e.g. €10.00

API endpoints

HTTP method Path Description
POST /players Register a player with the default initial balance
GET /players/{playerId} Read a player
POST /players/{playerId}/bets Place a bet
GET /game-rounds?playerId={playerId} List all game rounds for the player
GET /game-rounds/{roundId} Read a game round

Usage manual

Please find full user journey documented in the form of the acceptance test in class GameAcceptanceTests.

Firstly a player needs to be registered with a call to POST /players

// POST /players
{
  "playerId": "21393719-4f01-40cb-b2d7-8c287900213e",
  "balance": {
    "amount": 500000,
    "formatted": "€5,000.00"
  },
  "freeRoundAvailable": false
}
// 200 OK
{
  "playerId": "2d04073d-cb7f-4c63-a57a-40e711948a36",
  "balance": {
    "amount": 500000,
    "formatted": "€5,000.00"
  },
  "freeRoundAvailable": false
}

Then the player is eligible for placing bets

// POST /players/21393719-4f01-40cb-b2d7-8c287900213e/bets
{
  "stake": 1000,
  "mode": "PLAY_FOR_CASH"
}
// 200 OK
{
  "id": "9292409a-a926-43a9-acf7-2296e75a55a3",
  "bet": {
    "mode": "PLAY_FOR_CASH",
    "stake": {
      "amount": 1000,
      "formatted": "€10.00"
    }
  },
  "win": {
    "payout": {
      "amount": 3000,
      "formatted": "€30.00"
    },
    "freeRound": false
  },
  "nextBalance": {
    "amount": 502000,
    "formatted": "€5,020.00"
  },
  "playerId": "21393719-4f01-40cb-b2d7-8c287900213e"
}

Then the player is eligible to read the game history at GET /game-rounds?playerId=2d04073d-cb7f-4c63-a57a-40e711948a36

{
  "rounds": [
    {
      "id": "164e9cf9-f369-4170-9987-638c93fde5fa",
      "bet": {
        "mode": "PLAY_FOR_CASH",
        "stake": {
          "amount": 1000,
          "formatted": "€10.00"
        }
      },
      "win": {
        "payout": {
          "amount": 3000,
          "formatted": "€30.00"
        },
        "freeRound": false
      },
      "nextBalance": {
        "amount": 502000,
        "formatted": "€5,020.00"
      },
      "playerId": "2d04073d-cb7f-4c63-a57a-40e711948a36"
    }
  ]
}

evolution-game-service's People

Contributors

kamil-perczynski avatar

Watchers

 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.