diff --git a/out/production/FIProjetIHM2022/Main.class b/out/production/FIProjetIHM2022/Main.class index d65f297..e077c7f 100644 Binary files a/out/production/FIProjetIHM2022/Main.class and b/out/production/FIProjetIHM2022/Main.class differ diff --git a/src/API.java b/src/API.java new file mode 100644 index 0000000..ed6ca94 --- /dev/null +++ b/src/API.java @@ -0,0 +1,189 @@ +/* +* [Proposition d'API.] +* Auteur : Bilal Boudjemline. +* Description : Proposition d'API pour le projet FIProjetIHM2022 dirigée par F.Madelaine et L.Hernandez. +* Faite le : 7 oct. 2022 a 22:20 +* */ + +/* +* Pourquoi est-elle efficasse? +* +* Car elle est fonctionnelle dans tous les cas et les eleves n'auront besoin que de creer l'objet: +* API api = new API(); +* Puis utiliser les methodes fourni par cette derniere. EX : +* String prenom = api.getPrenom(2); +* System.out.println("->" + prenom); +* out: -> Prenom Selectionné. +* */ + +import java.util.ArrayList; + +public class API { + private final BDatabase sharedObject; + private final String TableDesComptes = "Comptes"; + private final String TableDesGroupes = "Groupes"; + private final String TableDesMembres = "Membres"; + private final String TableDesGrades = "Grades"; + private final String TableDesDemandes = "Demandes"; + + public API() { + BDatabase db = new BDatabase(); + this.sharedObject = db; + } + + // Retourne le nom de l'id entree + public String getNom(int id) { + return this.sharedObject.fetchAll( + "SELECT nom FROM Membres WHERE idCompte=" + id + ).get(0); + } + + // Retourne le prenom de l'id entree + public String getPrenom(int id) { + return this.sharedObject.fetchAll( + "SELECT prenom FROM Membres WHERE idCompte=" + id + ).get(0); + } + + // Retourne l'adresse de telephone de l'id entree + public String getAdresse(int id) { + return this.sharedObject.fetchAll( + "SELECT adresse FROM Membres WHERE idCompte=" + id + ).get(0); + } + + // Retourne le numero de telephone de l'id entree + public String getPhone(int id) { + return this.sharedObject.fetchAll( + "SELECT phone FROM Membres WHERE idCompte=" + id + ).get(0); + } + + // Schema de retour : + // Liste des demandes = { + // {ListeDesId-1, ListeDesType-1, ListeDesMessage-1}, + // {ListeDesId-2, ListeDesType-2, ListeDesMessage-2}, + // {ListeDesId-3, ListeDesType-3, ListeDesMessage-3}, + // etc... + // } + // Retourne toutes les requetes qu'ils y a en bdd + public ArrayList> getAllRequest() { + ArrayList> toReturn = new ArrayList<>(); + ArrayList tmp = new ArrayList<>(); + + ArrayList listId = this.sharedObject.fetchAll( + "SELECT idCompte FROM " + this.TableDesDemandes + ); + + ArrayList listType = this.sharedObject.fetchAll( + "SELECT type FROM " + this.TableDesDemandes + ); + + ArrayList listContent = this.sharedObject.fetchAll( + "SELECT contenu FROM " + this.TableDesDemandes + ); + + if(listId.size() == listContent.size() && listType.size() == listContent.size()) { + for(int i = 0; i <= listId.size()-1; i++) { + tmp.add(listId.get(i)); + tmp.add(listType.get(i)); + tmp.add(listContent.get(i)); + + toReturn.add(tmp); + } + } else { + System.out.println("Erreur."); + } + + return toReturn; + } + + // Retourne les requetes faites par un eleve en particulier + public ArrayList> getRequest(int id) { + ArrayList> toReturn = new ArrayList<>(); + ArrayList tmp = new ArrayList<>(); + + ArrayList listId = this.sharedObject.fetchAll( + "SELECT idCompte FROM " + this.TableDesDemandes + ); + + ArrayList listType = this.sharedObject.fetchAll( + "SELECT type FROM " + this.TableDesDemandes + ); + + ArrayList listContent = this.sharedObject.fetchAll( + "SELECT contenu FROM " + this.TableDesDemandes + ); + + if(listId.size() == listContent.size() && listType.size() == listContent.size()) { + for(int i = 0; i <= listId.size()-1; i++) { + tmp.add(listId.get(i)); + tmp.add(listType.get(i)); + tmp.add(listContent.get(i)); + + toReturn.add(tmp); + } + } else { + System.out.println("Erreur."); + } + + return toReturn; + } + + // Retourne tous les groupes existant + public ArrayList> getAllGrups(){ + ArrayList> toReturn = new ArrayList<>(); + ArrayList tmp = new ArrayList<>(); + + ArrayList listGrups = this.sharedObject.fetchAll( + "SELECT intitule FROM " + this.TableDesGroupes + ); + + ArrayList listIdGrups = this.sharedObject.fetchAll( + "SELECT idRequete FROM " + this.TableDesGroupes + ); + + for(int i = 0; i <= listGrups.size(); i++) { + tmp.add(listIdGrups.get(i)); + tmp.add(listGrups.get(i)); + + toReturn.add(tmp); + } + + return toReturn; + } + + // Retourne en String par son id + public String getGrup(int id) { + return this.sharedObject.fetchAll( + "SELECT intitule FROM " + this.TableDesGroupes + " WHERE idGroupe=" + id + ).get(0); + } + + // Retourne l'id d'un groupe + public int getGrup(String intitule) { + return Integer.parseInt( + this.sharedObject.fetchAll( + "SELECT idGroupe FROM " + this.TableDesGroupes + " WHERE intitule=" + intitule + ).get(0), 10 + ); + } + + // Retourne le grade par son id + public String getGrade(int id) { + return this.sharedObject.fetchAll( + "SELECT GR.intitule FROM " + + this.TableDesComptes + " TC," + this.TableDesGrades + " GR" + + " WHERE idCompte=" + id + ).get(0); + } + + // Retourne l'id du grade mis en parametre + public int getGrade(String intitule) { + return Integer.parseInt( + this.sharedObject.fetchAll( + "SELECT idGrade FROM " + this.TableDesGrades + " WHERE intitule = " + intitule + ).get(0) + , 10); + } +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 7c0bd29..6ba01a1 100644 --- a/src/Main.java +++ b/src/Main.java @@ -4,11 +4,9 @@ import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { // test - //BDatabase db = new BDatabase(); - //ManageStudent test = new ManageStudent(db); + BDatabase db = new BDatabase(); + ManageStudent test = new ManageStudent(db); - // - // - LoginConnection goToLogin = new LoginConnection("Grup'App", 400, 400, JFrame.EXIT_ON_CLOSE); + //LoginConnection goToLogin = new LoginConnection("Grup'App", 400, 400, JFrame.EXIT_ON_CLOSE); } } \ No newline at end of file