Skip to content

Commit ad1076d

Browse files
committed
Merge branch 'frontend' of github.com:DoodleyJC/RetroOlympics into frontend
2 parents db2ecc1 + a5eecf8 commit ad1076d

28 files changed

+785
-396
lines changed

.devcontainer/devcontainer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
"ms-python.vscode-pylance",
1818
"ms-python.black-formatter",
1919
"ms-python.isort",
20-
"charliermarsh.ruff"
20+
"charliermarsh.ruff",
21+
"dbaeumer.vscode-eslint",
22+
"esbenp.prettier-vscode",
23+
"bradlc.vscode-tailwindcss"
2124
]
2225
}
2326
},

.devcontainer/docker-compose.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@ services:
77
dockerfile: Dockerfile
88
entrypoint: ["tail", "-f", "/dev/null"]
99
volumes:
10-
- ../..:/workspaces:cached
10+
- ..:/workspaces:cached
1111
command: sleep infinity
12-
network_mode: service:db
12+
#network_mode: service:db
13+
ports:
14+
- "8000:5000"
15+
depends_on:
16+
- db
1317
db:
1418
image: postgres:16-alpine
1519
restart: unless-stopped
1620
volumes:
1721
- postgres-data:/var/lib/postgresql/data
1822
environment:
1923
POSTGRES_HOST_AUTH_METHOD: trust
24+
POSTGRES_DB: retroolympics
25+
POSTGRES_USER: postgres
26+
POSTGRES_PASSWORD: postgres
27+
ports:
28+
- "8001:5432"
2029

2130
volumes:
2231
postgres-data:

.github/workflows/labeler.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ jobs:
1111
steps:
1212
- uses: actions/labeler@v5
1313
with:
14+
repo-token: ${{ secrets.LABELER_TOKEN }}
1415
configuration-path: .github/labeler.yaml

.github/workflows/node.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Node.js CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, labeled, synchronize]
6+
branches: main
7+
8+
defaults:
9+
run:
10+
working-directory: ./frontend
11+
12+
jobs:
13+
lint:
14+
if: contains(github.event.pull_request.labels.*.name, 'frontend')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/[email protected]
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
with:
22+
package_json_file: "./frontend/package.json"
23+
- name: Setup Node
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version-file: "./frontend/.nvmrc"
27+
cache: pnpm
28+
cache-dependency-path: "./frontend/pnpm-lock.yaml"
29+
- name: Install dependencies
30+
run: pnpm install
31+
- name: Run lint
32+
run: pnpm lint
33+
build:
34+
if: contains(github.event.pull_request.labels.*.name, 'frontend')
35+
runs-on: ubuntu-latest
36+
needs: [lint]
37+
steps:
38+
- name: Checkout repo
39+
uses: actions/[email protected]
40+
- name: Setup pnpm
41+
uses: pnpm/action-setup@v4
42+
with:
43+
package_json_file: "./frontend/package.json"
44+
- name: Setup Node
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version-file: "./frontend/.nvmrc"
48+
cache: pnpm
49+
cache-dependency-path: "./frontend/pnpm-lock.yaml"
50+
- name: Install dependencies
51+
run: pnpm install
52+
- name: Run build
53+
run: pnpm build

.github/workflows/python.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Python CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, labeled, synchronize]
6+
branches: main
7+
8+
defaults:
9+
run:
10+
working-directory: ./backend
11+
12+
jobs:
13+
check-code-quality:
14+
if: contains(github.event.pull_request.labels.*.name, 'backend')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/[email protected]
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
- name: Install dependencies
24+
run: pip install -r requirements-combined.txt
25+
- name: Run lint with ruff
26+
run: ruff .
27+
- name: Check formatting with black
28+
run: black --check .
29+
- name: Check imports with isort
30+
run: isort --check .

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ build
2020
next-env.d.ts
2121

2222
# Python
23-
*.pyc
23+
*.pyc
24+
25+
.env

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
"source.organizeImports": "always"
1717
}
1818
},
19+
"[javascript][typescript][typescriptreact][tailwindcss]": {
20+
"editor.defaultFormatter": "esbenp.prettier-vscode",
21+
"editor.formatOnSave": true,
22+
"editor.codeActionsOnSave": {
23+
"source.fixAll": "always",
24+
"source.organizeImports": "always"
25+
},
26+
},
1927
"isort.args": ["--profile", "black"],
2028
"ruff.nativeServer": true
2129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .controller import betting_api
2+
3+
__all__ = ["betting_api"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from flask import Blueprint, Response, jsonify, request
2+
3+
from api.consts import COMMON_API_PREFIX
4+
from api.model.betting import getAll, insertBet
5+
6+
betting_api = Blueprint(
7+
"betting_api", __name__, url_prefix=COMMON_API_PREFIX + "/betting"
8+
)
9+
10+
11+
@betting_api.route("/", methods=["GET"])
12+
def get_collections():
13+
try:
14+
responseobject = getAll()
15+
return jsonify(responseobject)
16+
except Exception as e:
17+
print(e)
18+
return Response("something went wrong", 500)
19+
20+
21+
@betting_api.route("/", methods=["POST", "PUT"])
22+
def handle_post():
23+
if request.method == "POST":
24+
try:
25+
content = request.json
26+
userid = content["userid"]
27+
matchid = content["matchid"]
28+
teamid = content["teamid"]
29+
amount = content["amount"]
30+
except Exception as e:
31+
print(e)
32+
return Response(
33+
"""content_type="bad request, please supply the following: \"user\", \"matchid\", \"teamid\"and \"amount\"
34+
in json form with a content-type json header""",
35+
400,
36+
)
37+
try:
38+
print(
39+
f"userid = {userid}, matchid={matchid}, teamid{teamid}, amount={amount}"
40+
)
41+
insertBet(userid, matchid, teamid, amount)
42+
return Response("inserted", 200)
43+
except Exception as e:
44+
print(e)
45+
return Response(
46+
"""something went wrong with inserting the bet in the database""", 500
47+
)
48+
else:
49+
return Response("Only posts are allowed right now", 400)
50+
51+
52+
@betting_api.route("/datatest", methods=["GET", "POST", "PUT"])
53+
def handle_test():
54+
pass

backend/api/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import Flask
22

3+
from api.components.betting import betting_api
34
from api.components.hello import hello_api
45

56
api: Flask | None = None
@@ -11,5 +12,6 @@ def get_api() -> Flask:
1112
api = Flask(__name__)
1213

1314
api.register_blueprint(hello_api)
15+
api.register_blueprint(betting_api)
1416

1517
return api

backend/api/model/betting/__init__.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import psycopg2
2+
3+
from .main import datacon, getAll, insertBet, removeBet
4+
5+
__all__ = ["insertBet", "removeBet", "getAll"]
6+
7+
8+
createTableString = """
9+
CREATE TABLE bettingtest (
10+
id SERIAL PRIMARY KEY,
11+
userid VARCHAR,
12+
matchid INT,
13+
teamid INT,
14+
amount FLOAT
15+
);
16+
"""
17+
18+
19+
def __init__():
20+
with datacon.cursor() as curs:
21+
try:
22+
curs.execute(createTableString)
23+
except psycopg2.errors.DuplicateTable:
24+
print("duplicate table encountered")
25+
pass
26+
27+
28+
__init__()

backend/api/model/betting/main.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from api.model.database import bettingconn as datacon
2+
3+
datacon.autocommit = True
4+
5+
6+
def insertBet(userid, matchid, teamid, amount):
7+
with datacon.cursor() as curs:
8+
curs.execute(
9+
f"""INSERT INTO bettingtest (userid, matchid, teamid, amount)
10+
VALUES ({userid},{matchid},{teamid},{amount});"""
11+
)
12+
13+
14+
def getAll():
15+
with datacon.cursor() as curs:
16+
curs.execute(
17+
"""
18+
SELECT * FROM bettingtest;
19+
"""
20+
)
21+
res = curs.fetchall()
22+
return res
23+
24+
25+
def removeBet():
26+
pass
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .main import bettingconn
2+
3+
__all__ = ["bettingconn"]

backend/api/model/database/main.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import psycopg2
2+
3+
bettingconn = psycopg2.connect(
4+
host="db", user="postgres", password="postgres", dbname="retroolympics"
5+
)
6+
bettingconn.autocommit = True

backend/requirements-combined.txt

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# This file is autogenerated by pip-compile with Python 3.12
33
# by the following command:
44
#
5-
# pip-compile --output-file=backend/requirements-combined.txt backend/requirements-dev.in backend/requirements.in
5+
# pip-compile --output-file=requirements-combined.txt requirements-dev.in requirements.in
66
#
77
black==24.4.2
8-
# via -r backend/requirements-dev.in
8+
# via -r requirements-dev.in
99
blinker==1.8.2
1010
# via flask
1111
build==1.2.1
@@ -15,12 +15,16 @@ click==8.1.7
1515
# black
1616
# flask
1717
# pip-tools
18+
colorama==0.4.6
19+
# via
20+
# build
21+
# click
1822
flask==3.0.3
19-
# via -r backend/requirements.in
23+
# via -r requirements.in
2024
invoke==2.2.0
21-
# via -r backend/requirements-dev.in
25+
# via -r requirements-dev.in
2226
isort==5.13.2
23-
# via -r backend/requirements-dev.in
27+
# via -r requirements-dev.in
2428
itsdangerous==2.2.0
2529
# via flask
2630
jinja2==3.1.4
@@ -38,15 +42,17 @@ packaging==24.1
3842
pathspec==0.12.1
3943
# via black
4044
pip-tools==7.4.1
41-
# via -r backend/requirements-dev.in
45+
# via -r requirements-dev.in
4246
platformdirs==4.2.2
4347
# via black
48+
psycopg2==2.9.9
49+
# via -r requirements.in
4450
pyproject-hooks==1.1.0
4551
# via
4652
# build
4753
# pip-tools
4854
ruff==0.4.9
49-
# via -r backend/requirements-dev.in
55+
# via -r requirements-dev.in
5056
werkzeug==3.0.3
5157
# via flask
5258
wheel==0.43.0

backend/requirements.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Flask==3.0.3
1+
Flask==3.0.3
2+
Psycopg2==2.9.9

backend/requirements.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# This file is autogenerated by pip-compile with Python 3.12
33
# by the following command:
44
#
5-
# pip-compile backend/requirements.in
5+
# pip-compile requirements.in
66
#
77
blinker==1.8.2
88
# via flask
99
click==8.1.7
1010
# via flask
11+
colorama==0.4.6
12+
# via click
1113
flask==3.0.3
12-
# via -r backend/requirements.in
14+
# via -r requirements.in
1315
itsdangerous==2.2.0
1416
# via flask
1517
jinja2==3.1.4

backend/tasks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def update_app_reqs(c):
1212
@task
1313
def update_combined_reqs(c):
1414
c.run(
15-
"pip-compile backend/requirements.in backend/requirements-dev.in -o backend/requirements-combined.txt"
15+
"pip-compile requirements.in requirements-dev.in -o requirements-combined.txt"
1616
)
1717

1818

1919
# Run
2020
@task
2121
def run_back(c):
22-
get_api().run()
22+
get_api().run("0.0.0.0")

frontend/.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.next
2+
pnpm-lock.yaml
3+
public

frontend/.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 120,
3+
"plugins": ["prettier-plugin-tailwindcss"]
4+
}

0 commit comments

Comments
 (0)