Commit 38fbc0f4 authored by Leo Peron's avatar Leo Peron
Browse files

Updating files

parent 1a5345d6
import requests as r
from typing import List
req = r.Requests()
def main():
while i != 3:
print("Selectionnez l'action souhaitée")
print(" Connectez vous : 1 ")
print("Inscrivez vous : 2 ")
print("Arreter le programme : 3")
i = int(input("Choississez l'option:"))
if i == 3:
return
num = int(input("Entrez votre numéro de téléphone:"))
if i == 1:
raw = req.getUserByNum(num)
if not raw:
print("Compte inexistant")
else:
userInterface(raw, req)
pass
elif i == 2:
nom = str(input("Entrez votre prénom et votre nom"))
adresse = str(input("Entrez votre adresse"))
result = req.createUser(num, nom, adresse)
if result:
print("Le client a bien été crée")
else:
print("Client déjà existant")
def userInterface(raw: List[str]):
i = 5
while i != 5:
print("---------------------------------------")
print(
f"Bonjour {raw[1]}, \n Numéro de téléphone: {raw[0]} \n Adresse: {raw[2]}"
)
print("---------------------------------------")
print("1. Afficher vos comptes Courants")
print("2. Afficher vos comptes Epargnes")
print("3. Afficher vos comptes Revolvings")
print("3. Créer/Ajouter un compte bancaire")
print("4. Supprimer/Retirer un compte bancaire")
print("5. Modifier votre profil")
print("6. Supprimer votre profil")
pass
def displayAccount(num: int, type: str):
pass
def makeOperation(num: int):
pass
def addAccount(num: int):
pass
def removeAccount(num: int):
pass
def modifyProfile(num: int):
nom = str(input("Entrez votre prénom et votre nom"))
adresse = str(input("Entrez votre adresse"))
result = req.modifyUser(num, nom, adresse)
if result:
print("La modification a fonctionné")
else:
print("La modification n'a pas fonctionné")
pass
def deleteProfile(num: int):
result = req.deleteUser(num)
if result:
print("Votre compte a bien été supprimé")
else:
print("Votre compte n'a pas être supprimé")
if __name__ == "__main__":
main()
import utils
import psycopg2 as sql
from psycopg2._psycopg import AsIs
......@@ -40,7 +38,8 @@ class Requests:
def getUserAccountsId(self, num: int):
self.cur.execute(
"SELECT Courant, Revolving, Epargne FROM Appartenance WHERE client = %s", (num,)
"SELECT Courant, Revolving, Epargne FROM Appartenance WHERE client = %s",
(num,),
)
return self.__getAccounts(self.cur.fetchall())
......@@ -53,16 +52,21 @@ class Requests:
# GESTION D'UN UTILISATEUR
def createUser(self, num: int, prenom: str, nom: str) -> bool:
def createUser(self, num: int, prenom: str, adresse: str) -> bool:
try:
self.cur.execute("INSERT INTO clients VALUES (%s,%s,%s)", (num, prenom, nom))
self.cur.execute(
"INSERT INTO clients VALUES (%s,%s,%s)", (num, prenom, adresse)
)
return True
except sql.Error as e:
return False
def modifyUser(self, num: int, prenom: str, nom: str) -> bool:
def modifyUser(self, num: int, prenom: str, adresse: str) -> bool:
try:
self.cur.execute("UPDATE clients SET prenom=%s, nom=%s WHRER telephone=%s", (prenom, nom, num))
self.cur.execute(
"UPDATE clients SET prenom=%s, adresse=%s WHERE telephone=%s",
(prenom, adresse, num),
)
return True
except sql.Error as e:
return False
......@@ -74,34 +78,60 @@ class Requests:
except sql.Error as e:
return False
def getUserCourantAccounts(self, num: int):
try:
self.cur.execute(
"SELECT * FROM appartenance WHERE client=%s INNER JOIN comptescourant ON appartenance.courant = comptescourant.id",
(num,),
)
return True
except sql.Error as e:
return False
def getUserEpargneAccounts(self, num: int):
pass
def getUserRevolvingAccounts(self, num: int):
pass
# CREATION DES COMPTES BANCAIRES
def createCourantAccount(self, num: int, solde: int, decouvert: int) -> bool:
id = self.__generateAccountId()
try:
self.cur.execute('INSERT INTO comptescourant VALUES (%s, current_timestamp , %s,%s,%s,%s,%s)',
(id, self.account_state[0], solde, solde, solde, decouvert))
self.cur.execute(
"INSERT INTO comptescourant VALUES (%s, current_timestamp , %s,%s,%s,%s,%s)",
(id, self.account_state[0], solde, solde, solde, decouvert),
)
self.addUserToAccount(num, id, "courant")
return True
except sql.Error as e:
return False
def createRevolvingAccount(self, num: int, solde: int, taux: int, montant: int) -> bool:
def createRevolvingAccount(
self, num: int, solde: int, taux: int, montant: int
) -> bool:
id = self.__generateAccountId()
try:
self.cur.execute('INSERT INTO comptesepargne VALUES (%s, current_timestamp, %s,%s,%s,%s)',
(id, self.account_state[0], taux, montant, solde))
self.cur.execute(
"INSERT INTO comptesepargne VALUES (%s, current_timestamp, %s,%s,%s,%s)",
(id, self.account_state[0], taux, montant, solde),
)
self.addUserToAccount(num, id, "revolving")
return True
except sql.Error as e:
print(e)
return False
def createEpargneAccount(self, num: int, interet: int, plafond: int, solde: int) -> bool:
def createEpargneAccount(
self, num: int, interet: int, plafond: int, solde: int
) -> bool:
id = self.__generateAccountId()
try:
self.cur.execute('INSERT INTO ComptesEpargne VALUES (%s, current_timestamp, %s,%s,%s,%s)',
(id, self.account_state[0], interet, plafond, solde))
self.cur.execute(
"INSERT INTO ComptesEpargne VALUES (%s, current_timestamp, %s,%s,%s,%s)",
(id, self.account_state[0], interet, plafond, solde),
)
self.addUserToAccount(num, id, "epargne")
return True
except sql.Error as e:
......@@ -112,21 +142,27 @@ class Requests:
def modifyCourantAccount(self, id: int, decouvert: int) -> bool:
try:
self.cur.execute('UPDATE comptescourant SET decouvert=%s WHERE id=%s', (decouvert, id))
self.cur.execute(
"UPDATE comptescourant SET decouvert=%s WHERE id=%s", (decouvert, id)
)
return True
except sql.Error as e:
return False
def modifyRevolvingAccount(self, id: int, taux: int) -> bool:
try:
self.cur.execute('UPDATE comptesrevolving SET taux=%s WHERE id=%s', (id, taux))
self.cur.execute(
"UPDATE comptesrevolving SET taux=%s WHERE id=%s", (id, taux)
)
return True
except sql.Error as e:
return False
def modifyEpargneAccount(self, num: int, interet: int) -> bool:
try:
self.cur.execute('UPDATE comptesrevolving SET interet=%s WHERE id=%s', (id, interet))
self.cur.execute(
"UPDATE comptesrevolving SET interet=%s WHERE id=%s", (id, interet)
)
return True
except sql.Error as e:
return False
......@@ -141,8 +177,17 @@ class Requests:
def createOperation(self, compte: int, op_type: str, acc_type: str, montant: int):
id = self.__generateOperationId()
try:
self.cur.execute('INSERT INTO %s (id, %s, montant, etat, date) VALUES (%s, %s, %s, %s, current_timestamp)',
(AsIs('operations' + op_type),AsIs(acc_type), id, compte, montant, self.operation_state[0]))
self.cur.execute(
"INSERT INTO %s (id, %s, montant, etat, date) VALUES (%s, %s, %s, %s, current_timestamp)",
(
AsIs("operations" + op_type),
AsIs(acc_type),
id,
compte,
montant,
self.operation_state[0],
),
)
self.__updateSoldById(compte, type, montant)
return True
except sql.Error as e:
......@@ -157,19 +202,24 @@ class Requests:
pass
pass
# GESTION DES RELATIONS COMPTES - CLIENTS
def addUserToAccount(self, num: int, id: int, type: str) -> bool:
try:
self.cur.execute('INSERT INTO appartenance (client, %s) VALUES (%s, %s)', (AsIs(type), num, id))
self.cur.execute(
"INSERT INTO appartenance (client, %s) VALUES (%s, %s)",
(AsIs(type), num, id),
)
return True
except sql.Error as e:
return False
def removeUserFromAccount(self, num: int, id: int, type: str) -> bool:
try:
self.cur.execute('DELETE FROM appartenance WHERE client=%s AND %s=%s', (num, AsIs(type), id))
self.cur.execute(
"DELETE FROM appartenance WHERE client=%s AND %s=%s",
(num, AsIs(type), id),
)
return True
except sql.Error as e:
return False
......@@ -177,14 +227,18 @@ class Requests:
# GENERATIONS CLES COMPTES ET OPERATIONS
def __generateAccountId(self) -> int:
self.cur.execute('SELECT MAX(id) FROM (SELECT id FROM ComptesEpargne UNION SELECT id FROM ComptesRevolving UNION SELECT id FROM ComptesCourant) AS comptes')
self.cur.execute(
"SELECT MAX(id) FROM (SELECT id FROM ComptesEpargne UNION SELECT id FROM ComptesRevolving UNION SELECT id FROM ComptesCourant) AS comptes"
)
cle = self.cur.fetchone()
if not cle[0]:
return 1
return cle[0] + 1
def __generateOperationId(self) -> int:
self.cur.execute('SELECT MAX(id) FROM (SELECT id FROM operationscartebleue UNION SELECT id FROM operationscheque UNION SELECT id FROM operationsguichet UNION SELECT id FROM operationsvirement) AS operation')
self.cur.execute(
"SELECT MAX(id) FROM (SELECT id FROM operationscartebleue UNION SELECT id FROM operationscheque UNION SELECT id FROM operationsguichet UNION SELECT id FROM operationsvirement) AS operation"
)
cle = self.cur.fetchone()
if not cle[0]:
return 1
......@@ -195,13 +249,13 @@ class Requests:
"SELECT * FROM comptecourant, compterevolving, comptecourant WHERE Courant.id = {id} OR Revolving.id = {id} OR Epargne.id = {id}"
)
def __updateSoldById(self, id: int, type: str, var: int) -> bool:
try:
self.cur.execute("SELECT solde FROM %s WHERE id =%s", (AsIs(type), id))
raw = self.cur.fetchone()
self.cur.execute(
"UPDATE %s SET solde=%s WHERE id=%s", (AsIs('comptes'+type), raw[0] + var, id)
"UPDATE %s SET solde=%s WHERE id=%s",
(AsIs("comptes" + type), raw[0] + var, id),
)
return True
except sql.Error as e:
......
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