Giter Site home page Giter Site logo

card-fun's Introduction

card-fun

card-fun is a demo about creating decks of cards, and drawing items from it.

The project uses task to make your life easier. If you're not familiar with Taskfile, you can take a look at this quickstart guide.

Overview

Create a new Deck

PUT request to /v1/create

It can be done by either:

  • creating a deck from a given list of cards like cards=AS,KD,AC,2C,KH as query parameter.
  • creating a full deck by leaving it out

Then it may be shuffled on request by adding shuffled=true as query parameter creating a full deck.

It returns a JSON response like the following with a random UUID as a deck identifier and number of cards.

{
    "deck_id": "a251071b-662f-44b6-ba11-e24863039c59",
    "shuffled": false,
    "remaining": 30
}

It may return errors with status 400 if there are duplicated cards, of some cards are not found or in a wrong format.

Open a Deck

GET request to /v1/open

There is a mandatory parameter in the query for deck identifier in deck_id.

The response looks like the following as JSON.

{
    "deck_id": "a251071b-662f-44b6-ba11-e24863039c59",
    "shuffled": false,
    "remaining": 3,
    "cards": [
        {
            "value": "ACE",
            "suit": "SPADES",
            "code": "AS"
        },
        ...
    ]
}

It may result in an error if there's no such deck.

Draw card(s)

POST request to /v1/draw

There is a mandatory parameter in the query for deck identifier in deck_id. Another optional parameter in query is count that may be any positive integer until the size of the deck. If not set, it's default is 1.

The response looks like the following with the drawn list of cards:

{
    "cards": [
        {
            "value": "QUEEN",
            "suit": "HEARTS",
            "code": "QH"
        },
        {
            "value": "4",
            "suit": "DIAMONDS",
            "code": "4D"
        }
    ]
}

It may result in an error if there's no such deck, or if the deck has less cards than the requested number.

Dependencies and install

Taskfile. Docker for the following commands: task docker-build, task docker-run, task dev, task docker-test

Usage

In order to run it, you need a running redis server. The easiest way to run it is calling the following with running docker service:

task docker-run

Or if you have an installed Go ecosystem with GOPATH, the following will reuse package cache, so it will be much faster:

task dev

Or if you have a running redis on your localhost, you may run it without docker:

task run

Then open http://localhost:3000/swagger in your browser.

Test & lint

Lint:

task lint

Run tests with running docker service:

task docker-test

Run tests with running redis on localhost:

task test

Check test coverage in browser:

task cover

REST

Swagger docs can be regenerated using task swagger, and can be found in cmd/server/docs. If you already ran it, it will be symlinked to out/docs.

card-fun's People

Contributors

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