Skip to content

abelbarreto-dev/better-bet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Better Bet

API to control bets, lost and winnings. So with that and a database, you'll can control your bets better. Then you'll can filter and compare previous bet profits for you. The only thing you need is to create an account.

Summary

  1. Dependencies
    1. Python and Pip
    2. FastAPI
    3. Peewee
  2. How To Run
  3. How To Test
    1. Run Specific Tests
    2. Run All Tests
  4. Models
    1. Login
    2. Single Bet
    3. Multi Bet
  5. Models of Body
    1. BetPatchBody
    2. DateFromToBody
    3. DateFilterBody
  6. Project Structure
    1. Source Package
    2. Test Package
  7. API Routes
  8. Database Relationship
  9. FAQ

Dependencies

Here you'll see the list of dependencies from this project.

  1. Python and Pip here and here language and package install resource
  2. FastAPI here used to build API Rest
  3. Peewee here used as a ORM
  4. Uvicorn here used as a server to access this API

Note: you can install uvicorn searching for install it by pip from FastAPI website.

How To Run?

Before you run this project, you need to check if all dependencies are installed and access FAQ to set the file settings.json and .env configurations.

To run this project, after you have made what was described here, you need to run the following command:

uvicorn main:app --reload

How To Test?

To run unit tests here you need to check what is described at How to Run topic. After you have two options:

  1. Access the package test then you have two options:
    1. controller the endpoints tests
    2. repository the persistence tests
  2. Run the following command in root dir for run all tests:
    1. pytest
      

Models

Bellow you can see our methods.

Login

{
   "player_name": "string",
   "username": "string",
   "password": "string"
}

SingleBet

{
   "id_login": 0,
   "home_team": "string", 
   "away_team": "string", 
   "team_bet": "string", 
   "odd": "1.00"
   "value_invest": "1.00"
   "profit": "1.00",
   "bet_status": "success"
}

MultiBet

{
   "id_login": 0,
   "home_team": "string", 
   "away_team": "string", 
   "team_bet": "string", 
   "list_odds": [
      "1.00"
   ],
   "value_invest": "1.00"
   "profit": "1.00",
   "bet_status": "success"
}

Models of Body

Bodies to use as a custom JSON to make API operations.

BetPatchBody

{
   "id": 0,
   "bet_status": "string",
}

DateFromToBody

{
   "login_id": 0,
   "date_from": "2023-05-24",
   "date_to": null
}

DateFilterBody

{
   "login_id": 0,
   "date_from": null,
   "date_to": null
}

Project Structure

Here you can see the project tree for source and tests folders. I used the structure of a html code. Each tag means a package.

Source Package

<src>
   <api>
      <app>
         __init__.py
         app.py
      </app>
      <application>
         __init__.py
         application.py
      </application>
      <controller>
         __init__.py
         controller.py
      </controller>
      <data>
         __init__.py
         data_model.py
      </data>
      <models>
         __init__.py
         api_models.py
         request_body.py
      </models>
      <repository>
         __init__.py
      </repository>
      <routes>
         __init__.py
         routes.py
      </routes>
      __init__.py
   </api>
   <utils>
      __init__.py
      bet_status.py
      checker.py
      connection.py
      create_tables.py
      exceptions.py
      types_utils.py
   </utils>
   __init__.py
</src>

Test Package

<test>
   <api>
      <controller>
         __init__.py
         test_login_controller.py
         test_single_bet_controller.py
         test_multi_bet_controller.py
      </controller>
      <repository>
         __init__.py
      </repository>
      <utils>
         __init__.py
         get_auth_headers.py
         login_opps.py
      </utils>
      __init__.py
   </api>
   __init__.py
   conftest.py
</test>

API Routes

Here I present our routes for this API. It will be in JSON format.

{
    "post_login": "/login",
    "post_login_auth": "/login/auth",
    "post_single_bet": "/bet/single",
    "post_multi_bet": "/bet/multi",
    "patch_single_bet": "/bet/single",
    "patch_multi_bet": "/bet/multi",
    "get_filter_single": "/get/bet/single",
    "get_filter_multi": "/get/bet/multi",
    "get_profits_single": "/bet/single/profits",
    "get_profits_multi": "/bet/multi/profits",
    "get_lost_single": "/bet/single/lost",
    "get_lost_multi": "/bet/multi/lost",
    "get_all_profits": "/bet/profits/{id_login}/all",
    "get_all_lost": "/bet/lost/{id_login}/all",
    "post_compound_interest": "/compound-interest"
}

So we can see the name and the link to each endpoint at this API.

Database Relationship

The main class of this project is named Login. So we have others 2 (two) database entities, SingleBet and MultiBet. Both are independent, but both is linked to Login.

                        [ Login ]
                     ___/       \___                        Login <> SingleBet
                 ___/               \___                    Login <> MultiBet
             ___/                       \___
            /                               \
      SingleBet                           MultiBet

FAQ

At this point, we select common questions to answer.

How to create a file settings.json?

Note: it must be at project's root directory.

After, paste the following text: {"database": "staging"}

How to set the file .env?

At root directory, you will find the file .env.example. Copy it and rename to .env, so open and sets the information required there.

  • DATABASE_HOST
  • DATABASE_PORT
  • DATABASE_NAME
  • DATABASE_USER
  • DATABASE_PASSWD

You need to fill these variables.

How the module set_config.py works?

This module has functions to use as a switch between databases as part of this file to change the database between staging, production and testing.

What's the field potential_earnings?

This field represents the earnings without the operator_fee.

What's the field total_amount?

This field represents the real earning after apply the operator_fee.

What's the field profit?

This field represents the profit of operation or the value_invest * odd

Back to Start

About

API to control bets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages