-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from DoodleyJC/dev
Database connection and betting endpoint update
- Loading branch information
Showing
17 changed files
with
158 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,6 @@ build | |
next-env.d.ts | ||
|
||
# Python | ||
*.pyc | ||
*.pyc | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .controller import betting_api | ||
|
||
__all__=["betting_api"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from flask import Blueprint, jsonify, request, render_template, Response | ||
|
||
from api.consts import COMMON_API_PREFIX | ||
import api.model.betting | ||
|
||
betting_api = Blueprint("betting_api", __name__, url_prefix=COMMON_API_PREFIX + "/betting", | ||
template_folder="templates") | ||
|
||
|
||
@betting_api.route("/", methods=["GET"]) | ||
def get_collections(): | ||
try: | ||
responseobject = api.model.betting.getAll() | ||
return jsonify(responseobject) | ||
except Exception as e: | ||
print(e) | ||
return Response("something went wrong", 500) | ||
|
||
|
||
|
||
@betting_api.route("/", methods=["POST", "PUT"]) | ||
def handle_post(): | ||
if request.method == "POST": | ||
try: | ||
content = request.json | ||
userid = content["userid"] | ||
matchid = content["matchid"] | ||
teamid = content["teamid"] | ||
amount = content["amount"] | ||
except Exception as e: | ||
print(e) | ||
return Response(f"""content_type="bad request, please supply the following: \"user\", \"matchid\", \"teamid\"and \"amount\" | ||
in json form with a content-type json header""" | ||
, 400) | ||
try: | ||
print(f"userid = {userid}, matchid={matchid}, teamid{teamid}, amount={amount}") | ||
api.model.betting.insertBet(userid, matchid, teamid, amount) | ||
return Response("inserted", 200) | ||
except Exception as e: | ||
print(e) | ||
return Response(f"""something went wrong with inserting the bet in the database""" | ||
, 500) | ||
else: | ||
return Response("Only posts are allowed right now", 400) | ||
|
||
@betting_api.route("/datatest", methods=["GET", "POST", "PUT"]) | ||
def handle_test(): | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
|
||
</head> | ||
<body> | ||
<p> this request type is not allowed, only post</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
|
||
</head> | ||
<body> | ||
<p> Placeholder</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from .main import * | ||
import psycopg2 | ||
|
||
__all__ = ["insertBet", "removeBet"] | ||
|
||
|
||
createTableString = """ | ||
CREATE TABLE bettingtest ( | ||
id SERIAL PRIMARY KEY, | ||
userid VARCHAR, | ||
matchid INT, | ||
teamid INT, | ||
amount FLOAT | ||
); | ||
""" | ||
|
||
def __init__(): | ||
with datacon.cursor() as curs: | ||
try: | ||
curs.execute(createTableString) | ||
except psycopg2.errors.DuplicateTable as e: | ||
print("duplicate table encountered") | ||
pass | ||
|
||
__init__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import psycopg2 | ||
import api.model.database as data | ||
|
||
datacon = data.bettingconn | ||
datacon.autocommit=True | ||
|
||
def insertBet(userid, matchid, teamid, amount): | ||
with datacon.cursor() as curs: | ||
curs.execute(f"""INSERT INTO bettingtest (userid, matchid, teamid, amount) | ||
VALUES ({userid},{matchid},{teamid},{amount});""") | ||
|
||
def getAll(): | ||
with datacon.cursor() as curs: | ||
curs.execute(""" | ||
SELECT * FROM bettingtest; | ||
""") | ||
res = curs.fetchall() | ||
return res | ||
|
||
def removeBet(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .main import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import psycopg2 | ||
bettingconn = psycopg2.connect(host="db", user="postgres", password="postgres", dbname="retroolympics") | ||
bettingconn.autocommit=True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Flask==3.0.3 | ||
Flask==3.0.3 | ||
Psycopg2==2.9.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pip install invoke | ||
pip install -r backend/requirements-combined.txt |