Skip to content

Commit

Permalink
Merge branch 'frontend' of github.com:DoodleyJC/RetroOlympics into fr…
Browse files Browse the repository at this point in the history
…ontend
  • Loading branch information
DaiseyD committed Jul 21, 2024
2 parents db2ecc1 + a5eecf8 commit ad1076d
Show file tree
Hide file tree
Showing 28 changed files with 785 additions and 396 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"ms-python.isort",
"charliermarsh.ruff"
"charliermarsh.ruff",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}
},
Expand Down
13 changes: 11 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ services:
dockerfile: Dockerfile
entrypoint: ["tail", "-f", "/dev/null"]
volumes:
- ../..:/workspaces:cached
- ..:/workspaces:cached
command: sleep infinity
network_mode: service:db
#network_mode: service:db
ports:
- "8000:5000"
depends_on:
- db
db:
image: postgres:16-alpine
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: retroolympics
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "8001:5432"

volumes:
postgres-data:
1 change: 1 addition & 0 deletions .github/workflows/labeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ jobs:
steps:
- uses: actions/labeler@v5
with:
repo-token: ${{ secrets.LABELER_TOKEN }}
configuration-path: .github/labeler.yaml
53 changes: 53 additions & 0 deletions .github/workflows/node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Node.js CI

on:
pull_request:
types: [opened, labeled, synchronize]
branches: main

defaults:
run:
working-directory: ./frontend

jobs:
lint:
if: contains(github.event.pull_request.labels.*.name, 'frontend')
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: "./frontend/package.json"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: "./frontend/.nvmrc"
cache: pnpm
cache-dependency-path: "./frontend/pnpm-lock.yaml"
- name: Install dependencies
run: pnpm install
- name: Run lint
run: pnpm lint
build:
if: contains(github.event.pull_request.labels.*.name, 'frontend')
runs-on: ubuntu-latest
needs: [lint]
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: "./frontend/package.json"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: "./frontend/.nvmrc"
cache: pnpm
cache-dependency-path: "./frontend/pnpm-lock.yaml"
- name: Install dependencies
run: pnpm install
- name: Run build
run: pnpm build
30 changes: 30 additions & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python CI

on:
pull_request:
types: [opened, labeled, synchronize]
branches: main

defaults:
run:
working-directory: ./backend

jobs:
check-code-quality:
if: contains(github.event.pull_request.labels.*.name, 'backend')
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements-combined.txt
- name: Run lint with ruff
run: ruff .
- name: Check formatting with black
run: black --check .
- name: Check imports with isort
run: isort --check .
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ build
next-env.d.ts

# Python
*.pyc
*.pyc

.env
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
"source.organizeImports": "always"
}
},
"[javascript][typescript][typescriptreact][tailwindcss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
},
"isort.args": ["--profile", "black"],
"ruff.nativeServer": true
}
3 changes: 3 additions & 0 deletions backend/api/components/betting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .controller import betting_api

__all__ = ["betting_api"]
54 changes: 54 additions & 0 deletions backend/api/components/betting/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from flask import Blueprint, Response, jsonify, request

from api.consts import COMMON_API_PREFIX
from api.model.betting import getAll, insertBet

betting_api = Blueprint(
"betting_api", __name__, url_prefix=COMMON_API_PREFIX + "/betting"
)


@betting_api.route("/", methods=["GET"])
def get_collections():
try:
responseobject = 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(
"""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}"
)
insertBet(userid, matchid, teamid, amount)
return Response("inserted", 200)
except Exception as e:
print(e)
return Response(
"""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
2 changes: 2 additions & 0 deletions backend/api/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask

from api.components.betting import betting_api
from api.components.hello import hello_api

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

api.register_blueprint(hello_api)
api.register_blueprint(betting_api)

return api
28 changes: 28 additions & 0 deletions backend/api/model/betting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import psycopg2

from .main import datacon, getAll, insertBet, removeBet

__all__ = ["insertBet", "removeBet", "getAll"]


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:
print("duplicate table encountered")
pass


__init__()
26 changes: 26 additions & 0 deletions backend/api/model/betting/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from api.model.database import bettingconn as datacon

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
3 changes: 3 additions & 0 deletions backend/api/model/database/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .main import bettingconn

__all__ = ["bettingconn"]
6 changes: 6 additions & 0 deletions backend/api/model/database/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import psycopg2

bettingconn = psycopg2.connect(
host="db", user="postgres", password="postgres", dbname="retroolympics"
)
bettingconn.autocommit = True
20 changes: 13 additions & 7 deletions backend/requirements-combined.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=backend/requirements-combined.txt backend/requirements-dev.in backend/requirements.in
# pip-compile --output-file=requirements-combined.txt requirements-dev.in requirements.in
#
black==24.4.2
# via -r backend/requirements-dev.in
# via -r requirements-dev.in
blinker==1.8.2
# via flask
build==1.2.1
Expand All @@ -15,12 +15,16 @@ click==8.1.7
# black
# flask
# pip-tools
colorama==0.4.6
# via
# build
# click
flask==3.0.3
# via -r backend/requirements.in
# via -r requirements.in
invoke==2.2.0
# via -r backend/requirements-dev.in
# via -r requirements-dev.in
isort==5.13.2
# via -r backend/requirements-dev.in
# via -r requirements-dev.in
itsdangerous==2.2.0
# via flask
jinja2==3.1.4
Expand All @@ -38,15 +42,17 @@ packaging==24.1
pathspec==0.12.1
# via black
pip-tools==7.4.1
# via -r backend/requirements-dev.in
# via -r requirements-dev.in
platformdirs==4.2.2
# via black
psycopg2==2.9.9
# via -r requirements.in
pyproject-hooks==1.1.0
# via
# build
# pip-tools
ruff==0.4.9
# via -r backend/requirements-dev.in
# via -r requirements-dev.in
werkzeug==3.0.3
# via flask
wheel==0.43.0
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.in
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
6 changes: 4 additions & 2 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile backend/requirements.in
# pip-compile requirements.in
#
blinker==1.8.2
# via flask
click==8.1.7
# via flask
colorama==0.4.6
# via click
flask==3.0.3
# via -r backend/requirements.in
# via -r requirements.in
itsdangerous==2.2.0
# via flask
jinja2==3.1.4
Expand Down
4 changes: 2 additions & 2 deletions backend/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def update_app_reqs(c):
@task
def update_combined_reqs(c):
c.run(
"pip-compile backend/requirements.in backend/requirements-dev.in -o backend/requirements-combined.txt"
"pip-compile requirements.in requirements-dev.in -o requirements-combined.txt"
)


# Run
@task
def run_back(c):
get_api().run()
get_api().run("0.0.0.0")
3 changes: 3 additions & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.next
pnpm-lock.yaml
public
4 changes: 4 additions & 0 deletions frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"plugins": ["prettier-plugin-tailwindcss"]
}
Loading

0 comments on commit ad1076d

Please sign in to comment.