GitHunt
IG

igorantun/card-games-api

๐Ÿƒ API for managing card games

๐Ÿƒ Card games API

CircleCI
Codecov Coverage

Description

This is an API for managing card games. It supports creating card decks, buying cards, shuffling and returning them to the deck.

Getting started

Prerequesites

  • Docker
  • Docker Compose

Cloning and copying .env example

$ git clone git@github.com:igorantun/card-games-api.git
$ cd card-games-api
$ cp .env.example .env

Make commands

$ make dev # Starts development server, with nodemon
$ make start # Starts server
$ make stop # Stops server
$ make kill # Kills containers
$ make restart # Restarts server
$ make clean # Cleans containers and volumes
$ make sh # Opens shell inside api container
$ make test-e2e # Runs end-to-end test scripts
$ make test-unit # Runs unit test scripts
$ make test-coverage # Runs test coverage audit
$ make test # Runs all tests scripts

Routes

Run in Postman

Create new game with 2 decks

Request

POST /decks

{
  "decks": 2
}
Response
{
  "id": "5ec4b190eae60200181db40c",
  "remainingCards": 104
}

Create new game with truco deck

Request

POST /decks

{
  "decks": 1,
  "options": {
    "without": {
      "ranks": ["8", "9", "10"]
    }
  }
}
Response
{
  "id": "5ec4b282eae60200181db40d",
  "remainingCards": 40
}

Buy cards from deck

Request

POST /decks/:deckId/buy

{
  "cards": 3
}
Response
{
  "remainingCards": 37,
  "cards": [
    { "rank": "4", "suit": "diamonds" },
    { "rank": "5", "suit": "clubs" },
    { "rank": "7", "suit": "hearts" }
  ]
}

Return cards to deck

Request

PUT /decks/:deckId/return

{
    "position": "middle",
    "cards": [
      { "rank": "7", "suit": "hearts" },
      { "rank": "4", "suit": "diamonds" }
    ]
  }
Response
{
  "remainingCards": 39
}

Shuffle cards on deck

Request

PUT /decks/:deckId/shuffle

Response
{
  "remainingCards": 39
}

License

Released under the MIT License. See the LICENSE file
for details.