Created base database controller and user database controller to allow for initial database control
This commit is contained in:
parent
ef94773b8f
commit
b1a22cb7bd
2
app.py
2
app.py
@ -1,6 +1,6 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from os import environ
|
from os import environ
|
||||||
from web import blueprint
|
from controllers.web import blueprint
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Main entrypoint for Flask application.
|
Main entrypoint for Flask application.
|
||||||
|
0
controllers/__init__.py
Normal file
0
controllers/__init__.py
Normal file
0
controllers/database/__init__.py
Normal file
0
controllers/database/__init__.py
Normal file
31
controllers/database/database.py
Normal file
31
controllers/database/database.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
class DatabaseController(ABC):
|
||||||
|
__sqlitefile = "./data/wmgzon.db"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._conn = None
|
||||||
|
try:
|
||||||
|
self._conn = sqlite3.connect(self.__sqlitefile)
|
||||||
|
except sqlite3.Error as e:
|
||||||
|
# Close the connection if still open
|
||||||
|
if self._conn:
|
||||||
|
self._conn.close()
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def create(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def read(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def update(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def delete(self):
|
||||||
|
pass
|
33
controllers/database/user.py
Normal file
33
controllers/database/user.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from .database import DatabaseController
|
||||||
|
from models.users.user import User
|
||||||
|
|
||||||
|
class UserController(DatabaseController):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def create(self, user: User):
|
||||||
|
params = [
|
||||||
|
user.firstName,
|
||||||
|
user.lastName,
|
||||||
|
user.email,
|
||||||
|
user.phone,
|
||||||
|
user.password,
|
||||||
|
user.role
|
||||||
|
]
|
||||||
|
|
||||||
|
self._conn.execute(
|
||||||
|
"INSERT INTO Users (first_name, last_name, email, phone, password, role) VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
|
params
|
||||||
|
)
|
||||||
|
self._conn.commit()
|
||||||
|
user.login()
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
print("Doing work")
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
print("Doing work")
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
print("Doing work")
|
@ -1,5 +1,7 @@
|
|||||||
from . import blueprint
|
from . import blueprint
|
||||||
from flask import render_template, redirect, request, session
|
from flask import render_template, redirect, request
|
||||||
|
from controllers.database.user import UserController
|
||||||
|
from models.users.customer import Customer
|
||||||
|
|
||||||
|
|
||||||
# Function responsible for displaying the main landing page of the site
|
# Function responsible for displaying the main landing page of the site
|
||||||
@ -31,5 +33,8 @@ def display_signup():
|
|||||||
# Function responsible for handling signups to the site
|
# Function responsible for handling signups to the site
|
||||||
@blueprint.post('/signup')
|
@blueprint.post('/signup')
|
||||||
def signup():
|
def signup():
|
||||||
|
database = UserController()
|
||||||
|
database.create(Customer())
|
||||||
|
|
||||||
print("Tryin to signup as " + request.form['username'])
|
print("Tryin to signup as " + request.form['username'])
|
||||||
return redirect("/")
|
return redirect("/")
|
@ -1,4 +1,4 @@
|
|||||||
from user import User
|
from .user import User
|
||||||
|
|
||||||
class Admin(User):
|
class Admin(User):
|
||||||
'''
|
'''
|
||||||
@ -8,10 +8,10 @@ class Admin(User):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.store = ""
|
self.store = ""
|
||||||
|
|
||||||
def login():
|
def login(self):
|
||||||
print("Logging in as Admin")
|
print("Logging in as Admin")
|
||||||
|
|
||||||
def signup():
|
def signup(self):
|
||||||
print("Signing up as Admin")
|
print("Signing up as Admin")
|
||||||
|
|
||||||
def createProduct():
|
def createProduct():
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from user import User
|
from .user import User
|
||||||
|
|
||||||
class Customer(User):
|
class Customer(User):
|
||||||
'''
|
'''
|
||||||
@ -9,9 +9,9 @@ class Customer(User):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def login():
|
def login(self):
|
||||||
print("Logging in as Customer")
|
print("Logging in as Customer")
|
||||||
|
|
||||||
def signup():
|
def signup(self):
|
||||||
print("Signing up as Customer")
|
print("Signing up as Customer")
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from user import User
|
from .user import User
|
||||||
|
|
||||||
class Seller(User):
|
class Seller(User):
|
||||||
'''
|
'''
|
||||||
@ -8,10 +8,10 @@ class Seller(User):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.store = ""
|
self.store = ""
|
||||||
|
|
||||||
def login():
|
def login(self):
|
||||||
print("Logging in as Seller")
|
print("Logging in as Seller")
|
||||||
|
|
||||||
def signup():
|
def signup(self):
|
||||||
print("Signing up as Seller")
|
print("Signing up as Seller")
|
||||||
|
|
||||||
def createProduct():
|
def createProduct():
|
||||||
|
@ -11,6 +11,8 @@ class User(ABC):
|
|||||||
self.firstName = ""
|
self.firstName = ""
|
||||||
self.lastName = ""
|
self.lastName = ""
|
||||||
self.phone = ""
|
self.phone = ""
|
||||||
|
self.password = ""
|
||||||
|
self.role=""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def login(self):
|
def login(self):
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from sqlite3 import Error
|
|
||||||
|
|
||||||
|
|
||||||
def create_connection(db_file):
|
def create_connection(db_file):
|
||||||
@ -15,7 +14,7 @@ def create_connection(db_file):
|
|||||||
|
|
||||||
print("SQLite Version: " + sqlite3.version)
|
print("SQLite Version: " + sqlite3.version)
|
||||||
print("Table creation complete")
|
print("Table creation complete")
|
||||||
except Error as e:
|
except sqlite3.Error as e:
|
||||||
print(e)
|
print(e)
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
|
Loading…
Reference in New Issue
Block a user