Skip to content

Commit 7645a6e

Browse files
committed
Merge remote-tracking branch 'origin/testing' into oldIsNewAgain
2 parents 31567e4 + e544baf commit 7645a6e

36 files changed

Lines changed: 484 additions & 80 deletions

.github/workflows/formatter.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: ["3.10", "3.11", "3.12"]
12+
python-version: [ "3.10", "3.11", "3.12" ]
1313
steps:
14-
- uses: actions/checkout@v4
15-
- name: Set up Python ${{ matrix.python-version }}
16-
uses: actions/setup-python@v3
17-
with:
18-
python-version: ${{ matrix.python-version }}
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install black
23-
- name: Formatting the code with black
24-
run: |
25-
black $(git ls-files '*.py')
14+
- uses: actions/checkout@v4
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v3
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install black
23+
- name: Formatting the code with black
24+
run: |
25+
black $(git ls-files '*.py')

.github/workflows/pylint.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
name: Pylint
22
run-name: Pylint Checker 🐧
3-
on: [push]
3+
on: [ push ]
44
jobs:
55
build:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
python-version: ["3.10", "3.11", "3.12"]
9+
python-version: [ "3.10", "3.11", "3.12" ]
1010
steps:
11-
- uses: actions/checkout@v4
12-
- name: Set up Python ${{ matrix.python-version }}
13-
uses: actions/setup-python@v3
14-
with:
15-
python-version: ${{ matrix.python-version }}
16-
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip
19-
pip install -r ./api/requirements_dev.txt
20-
- name: Analysing the code with pylint
21-
run: |
22-
pylint $(git ls-files '*.py')
11+
- uses: actions/checkout@v4
12+
- name: Set up Python ${{ matrix.python-version }}
13+
uses: actions/setup-python@v3
14+
with:
15+
python-version: ${{ matrix.python-version }}
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install -r ./api/requirements.txt
20+
pip install -r ./api/utils.txt
21+
- name: Analysing the code with pylint
22+
run: |
23+
pylint $(git ls-files '*.py')

api/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
API_MODE=dev
2+
DB=relational

api/auth/controller.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from api.database.db import db
2+
3+
4+
def create_account(username, numeric_identifier, auth_level='student'):
5+
account_id = db.create_account(username, numeric_identifier)
6+
return account_id

api/auth/routes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
blueprint = Blueprint("auth", __name__)
66

7+
78
@blueprint.route("/login", methods=["POST"])
89
def login():
910
"""Checks if the current user has the right credentials to log in
@@ -29,3 +30,7 @@ def signup():
2930
The status of the sign-up attempt
3031
"""
3132
return "Signup arrived"
33+
34+
# TODO: update preferred name
35+
36+
# TODO: accounts has UBIT (For AL lookups) and pn (For card swipes)

api/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class Config:
7-
"""Configuration class for MOJ api server, stores current configuration state of flask api"""
7+
"""Configuration class for MOH api server, stores current configuration state of flask api"""
88

99
def __init__(self):
1010
self.API_MODE = os.getenv("API_MODE", "Can not find mode")

api/database/db.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
3+
from api.database.relational_db.relational_db import RelationalDB
4+
from api.database.testing_db.testing_db import TestingDB
5+
from api.database.mock_db.mock_db import MockDB
6+
7+
8+
def create_db():
9+
db_type = os.getenv("DB")
10+
match db_type:
11+
case "relational":
12+
return RelationalDB()
13+
case "testing":
14+
return TestingDB()
15+
case "mock":
16+
return MockDB()
17+
case None:
18+
raise EnvironmentError("environment variable \"DB\" not set")
19+
case _:
20+
raise ModuleNotFoundError("Could not find database named " + db_type)
21+
22+
23+
db = create_db()

api/database/db_interface.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from abc import ABC, abstractmethod
2+
3+
from api.database.idb_queue import IQueue
4+
from api.database.idb_ratings import IRatings
5+
from api.database.idb_accounts import IAccounts
6+
from api.database.idb_roster import IRoster
7+
8+
9+
class DBInterface(IQueue, IRatings, IAccounts, IRoster, ABC):
10+
11+
# All database implements must extend this class
12+
13+
def __init__(self):
14+
super().__init__()
15+
16+
@abstractmethod
17+
def connect(self):
18+
pass

api/database/idb_accounts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class IAccounts(ABC):
5+
6+
def __init__(self):
7+
super().__init__()
8+
9+
@abstractmethod
10+
def create_account(self, ubit, pn):
11+
# Creates an account with the provided ubit and pn. Generates, and returns, a unique id for the new account
12+
raise NotImplementedError()

api/database/idb_queue.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class IQueue(ABC):
5+
6+
def __init__(self):
7+
super().__init__()
8+
9+
@abstractmethod
10+
def enqueue_student(self, student):
11+
raise NotImplementedError()
12+
13+
@abstractmethod
14+
def dequeue_student(self):
15+
raise NotImplementedError()

0 commit comments

Comments
 (0)