Commit 73c7460a authored by Dimitri Nicolas's avatar Dimitri Nicolas
Browse files

Requests added

parent 09334a60
......@@ -13,7 +13,9 @@ class AdherentDataMapper(DataMapper):
except Exception as err:
print(err)
finally:
conn.close()
connection.close()
def getPrets(self, login):
connection = self.connect()
try:
......@@ -25,7 +27,6 @@ class AdherentDataMapper(DataMapper):
except Exception as err:
print(err)
finally:
conn.close()
connection.close()
datamapper = AdherentDataMapper()
datamapper.selectAdherents()
\ No newline at end of file
datamapper = AdherentDataMapper()
\ No newline at end of file
......@@ -19,8 +19,4 @@ class DataMapper:
password=self.password)
except psycopg2.OperationalError:
print("Database connection error ")
return res
dataMapper = DataMapper()
conn = dataMapper.connect()
print(type(conn))
\ No newline at end of file
return res
\ No newline at end of file
from datetime import date
from enum import Enum
import psycopg2
from DataMapper import DataMapper
class SanctionDataMapper(DataMapper):
def blacklister(self, login):
connection = self.connect()
try:
cursor : psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"UPDATE adherent SET blacklisted = TRUE WHERE login = '{login}'")
connection.commit()
except Exception as err:
print(err)
finally:
connection.close()
def getSanctions(self):
connection = self.connect()
try:
cursor : psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"SELECT sanctionid, adherent, datesanction, encours FROM sanction")
return cursor.fetchall()
except Exception as err:
print(err)
finally:
connection.close()
dataMapper = SanctionDataMapper()
\ No newline at end of file
from datetime import date
from enum import Enum
import psycopg2
......@@ -10,6 +11,47 @@ class Roles(Enum):
PERSONNEL = 2
class UserDataMapper(DataMapper):
def ajouterAdherent(self, login : str, numcarte: str, datenaissance:date, numtel:str):
connection = self.connect()
try:
cursor: psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"INSERT INTO adherent(login, numcarte, datenaissance, numtel, dateadhesion, blacklisted)"
f"VALUES ('{login}', '{numcarte}', '{datenaissance}', '{numtel}', CURRENT_TIMESTAMP, FALSE)")
connection.commit()
except Exception as err:
print(err)
finally:
connection.close()
def deleteAdherent(self, login:str):
connection = self.connect()
try:
cursor: psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"DELETE FROM adherent WHERE login = '{login}'")
connection.commit()
except Exception as err:
print(err)
finally:
connection.close()
def ajouterPersonnel(self, login: str):
connection = self.connect()
try:
cursor: psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"INSERT INTO personnel(login) VALUES ('{login}')")
connection.commit()
except Exception as err:
print(err)
finally:
connection.close()
def deletePersonnel(self, login:str):
connection = self.connect()
try:
cursor: psycopg2.extensions.cursor = connection.cursor()
cursor.execute(f"DELETE FROM personnel WHERE login = '{login}'")
connection.commit()
except Exception as err:
print(err)
finally:
connection.close()
def checkUser(self, login : str, password: str) -> Roles:
connection = self.connect()
try:
......@@ -36,5 +78,6 @@ class UserDataMapper(DataMapper):
dataMapper = UserDataMapper()
role = dataMapper.checkUser("lbernard", "47FEADQ665D788")
print(role)
\ No newline at end of file
dataMapper.deleteAdherent("blussier")
dataMapper.deletePersonnel("hlefebvre")
print(dataMapper.checkUser("hlefebvre", "1888ZFDSDSQD5Q"))
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment