Skip to content

olexandr-klymenko/tictactoe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic-tac-toe game API

A Tic-tac-toe game API

Features

  • Create/Delete/Read Player details (/api/admin/players/)
  • List players table (/api/admin/players/)
  • Build ranking table for current season (/api/admin/ranking/)
  • Start new season, list seasons (/api/admin/seasons/)
  • Start game, list games statistics (/api/games/)
  • Get game board data, make game turn (/api/games/<game_id>)

Note: Ranking table can be built by any season by passing season_id as query argument:

/api/admin/ranking/?season_id=XXX

Note: Games stat list can be obtained for given season, player, draw result by passing corresponding query arguments:

/api/games/?season_id=XXX
/api/games/?player_id=XXX
/api/games/?is_draw=true

Components

Flask CLI help command output:

Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=tictactoe.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  db      Perform database migrations.
  routes  Show the routes for the app.
  run     Run a development server.
  shell   Run a shell in the app context.
  test    Run unit tests

Pre-requisites

Poetry is recommended to help manage the dependencies and virtualenv.

You can also use other DBs like PostGreSQL, make sure you have it setup and update your DATABASE_URL in your configs. Read more at Flask-SQLAlchemy's documentations.

It uses Black for code styling/formatting.

Usage

Installing with Poetry

# Install packages with poetry
$ poetry install

Running

Please specify your app's environment variables in a .env file, otherwise Flask CLI wouldn't find your app.

# .env file example
FLASK_APP=tictactoe
FLASK_CONFIG=development

# Read more at https://github.com/theskumar/python-dotenv
$ cp .env_eample .env
# Enter the virtualenv
$ poetry shell

$ flask db init # Creates a new migration repository.
$ flask db migrate #  Create a new revision file.
$ flask db upgrade # Upgrade to a later version.

# Run the app
$ flask run

You can make requests to API in swagger UI. Open in browser http://127.0.0.1:5000/api

Unit testing

# Unit testing
$ flask test

# Run specific unit test(s)
$ flask test test tests.test_models.TestModels.test_game_finished_winner ...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages