Git Product home page Git Product logo

battle-results-flask's Introduction

Battle Results - Made with Flask

About this project

This project aims to develop a REST API using Flask + SQLAlchemy for managing game battle results, displaying entries from newest to oldest. The goal is to integrate backend functionality into my game projects and highlight Python code in my portfolio.

Technologies used

  • Sass for styling
  • SQLAlchemy as the ORM
  • SQLite as the database
  • Python as the backend language
  • Flask as the backend web framework
  • Jinja2 as a template engine for back-end UI rendering

How it looks after adding a few battle entries

Print


Running and coding in this project

  • Create a .env file in the project's root folder. For development purposes, it will work fine if you fill it like this:

    FLASK_APP=app.py
    FLASK_RUN_HOST=localhost
    FLASK_RUN_PORT=8080
    FLASK_ENV=development
    FLASK_DEBUG=True
    FLASK_SECRET_KEY=my_flask_app_security_key
    LOCAL_DATABASE_PATH=data
  • Have SQLite installed on your machine. You can check the official SQLite website and follow the installation instructions.

  • Install Pipenv on your machine with pip install pipenv.

  • Create a virtual environment with pipenv --python 3.

  • Activate/reactivate a virtual environment associated to this project with pipenv shell.

  • Confirm virtual environment creation path with pipenv --venv.

  • Install project's dependencies using pipenv install.

  • Run this project with python app.py to make sure the data base Path + URI are going to be resolved. After that, you can run this app with flask run.

  • Open your browser and check the project running with localhost:8080.

  • Make desired updates as you wish, this project is fully open source.

Once you have completed your coding session, you can stop the development server by pressing CTRL + C and exit the virtual environment by using the exit command.


API Endpoints and Models

The Endpoint /entries:

  • GET - /entries: Retrieves a list of all finished battle entries.

  • POST - /entries: Enables the creation of a new battle entry using a JSON object in the format of the BattleEntry model. Requires unique player names and specifies that the winner's name must match one of the players' names. This request needs a JSON body.

  • GET - /entries/:entryId: Allows retrieving a specific entry based on the ID provided in the endpoint. For instance, accessing /entries/1 will bring the first battle result.

  • DELETE - /entries/:entryId: Allows deleting a specific entry based on the ID provided in the endpoint. For instance, accessing /entries/1 delete the first battle result.

  • PATCH - /entries/:entryId: Enables updating any field of a battle entry. If names are being updated, the winner's name must be equal to one of the player's names. The only field that cannot be updated is gameTag once it represents the specific game in which the battle occurred. This request needs a JSON body as well.

The model related to battle result entries

Battle Entry model

  {
    id: number, // Auto-generated
    gameTag: string, // required
    player1Name: string, // required
    player2Name: string, // required
    winnerName: string, // required
    finishedDate: string // "YYYY-MM-DD HH:MM:SS" (ISO 8601 standard) - Optional
  }

Data to be received by the /entries endpoint

Example of a JSON body for POST requests (Creating a new battle entry)

{
  "gameTag": "dweeb_fight",
  "player1Name": "Player 1",
  "player2Name": "Player 2",
  "winnerName": "Player 2"
}

Example of a JSON body for PATCH requests (Updating fields of existing entries)

{
  "winnerName": "Player 1"
}

battle-results-flask's People

Contributors

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