Created base database controller and user database controller to allow for initial database control
This commit is contained in:
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")
|
Reference in New Issue
Block a user