/gyrododge

Highscore backend for GyroDodge

Primary LanguagePythonMIT LicenseMIT

GyroDodge score backend

This repository contains the source code for the GyroDodge score system.

Requirements

  • Python 3.6+
  • Postman (for making API requests)

Installation

Create your virtualenv

Inside the project root, create a new virtualenv. A virtualenv is an isolated installation of Python. This ensures that you can have multiple Python projects without worrying about different projects colliding with each other.

python3 -m venv venv

Activate the virtualenv.

Windows:

.\venv\Scripts\activate.bat

macOS / Linux:

source venv/bin/activate

Install project dependencies with pip

pip3 install -r requirements.txt

Migrate the database

Django manages the tables and columns in the database. This project is configured to use sqlite by default. Sqlite will store its database in a file called db.sqlite3.

Run migrations to create and populate the database:

python manage.py migrate

Create your user account

You are almost there. Create your user account and follow the prompts.

python manage.py createsuperuser

Start the server

Django comes with a webserver for development purposes. Because our GyroDodge game is not running on the same machine as this score backend we must tell the Django development server to accept connections from our Raspberry Pi.

This webserver should not be used to serve the applications on a real production server!

python manage.py runserver 0.0.0.0:8000

0.0.0.0:8000 means 'listen for connections from other computers on the network on port 8000'. Every computer in your network can now talk to the Django development server. This is a security risk so you should only run the above command on a trusted network like your home network.

Navigating the admin

Now that the development server is running you should be able to access the admin panel.

http://localhost:8000/admin/

After logging in with the credentials you created earlier, you should see a "Scores" link. Click it to view all highscore submissions.

There should be none because you didn't create any yet.

Submitting a highscore

We recommend installing Postman for an easier experience. This guide assumes you are using Postman.

  1. Start Postman. Open the import wizard via the menu File / Import... option and choose the GyroDodge.postman_collection.json file included in this repository.

    In the left sidebar you should now see a GyroDodge folder with at least one item in it.

  2. Open the 'Post new highscore' item by clicking it. Notice that it is a HTTP POST request to http://localhost:8000/api/v1/score/new/

  3. Navigate to the Body tab. It should already contain a JSON payload:

    {
        "points": 10
    }

    points should be the score you archieved while playing the GyroDodge game.

  1. Now make sure you have the development server running and click 'Send'.

  2. You should get a 200 OK response like this:

    {
        "position": 1
    }

    position indicates your current position in the leaderboard.

  1. Navigate to the score admin: http://localhost:8000/admin/score/score/.

    You should see your highscore has been submitted.


License

See LICENSE