added new endpoints, implemented db singleton, started on requests manager api
This commit is contained in:
parent
ed3b8d36cc
commit
11d4a866ef
13 changed files with 116 additions and 12 deletions
|
@ -12,6 +12,6 @@ backend-pylint:
|
||||||
- pip install -r requirements.txt --disable-pip-version-check -q
|
- pip install -r requirements.txt --disable-pip-version-check -q
|
||||||
- pip install pylint --disable-pip-version-check -q
|
- pip install pylint --disable-pip-version-check -q
|
||||||
- python --version
|
- python --version
|
||||||
- python -m pip list --format=columns
|
- python -m pip list --format=columns --disable-pip-version-check
|
||||||
script:
|
script:
|
||||||
- pylint src/* --fail-under 9
|
- pylint src/* --fail-under 9
|
|
@ -1,4 +1,5 @@
|
||||||
flask~=2.3.3
|
flask~=2.3.3
|
||||||
flask-smorest~=0.42.1
|
flask-smorest~=0.42.1
|
||||||
marshmallow~=3.20.1
|
marshmallow~=3.20.1
|
||||||
gevent~=23.9.1
|
gevent~=23.9.1
|
||||||
|
dictdatabase~=2.4.6
|
|
@ -1,2 +0,0 @@
|
||||||
[server]
|
|
||||||
port=5000
|
|
5
backend/src/config/db_settings.py
Normal file
5
backend/src/config/db_settings.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
import os
|
||||||
|
|
||||||
|
class DatabaseSettings:
|
||||||
|
DATABASE_DIRECTORY = f"{os.getcwd()}/database/storage"
|
5
backend/src/config/server_settings.py
Normal file
5
backend/src/config/server_settings.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
|
||||||
|
class ServerSettings:
|
||||||
|
HOSTNAME = "localhost"
|
||||||
|
PORT = 5000
|
1
backend/src/database/__init__.py
Normal file
1
backend/src/database/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .database import Database
|
26
backend/src/database/database.py
Normal file
26
backend/src/database/database.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
|
||||||
|
import dictdatabase as DDB
|
||||||
|
from config.db_settings import DatabaseSettings
|
||||||
|
|
||||||
|
class IsSingletonException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Database:
|
||||||
|
"""
|
||||||
|
This is a singleton that can be accessed using get_instance()
|
||||||
|
"""
|
||||||
|
__instance = None
|
||||||
|
db = DDB
|
||||||
|
db.config.storage_directory = DatabaseSettings.DATABASE_DIRECTORY
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_instance():
|
||||||
|
if Database.__instance is None:
|
||||||
|
Database()
|
||||||
|
return Database.__instance
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
if Database.__instance is not None:
|
||||||
|
raise IsSingletonException("This class is a singleton")
|
||||||
|
Database.__instance = self
|
2
backend/src/database/storage/.gitignore
vendored
Normal file
2
backend/src/database/storage/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*
|
||||||
|
!.gitignore
|
6
backend/src/routes/requests/__init__.py
Normal file
6
backend/src/routes/requests/__init__.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# pylint: disable=wrong-import-position,cyclic-import
|
||||||
|
from flask_smorest import Blueprint
|
||||||
|
|
||||||
|
routes_requests = Blueprint("requests", "requests", url_prefix="/requests", description="")
|
||||||
|
|
||||||
|
from . import base, create, interact # avoids circular imports problem
|
18
backend/src/routes/requests/base.py
Normal file
18
backend/src/routes/requests/base.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from flask.views import MethodView
|
||||||
|
import marshmallow as ma
|
||||||
|
|
||||||
|
from app import Application
|
||||||
|
from . import routes_requests as blp
|
||||||
|
|
||||||
|
instance = Application.get_instance()
|
||||||
|
|
||||||
|
class RequestsGetAll(ma.Schema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@blp.route("/all")
|
||||||
|
class AllRequests(MethodView):
|
||||||
|
@blp.doc(summary="Returns all requests")
|
||||||
|
@blp.response(200, RequestsGetAll, description="Successful operation")
|
||||||
|
def get(self):
|
||||||
|
response = {}
|
||||||
|
return response
|
18
backend/src/routes/requests/create.py
Normal file
18
backend/src/routes/requests/create.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from flask.views import MethodView
|
||||||
|
import marshmallow as ma
|
||||||
|
|
||||||
|
from app import Application
|
||||||
|
from . import routes_requests as blp
|
||||||
|
|
||||||
|
instance = Application.get_instance()
|
||||||
|
|
||||||
|
class RequestsCreate(ma.Schema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@blp.route("/create")
|
||||||
|
class CreateRequest(MethodView):
|
||||||
|
@blp.doc(summary="Create a new request")
|
||||||
|
@blp.response(200, RequestsCreate, description="Successful operation")
|
||||||
|
def post(self):
|
||||||
|
response = {}
|
||||||
|
return response
|
24
backend/src/routes/requests/interact.py
Normal file
24
backend/src/routes/requests/interact.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from flask.views import MethodView
|
||||||
|
import marshmallow as ma
|
||||||
|
|
||||||
|
from app import Application
|
||||||
|
from . import routes_requests as blp
|
||||||
|
|
||||||
|
instance = Application.get_instance()
|
||||||
|
|
||||||
|
class RequestsInteraction(ma.Schema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@blp.route("/<uuid>")
|
||||||
|
class InteractRequest(MethodView):
|
||||||
|
@blp.doc(summary="Returns a specific request by its UID")
|
||||||
|
@blp.response(200, RequestsInteraction, description="Successful operation")
|
||||||
|
def get(self):
|
||||||
|
response = {}
|
||||||
|
return response
|
||||||
|
|
||||||
|
@blp.doc(summary="Deletes a specific request by its UID")
|
||||||
|
@blp.response(200, RequestsInteraction, description="Successful operation")
|
||||||
|
def delete(self):
|
||||||
|
response = {}
|
||||||
|
return response
|
|
@ -1,26 +1,26 @@
|
||||||
# pylint: disable=multiple-statements,wrong-import-position,wrong-import-order
|
# pylint: disable=multiple-statements,wrong-import-position,wrong-import-order
|
||||||
from gevent.monkey import patch_all; patch_all()
|
from gevent.monkey import patch_all; patch_all()
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
import configparser
|
|
||||||
|
|
||||||
from app import Application
|
from app import Application
|
||||||
from routes import routes
|
from routes import routes
|
||||||
|
from routes.requests import routes_requests
|
||||||
|
from config.server_settings import ServerSettings
|
||||||
|
|
||||||
instance = Application.get_instance()
|
instance = Application.get_instance()
|
||||||
app = instance.app
|
app = instance.app
|
||||||
api = instance.api
|
api = instance.api
|
||||||
api.register_blueprint(routes)
|
api.register_blueprint(routes)
|
||||||
|
api.register_blueprint(routes_requests)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
HOSTNAME = ServerSettings.HOSTNAME
|
||||||
config.read('config/config.ini')
|
PORT = ServerSettings.PORT
|
||||||
|
|
||||||
port = int(config['server']['port']) or 5000
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
http_Server = WSGIServer(("127.0.0.1", port), app)
|
http_Server = WSGIServer((HOSTNAME, PORT), app)
|
||||||
try:
|
try:
|
||||||
print(f"Server available on http://127.0.0.1:{port}/")
|
print(f"Server available on http://{HOSTNAME}:{PORT}/")
|
||||||
print(f"View docs on http://127.0.0.1:{port}/swagger")
|
print(f"View docs on http://{HOSTNAME}:{PORT}/swagger")
|
||||||
http_Server.serve_forever()
|
http_Server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Keyboard interrupt received, stopping...")
|
print("Keyboard interrupt received, stopping...")
|
||||||
|
|
Loading…
Reference in a new issue