Code Monkey home page Code Monkey logo

hahimur-flask's Introduction

Hahimur-flask

Backend for Hahimur

Why "Hahimur"?

On every major football tournament, my friends and I are trying to predict the outcomes. We usually use excel sheets to do it, and I decided to create a website for us. For the front-end I'm using Elm, and you can see the first part of it, where you can start creating you predictions, here.

Live URL

https://hahimur-api.herokuapp.com/

Installation

Clone the repository, create a virtualenv, preferably with python3.7.6, and install all the dependencies.

git clone [email protected]:idanmel/Hahimur-flask.git
cd Hahimur-flask
virtualenv --python=/usr/bin/python3.7 venv
source venv/bin/activate
pip install -r requirements.txt
touch .env

The .env file is where you will place all your environment variables. For example:

FLASK_APP=hahimur.py
FLASK_ENV=development
SECRET_KEY=TOP_secret
DATABASE_URL=postgresql://hahimur:hahimur@localhost/hahimur
AUTH0_DOMAIN=confidentioal
API_AUDIENCE=confidentioal
ALGORITHMS=confidentioal

Database

Create a database, then run

flask db upgrade

Running the server locally

flask run

Running the tests locally

cd Hahimur-flask
source venv/bin/activate
python test_hahimur.py

The tests include JWT tokens for the two roles.

RBAC roles

Here are the roles and their permissions

User

  • get:tournaments
  • get:teams

Admin

  • get:tournaments
  • post:tournaments
  • delete:tournaments
  • get:teams
  • post:teams
  • patch:teams

API Endpoints

GET    '/tournaments'
POST   '/tournaments'
DELETE '/tournaments/<int>'
GET    '/teams/<int>'
POST   '/teams/'
Patch  '/teams/<int>'

GET '/tournaments'

  • Fetches a list of tournaments
  • Request Arguments: None
  • Returns: A list of objects of {id: int, name: text}.
[
    {"uid": 1, "name": "Euro 2020"},
    {"uid": 2, "name": "World Cup 2022"},
    {"uid": 3, "name": "Euro 2024"},
    ...
]

POST '/tournaments'

  • Creates a new tournament
  • ContentType: 'application/json'
  • Data: {"name": text}
  • Returns: 201 with a "Location" header containing the URL of the created tournament and an empty body

DELETE '/tournaments/'

  • Deletes a tournament
  • Request Arguments: Tournament UID
  • Returns on success: 204 with an empty body
  • Returns 422 when given the wrong UID

GET '/teams/'

  • Fetches a team
  • Request Argument: Team UID
  • Returns an object of {"uid": int, "name": text, "flag": text}
  • Returns 404 when given the wrong uid
{
    "uid": 1,
    "name": "Brazil",
    "flag": "url_of_flag"
}

POST '/teams/'

  • Creates a new team
  • ContentType: 'application/json'
  • Data: {"name": text, "flag": text}
  • Returns: 201 with a "Location" header containing the URL of the created team and an empty body

Patch '/teams/'

  • Changes an existing Team
  • ContentType: 'application/json'
  • Data: an object containing "name", "flag", or both.
  • Returns: 204 with an empty body

Tokens for calling the live site:

Admin Token

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik4wTTBOamhHUVRoRVJVUTVOVUpGUWtFMk5USkNOVEJCTURRelJFUkNNVGRGT0VWRE1rSTJOQSJ9.eyJpc3MiOiJodHRwczovL2lkYW5tZWwuZXUuYXV0aDAuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDJ8MTA4NDI2ODEzNDI4NDAyMjA2OTkyIiwiYXVkIjpbImh0dHBzOi8vaGFoaW11ci5jb20iLCJodHRwczovL2lkYW5tZWwuZXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTU4MDk0ODQ5MCwiZXhwIjoxNTgxMDM0ODkwLCJhenAiOiJMMlIzalVGaVRaRkptYXZ3VGNWUktxaDdMOUVPU0xETiIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwiLCJwZXJtaXNzaW9ucyI6WyJkZWxldGU6dG91cm5hbWVudHMiLCJnZXQ6dGVhbXMiLCJnZXQ6dG91cm5hbWVudHMiLCJwYXRjaDp0ZWFtcyIsInBvc3Q6dGVhbXMiLCJwb3N0OnRvdXJuYW1lbnRzIl19.RUOwEBioIPgZwIjz82uSwLVyJJXbDqEYOaa0ZKBbyhCAL3XZkjVoEKJTCyPfy9CJ52YoPX6BQukiyTZzbgq6REQ90uRtrCy_ZyX8ZkEDBQDXh7uuaNvYmTMCCBB86i_OGFLkvAQlUoxKTfnr8QHa5JR2SjNg9Q5ZBOzNB6RslRLT0UH8TiKuEOmRYYR-f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

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.