Sprint 1 done

This commit is contained in:
Abderrahman El-Ouali 2024-10-09 16:08:05 +02:00
commit 0245b5bbc0
10 changed files with 372 additions and 0 deletions

40
.classpath Normal file
View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target/

23
.project Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>projet-maven</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

20
pom.xml Normal file
View file

@ -0,0 +1,20 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>AidePersonnesApp</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- Dépendance pour MySQL Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,108 @@
package controller;
import database.DatabaseConnection;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class AjoutUtilisateur extends JFrame {
private JTextField nomField;
private JTextField emailField;
private JComboBox<String> typeComboBox;
private JButton ajouterButton;
private JButton retourAccueilButton;
public AjoutUtilisateur() {
setTitle("Ajouter un utilisateur");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
gbc.fill = GridBagConstraints.HORIZONTAL;
JLabel nomLabel = new JLabel("Nom :");
gbc.gridx = 0;
gbc.gridy = 0;
add(nomLabel, gbc);
nomField = new JTextField();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 2;
add(nomField, gbc);
JLabel emailLabel = new JLabel("Email :");
gbc.gridx = 0;
gbc.gridy = 1;
add(emailLabel, gbc);
emailField = new JTextField();
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 2;
add(emailField, gbc);
JLabel typeLabel = new JLabel("Type d'utilisateur :");
gbc.gridx = 0;
gbc.gridy = 2;
add(typeLabel, gbc);
typeComboBox = new JComboBox<>(new String[]{"benevole", "personne_besoin", "validateur"});
gbc.gridx = 1;
gbc.gridy = 2;
gbc.gridwidth = 2;
add(typeComboBox, gbc);
ajouterButton = new JButton("Ajouter");
gbc.gridx = 1;
gbc.gridy = 3;
add(ajouterButton, gbc);
retourAccueilButton = new JButton("Retour à l'accueil");
gbc.gridx = 1;
gbc.gridy = 4;
add(retourAccueilButton, gbc);
ajouterButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ajouterUtilisateur();
}
});
retourAccueilButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MainMenu menu = new MainMenu();
menu.setVisible(true);
dispose();
}
});
}
private void ajouterUtilisateur() {
String nom = nomField.getText();
String email = emailField.getText();
String typeUtilisateur = (String) typeComboBox.getSelectedItem();
try (Connection connection = DatabaseConnection.getConnection()) {
String sql = "INSERT INTO utilisateurs (nom, email, type_utilisateur) VALUES (?, ?, ?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, nom);
statement.setString(2, email);
statement.setString(3, typeUtilisateur);
statement.executeUpdate();
JOptionPane.showMessageDialog(this, "Utilisateur ajouté avec succès !");
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,56 @@
package controller;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainMenu extends JFrame {
private JButton ajouterUtilisateurButton;
private JButton soumettreDemandeButton;
public MainMenu() {
setTitle("Menu Principal");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
gbc.fill = GridBagConstraints.HORIZONTAL;
ajouterUtilisateurButton = new JButton("Ajouter un utilisateur");
gbc.gridx = 0;
gbc.gridy = 0;
add(ajouterUtilisateurButton, gbc);
soumettreDemandeButton = new JButton("Soumettre une demande d'aide");
gbc.gridx = 0;
gbc.gridy = 1;
add(soumettreDemandeButton, gbc);
ajouterUtilisateurButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AjoutUtilisateur ajoutUtilisateur = new AjoutUtilisateur();
ajoutUtilisateur.setVisible(true);
dispose();
}
});
soumettreDemandeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SoumettreDemande soumettreDemande = new SoumettreDemande();
soumettreDemande.setVisible(true);
dispose();
}
});
}
public static void main(String[] args) {
MainMenu menu = new MainMenu();
menu.setVisible(true);
}
}

View file

@ -0,0 +1,97 @@
package controller;
import database.DatabaseConnection;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class SoumettreDemande extends JFrame {
private JTextField utilisateurIdField;
private JTextArea descriptionArea;
private JButton soumettreButton;
private JButton retourAccueilButton;
public SoumettreDemande() {
setTitle("Soumettre une demande d'aide");
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);
gbc.fill = GridBagConstraints.HORIZONTAL;
JLabel utilisateurIdLabel = new JLabel("ID de l'utilisateur :");
gbc.gridx = 0;
gbc.gridy = 0;
add(utilisateurIdLabel, gbc);
utilisateurIdField = new JTextField();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 2;
add(utilisateurIdField, gbc);
JLabel descriptionLabel = new JLabel("Description de la tâche :");
gbc.gridx = 0;
gbc.gridy = 1;
add(descriptionLabel, gbc);
descriptionArea = new JTextArea(5, 20);
descriptionArea.setWrapStyleWord(true);
descriptionArea.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(descriptionArea);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 2;
add(scrollPane, gbc);
soumettreButton = new JButton("Soumettre");
gbc.gridx = 1;
gbc.gridy = 2;
add(soumettreButton, gbc);
retourAccueilButton = new JButton("Retour à l'accueil");
gbc.gridx = 1;
gbc.gridy = 3;
add(retourAccueilButton, gbc);
soumettreButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
soumettreDemande();
}
});
retourAccueilButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MainMenu menu = new MainMenu();
menu.setVisible(true);
dispose();
}
});
}
private void soumettreDemande() {
String utilisateurId = utilisateurIdField.getText();
String description = descriptionArea.getText();
try (Connection connection = DatabaseConnection.getConnection()) {
String sql = "INSERT INTO demandes_aide (utilisateur_id, description, statut) VALUES (?, ?, 'en attente')";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setInt(1, Integer.parseInt(utilisateurId));
statement.setString(2, description);
statement.executeUpdate();
JOptionPane.showMessageDialog(this, "Demande soumise avec succès !");
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,15 @@
package database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConnection {
private static final String URL = "jdbc:mysql://localhost:3306/aide_personnes_db";
private static final String USER = "root";
private static final String PASSWORD = "@Abdo2001elouali";
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(URL, USER, PASSWORD);
}
}