Compare commits
30 Commits
tp_rest
...
tp_servlet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cb36bd253 | ||
|
|
7ec2fd3fe0 | ||
|
|
c3167e43a0 | ||
|
|
1c9ecc1a1f | ||
|
|
c5eef2c624 | ||
|
|
208a660706 | ||
|
|
1344a11f3a | ||
|
|
e3ce24a43e | ||
|
|
58470b6e46 | ||
|
|
211a168bd0 | ||
|
|
5fbc2045f8 | ||
|
|
40ea3ed62a | ||
|
|
8abcff6dde | ||
|
|
4cb77f6158 | ||
|
|
b9d8925f1a | ||
|
|
2f4d87c487 | ||
|
|
2cac97c07d | ||
|
|
996d62ec10 | ||
|
|
8e8609aa4b | ||
|
|
fcc925d1bc | ||
|
|
d65baa3a78 | ||
|
|
7b7be6c91f | ||
|
|
9177d596af | ||
|
|
7b14ebcc0e | ||
|
|
4101d85cb0 | ||
|
|
8688bf1566 | ||
|
|
6a0976f92d | ||
|
|
b0c740dfab | ||
|
|
6d8c4a7865 | ||
|
|
63a6a258f9 |
84
README.md
84
README.md
@@ -1,29 +1,15 @@
|
||||
# TP TAA
|
||||
# TP1 et TP2_servlet
|
||||
|
||||
## TP2 Partie API REST
|
||||
## Demarrge
|
||||
|
||||
### Compte rendu
|
||||
Dans ce TP REST, nous avons implémenté les éléments suivants:
|
||||
- Mapper pour convertir les entités vers les DTO et inversement
|
||||
- Lombok afin de simplifier le code et éviter le code boilerplate (getters, setters, constructeurs, etc.)
|
||||
- API REST pour exposer les différentes ressources
|
||||
- Swagger UI pour documenter et tester facilement toutes les méthodes de l’API.
|
||||
- DTO (Data Transfer Objects) afin d’éviter les problèmes de boucle infinie liés aux relations bidirectionnelles entre entités.
|
||||
Optionnel : Reset la base de donné : ```rm -rd data/*```
|
||||
|
||||
lancer la base de donné : ```.\run-hsqldb-server.sh``` ou ```.\run-hsqldb-server.bat```
|
||||
|
||||
#### Execution du projet
|
||||
Recharger les dépendances Maven :
|
||||
`mvn clean install`
|
||||
run Maven : ```compile jetty:run``` ou ```mvn clean compile jetty:run```
|
||||
|
||||
Lancer la base de données (Linux) : `./run-hsqldb-server.sh`
|
||||
## Graph metier
|
||||
|
||||
Lancer le serveur par fichier `src/main/java/fr.istic.taa.jaxrs/RestServer.java`
|
||||
|
||||
Après le lancement du serveur, on a testé des appels API avec Insomnia et l'interface Swagger est accessible via: http://localhost:8080/api
|
||||
Seuls Utilisateur et Question sont fonctionnels, il reste quelques problèmes sur le reste.
|
||||
|
||||
|
||||
#### Diagramme de classe
|
||||
```mermaid
|
||||
classDiagram
|
||||
Utilisateur "*" -- "*" Session
|
||||
@@ -37,10 +23,10 @@ classDiagram
|
||||
class Utilisateur {
|
||||
-id : int
|
||||
-name : String
|
||||
-session : List<Session>
|
||||
-sessions : List<Session>
|
||||
-email : String
|
||||
-password : String
|
||||
-quizzs : String
|
||||
-quizzs : List<Quizz>
|
||||
}
|
||||
class Session{
|
||||
-id : int
|
||||
@@ -50,9 +36,10 @@ classDiagram
|
||||
-theme : String
|
||||
}
|
||||
class Quizz{
|
||||
-session: Session
|
||||
-sessions: List<Session>
|
||||
-id : int
|
||||
-createur: Utilisateur
|
||||
-createur : Utilisateur
|
||||
-quizz : Quizz
|
||||
}
|
||||
class Reponse{
|
||||
-id : int
|
||||
@@ -67,54 +54,7 @@ classDiagram
|
||||
class Question{
|
||||
-id : int
|
||||
-enonce : String
|
||||
-reponse: Reponse
|
||||
-reponse : Reponse
|
||||
}
|
||||
```
|
||||
|
||||
##### Utilisateur Resource
|
||||
| Methode | URL | Description |
|
||||
|---------|---------------------------------------------------|-------------------------------------------------------|
|
||||
| GET | `/utilisateur` | Retourne toute la liste de l'utilisateur |
|
||||
| POST | `/utilisateur/register` | S'incrire nouveaux utilisateur |
|
||||
| GET | `/utilisateur/login` | Se connecter |
|
||||
| GET | `/utilisateur/{id}` | Retourne l'utilisateur par id |
|
||||
| GET | `/utilisateur/{user_id}/session` | Retoune la liste de session que l'utilisateur attends |
|
||||
| PUT | `/utilisateur/{user_id}/add_session/{session_id}` | Ajoute un nouveau session à la liste de l'utilisateur |
|
||||
| DELETE | `/utilisteur/{user_id}/delete` | Supprime l'utilisateur |
|
||||
|
||||
##### Session Resource
|
||||
| Methode | URL | Description |
|
||||
|---------|--------------------------------------|------------------------------------|
|
||||
| GET | `/session` | Retourne toute la liste du session |
|
||||
| GET | `/session/{id}` | Retourne la session par id |
|
||||
| GET | `/session/{session_id}/quizzs` | Retourne la liste de quizzs |
|
||||
| GET | `/session/{session_id}/utilisateurs` | Retourne la liste de l'utilisateur |
|
||||
| DELETE | `/session/{session_id}/delete` | Supprime la session |
|
||||
|
||||
##### Quizz Resource
|
||||
| Methode | URL | Description |
|
||||
|---------|------------------------------------------------|-----------------------------------------|
|
||||
| GET | `/quizz` | Retourne toute la liste du quizz |
|
||||
| GET | `/quizz/{quizz_id}/questions` | Retourne toutes questions du quizz |
|
||||
| GET | `/quizz/{quizz_id}/add_question/{question_id}` | Ajoute une nouvuelle question au quizz |
|
||||
| DELETE | `/quizz/{quizz_id}/delete` | Suprrime le quizz |
|
||||
| PUT | `/quizz/{quizz_id}/deleteQ` | Supprime toute les questions de quizz |
|
||||
|
||||
##### Question Resource
|
||||
| Methode | URL | Description |
|
||||
|----------|----------------------------------------------------|-----------------------------------------------------------------------|
|
||||
| GET | `/question` | Retourne toute la liste du question |
|
||||
| POST | `/question/addQuestion` | Créer une question |
|
||||
| PUT | `/question/{question_id}/changeQuestion` | Change l'énoncé de la question |
|
||||
| GET | `/question/{question_id}/getReponse` | retourne l'objet Reponse |
|
||||
| DELETE | `/question/{question_id}/deletReponses` | supprime toute les réponse correct |
|
||||
| PUT | `/question/{question_id}/addReponse` | Ajoute une réponse à Reponse |
|
||||
| PUT | `/question/{question_id}/setReponse/choix` | créer un nouvel objet Reponse de type Choix pour la question |
|
||||
| PUT | `/question/{question_id}/setReponse/reponseCourte` | créer un nouvel objet Reponse de type reponse courte pour la question |
|
||||
| PUT | `/question/{question_id}/addChoix` | rajoute un choix si Reponse est de type Choix |
|
||||
|
||||
## Auteurs
|
||||
|
||||
- Tuan Minh VU
|
||||
|
||||
- Thibaut ROCHAS
|
||||
|
||||
BIN
hsqldb-2.7.2.jar
Normal file
BIN
hsqldb-2.7.2.jar
Normal file
Binary file not shown.
139
pom.xml
139
pom.xml
@@ -1,36 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>fr.istic.taa</groupId>
|
||||
<artifactId>jaxrs-example</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>jaxrs-example</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<groupId>test</groupId>
|
||||
<packaging>war</packaging>
|
||||
<artifactId>testjpa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<org.mapstruct.version>1.6.3</org.mapstruct.version>
|
||||
</properties>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- ==== JPA / Hibernate ==== -->
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>6.2.7.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>5.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.30</version>
|
||||
@@ -45,70 +46,42 @@
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
<version>4.0.2</version>
|
||||
</dependency>
|
||||
<!-- ==== REST API ==== -->
|
||||
<!--https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-undertow -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-undertow</artifactId>
|
||||
<version>6.2.4.Final</version>
|
||||
</dependency>
|
||||
<!--https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson2-provider</artifactId>
|
||||
<version>6.2.4.Final</version>
|
||||
</dependency>
|
||||
<!--https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxb-provider -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
<version>6.2.4.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OpenAPI-->
|
||||
<!--https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2-jakarta -->
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-jaxrs2-jakarta</artifactId>
|
||||
<version>2.2.15</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
|
||||
<version>2.2.15</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ==== MapStruct/ Lombok ==== -->
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-maven-plugin -->
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>11.0.16</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<httpConnector>
|
||||
<port>8080</port>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>11</source> <!-- depending on your project -->
|
||||
<target>11</target> <!-- depending on your project -->
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -120,10 +93,10 @@
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</path>
|
||||
<!-- other annotation processors -->
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
mkdir data
|
||||
cd data
|
||||
java -cp ..\hsqldb-2.7.2.jar org.hsqldb.Server
|
||||
mkdir data
|
||||
cd data
|
||||
java -cp ..\hsqldb-2.7.2.jar org.hsqldb.Server
|
||||
|
||||
2
show-hsqldb.bat
Normal file → Executable file
2
show-hsqldb.bat
Normal file → Executable file
@@ -1,2 +1,2 @@
|
||||
java -cp ./target/dependency/hsqldb-2.7.2.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --url jdbc:hsqldb:hsql://localhost/ --user SA
|
||||
java -cp hsqldb-2.7.2.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --url jdbc:hsqldb:hsql://localhost/ --user SA
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#mvn dependency:copy-dependencies
|
||||
java -cp ./target/dependency/hsqldb-2.7.2.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --url jdbc:hsqldb:hsql://localhost/ --user SA
|
||||
java -cp hsqldb-2.7.2.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --url jdbc:hsqldb:hsql://localhost/ --user SA
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jpa.EntityManagerHelper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
public abstract class AbstractJpaDao<K, T extends Serializable> implements IGenericDao<K, T> {
|
||||
protected EntityManager em;
|
||||
private Class<T> entityClass;
|
||||
@@ -57,4 +59,5 @@ public abstract class AbstractJpaDao<K, T extends Serializable> implements IGene
|
||||
T T_to_be_deleted = em.find(entityClass, id);
|
||||
em.remove(T_to_be_deleted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
@@ -6,19 +6,12 @@ import jakarta.persistence.Persistence;
|
||||
|
||||
public class EntityManagerHelper {
|
||||
|
||||
private static EntityManagerFactory emf;
|
||||
private static final EntityManagerFactory emf;
|
||||
private static final ThreadLocal<EntityManager> threadLocal;
|
||||
|
||||
static {
|
||||
try {
|
||||
emf = Persistence.createEntityManagerFactory("dev");
|
||||
} catch (Exception e) {
|
||||
emf = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
emf = Persistence.createEntityManagerFactory("dev");
|
||||
threadLocal = new ThreadLocal<EntityManager>();
|
||||
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
package DAO;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
10
src/main/java/DAO/QuestionDAO.java
Normal file
10
src/main/java/DAO/QuestionDAO.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package DAO;
|
||||
|
||||
import metier.Question;
|
||||
|
||||
public class QuestionDAO extends AbstractJpaDao<Integer, Question> {
|
||||
public QuestionDAO(){
|
||||
super();
|
||||
this.setClass(Question.class);
|
||||
}
|
||||
}
|
||||
34
src/main/java/DAO/QuizzDAO.java
Normal file
34
src/main/java/DAO/QuizzDAO.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import metier.Question;
|
||||
import metier.Quizz;
|
||||
|
||||
public class QuizzDAO extends AbstractJpaDao<Integer, Quizz> {
|
||||
public QuizzDAO(){
|
||||
super();
|
||||
this.setClass(Quizz.class);
|
||||
}
|
||||
|
||||
public void deleteAllQuiz(){
|
||||
EntityTransaction et= em.getTransaction();
|
||||
et.begin();
|
||||
em.createQuery("delete from Quizz").executeUpdate();
|
||||
et.commit();
|
||||
}
|
||||
|
||||
public void addQuestion(Quizz quizz, Question question) {
|
||||
System.out.println("ajout de question dans le quizz");
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
question.setQuizz(quizz);
|
||||
quizz.getQuestions().add(question);
|
||||
em.merge(quizz);
|
||||
t.commit();
|
||||
em.refresh(quizz);
|
||||
}
|
||||
|
||||
public void refresh(Quizz quizz) {
|
||||
em.refresh(quizz);
|
||||
}
|
||||
}
|
||||
24
src/main/java/DAO/ReponseDAO.java
Normal file
24
src/main/java/DAO/ReponseDAO.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import metier.Question;
|
||||
import metier.Reponse;
|
||||
|
||||
public class ReponseDAO extends AbstractJpaDao<Integer, Reponse> {
|
||||
public ReponseDAO(){
|
||||
super();
|
||||
this.setClass(Reponse.class);
|
||||
}
|
||||
|
||||
|
||||
public void addToQuestion(Reponse r, Question q) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
|
||||
q.setReponse(r);
|
||||
r.setQuestion(q);
|
||||
em.merge(r);
|
||||
t.commit();
|
||||
em.refresh(q);
|
||||
}
|
||||
}
|
||||
42
src/main/java/DAO/SessionDAO.java
Normal file
42
src/main/java/DAO/SessionDAO.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package DAO;
|
||||
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import metier.Quizz;
|
||||
import metier.Session;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SessionDAO extends AbstractJpaDao<Integer, Session> {
|
||||
public SessionDAO() {
|
||||
super();
|
||||
this.setClass(Session.class);
|
||||
}
|
||||
|
||||
public List<Session> findByTheme(String theme){
|
||||
Query query=em.createQuery("select s from Session s where s.theme=:theme");
|
||||
query.setParameter("theme",theme);
|
||||
List<Session> sessions=query.getResultList();
|
||||
|
||||
if(sessions.size()>0){
|
||||
return sessions;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh(Session session) {
|
||||
em.refresh(session);
|
||||
}
|
||||
|
||||
public void addQuizz(Quizz q, Session s) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
|
||||
q.getSessions().add(s);
|
||||
s.getQuizzs().add(q);
|
||||
em.merge(s);
|
||||
t.commit();
|
||||
}
|
||||
}
|
||||
37
src/main/java/DAO/UtilisateurDAO.java
Normal file
37
src/main/java/DAO/UtilisateurDAO.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
public class UtilisateurDAO extends AbstractJpaDao<Integer, Utilisateur> {
|
||||
public UtilisateurDAO() {
|
||||
super();
|
||||
this.setClass(Utilisateur.class);
|
||||
}
|
||||
|
||||
public Utilisateur findByEmail(String email){
|
||||
EntityTransaction t=em.getTransaction();
|
||||
t.begin();
|
||||
Query query=em.createQuery("select u from Utilisateur u where u.email=:email");
|
||||
query.setParameter("email",email);
|
||||
Utilisateur u=(Utilisateur)query.getSingleResult();
|
||||
t.commit();
|
||||
return u;
|
||||
}
|
||||
|
||||
public void addToSession(int sessionId, int userId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Session s = em.find(Session.class, sessionId);
|
||||
Utilisateur u = em.find(Utilisateur.class, userId);
|
||||
|
||||
//FAUT AJOUTER OWNING SIDE ( Ici u --> s)
|
||||
u.getSessions().add(s);
|
||||
//Jsp il faut birectionnelle ou pas?
|
||||
s.getUtilisateurs().add(u);
|
||||
em.merge(u);
|
||||
t.commit();
|
||||
}
|
||||
}
|
||||
11
src/main/java/DTO/QuestionDTO.java
Normal file
11
src/main/java/DTO/QuestionDTO.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package DTO;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class QuestionDTO {
|
||||
private int id;
|
||||
private String question;
|
||||
private List<String> reponses_string;
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
package DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class QuizzDTO {
|
||||
private int id;
|
||||
private List<Integer> sessionsId;
|
||||
private Integer sessionId;
|
||||
private Integer utilisateurId;
|
||||
private List<Integer> questionsId;
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
package DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class SessionDTO {
|
||||
private String theme;
|
||||
private int codePIN;
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
package DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class UtilisateurDTO {
|
||||
private int id;
|
||||
private String name;
|
||||
private String email;
|
||||
private String password;
|
||||
}
|
||||
|
||||
12
src/main/java/Mapper/QuestionMapper.java
Normal file
12
src/main/java/Mapper/QuestionMapper.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package Mapper;
|
||||
|
||||
import DTO.QuestionDTO;
|
||||
import metier.Question;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
public interface QuestionMapper {
|
||||
QuestionMapper INSTANCE = Mappers.getMapper( QuestionMapper.class );
|
||||
|
||||
QuestionDTO toDTO(Question question);
|
||||
Question toEntity(QuestionDTO questionDTO);
|
||||
}
|
||||
12
src/main/java/Mapper/QuizzMapper.java
Normal file
12
src/main/java/Mapper/QuizzMapper.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package Mapper;
|
||||
|
||||
import DTO.QuizzDTO;
|
||||
import metier.Quizz;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
public interface QuizzMapper {
|
||||
QuizzMapper INSTANCE = Mappers.getMapper( QuizzMapper.class );
|
||||
|
||||
QuizzDTO toDTO(Quizz quizz);
|
||||
Quizz toEntity(QuizzDTO quizzDTO);
|
||||
}
|
||||
13
src/main/java/Mapper/SessionMapper.java
Normal file
13
src/main/java/Mapper/SessionMapper.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package Mapper;
|
||||
|
||||
import DTO.SessionDTO;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
public interface SessionMapper {
|
||||
SessionMapper INSTANCE = Mappers.getMapper( SessionMapper.class );
|
||||
|
||||
SessionDTO toDTO(Utilisateur utilisateur);
|
||||
Session toEntity(SessionDTO sessionDTO);
|
||||
}
|
||||
@@ -1,19 +1,14 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
package Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.UtilisateurDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import DTO.UtilisateurDTO;
|
||||
import metier.Utilisateur;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UtilisateurMapper {
|
||||
UtilisateurMapper INSTANCE = Mappers.getMapper(UtilisateurMapper.class);
|
||||
|
||||
UtilisateurDTO toDTO(Utilisateur utilisateur);
|
||||
Utilisateur toEntity(UtilisateurDTO dto);
|
||||
|
||||
List<UtilisateurDTO> toDTOs(List<Utilisateur> utilisateurList);
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Choix;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import fr.istic.taa.jaxrs.metier.ReponseCourte;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
|
||||
public class QuestionDAO extends AbstractJpaDao<Integer, Question> {
|
||||
public QuestionDAO() {
|
||||
super();
|
||||
this.setClass(Question.class);
|
||||
}
|
||||
|
||||
public void addReponse(String reponse, int questionId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Question q = em.find(Question.class, questionId);
|
||||
if (q != null && q.getReponse() != null) {
|
||||
q.getReponse().getReponses().add(reponse);
|
||||
em.merge(q);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteReponse(int questionId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Question q = em.find(Question.class, questionId);
|
||||
if (q != null && q.getReponse() != null) {
|
||||
q.getReponse().setReponses(new ArrayList<>());
|
||||
em.merge(q);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setReponse(Reponse rep, Integer id) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Question q = em.find(Question.class, id);
|
||||
if (q != null) {
|
||||
q.setReponse(rep);
|
||||
em.merge(q);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setChoix(Integer id) {
|
||||
setReponse(new Choix(), id);
|
||||
}
|
||||
|
||||
public void setReponseCourte(Integer id) {
|
||||
setReponse(new ReponseCourte(), id);
|
||||
}
|
||||
|
||||
public void addChoix(Integer id, String choix) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Question q = em.find(Question.class, id);
|
||||
if (q != null && q.getReponse() instanceof Choix) {
|
||||
((Choix) q.getReponse()).getChoix().add(choix);
|
||||
em.merge(q);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void changeEnonce(String newEnonce, Integer id) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Question q = em.find(Question.class, id);
|
||||
if (q != null) {
|
||||
q.setEnonce(newEnonce);
|
||||
em.merge(q);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
|
||||
public class QuizzDAO extends AbstractJpaDao<Integer, Quizz> {
|
||||
public QuizzDAO(){
|
||||
super();
|
||||
this.setClass(Quizz.class);
|
||||
}
|
||||
|
||||
public void deleteAllQuestion(int quizzId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Quizz quizz = em.find(Quizz.class, quizzId);
|
||||
if (quizz != null) {
|
||||
quizz.getQuestions().clear();
|
||||
em.merge(quizz);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void addQuestion(int quizzId, int questionId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) t.begin();
|
||||
Quizz quizz = em.find(Quizz.class, quizzId);
|
||||
Question question = em.find(Question.class, questionId);
|
||||
|
||||
if (quizz != null && question != null) {
|
||||
quizz.getQuestions().add(question);
|
||||
em.merge(quizz);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
|
||||
public class ReponseDAO extends AbstractJpaDao<Integer, Reponse> {
|
||||
public ReponseDAO(){
|
||||
super();
|
||||
this.setClass(Reponse.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SessionDAO extends AbstractJpaDao<Integer, Session> {
|
||||
public SessionDAO() {
|
||||
super();
|
||||
this.setClass(Session.class);
|
||||
}
|
||||
|
||||
public List<Session> findByTheme(String theme) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) {
|
||||
t.begin();
|
||||
}
|
||||
Query query = em.createQuery("SELECT s FROM Session s WHERE s.theme = :theme", Session.class);
|
||||
query.setParameter("theme", theme);
|
||||
List<Session> sessions = query.getResultList();
|
||||
t.commit();
|
||||
return sessions;
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UtilisateurDAO extends AbstractJpaDao<Integer, Utilisateur> {
|
||||
public UtilisateurDAO() {
|
||||
super();
|
||||
this.setClass(Utilisateur.class);
|
||||
}
|
||||
|
||||
public Utilisateur findByEmail(String email) {
|
||||
List<Utilisateur> results = em.createQuery(
|
||||
"SELECT u FROM Utilisateur u WHERE u.email = :email", Utilisateur.class)
|
||||
.setParameter("email", email)
|
||||
.getResultList();
|
||||
return results.isEmpty() ? null : results.get(0);
|
||||
}
|
||||
|
||||
public void addToSession(int userId, int sessionId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) {
|
||||
t.begin();
|
||||
}
|
||||
Session s = em.find(Session.class, sessionId);
|
||||
Utilisateur u = em.find(Utilisateur.class, userId);
|
||||
if (s == null || u == null) {
|
||||
throw new IllegalArgumentException("User or session not found");
|
||||
}
|
||||
if (!u.getSessions().contains(s)) {
|
||||
u.getSessions().add(s);
|
||||
em.merge(u);
|
||||
}
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(Utilisateur entity) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
try {
|
||||
if (!t.isActive()) {
|
||||
t.begin();
|
||||
}
|
||||
em.merge(entity);
|
||||
t.commit();
|
||||
} catch (Exception e) {
|
||||
if (t.isActive()) t.rollback();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class QuestionDTO {
|
||||
private int id;
|
||||
private String enonce;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class ReponseDTO {
|
||||
public List<String> reponses;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.QuestionDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface QuestionMapper {
|
||||
QuestionMapper INSTANCE = Mappers.getMapper( QuestionMapper.class );
|
||||
|
||||
|
||||
QuestionDTO toDTO(Question question);
|
||||
|
||||
Question toEntity(QuestionDTO questionDTO);
|
||||
|
||||
List<QuestionDTO> toDTOs(List<Question> questionList);
|
||||
|
||||
default List<String> question_ReponseString(Reponse reponse){
|
||||
return reponse.getReponses();
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.QuizzDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface QuizzMapper {
|
||||
QuizzMapper INSTANCE = Mappers.getMapper( QuizzMapper.class );
|
||||
|
||||
//https://www.baeldung.com/mapstruct-map-source-object-target-list
|
||||
//https://mapstruct.org/
|
||||
@Mapping(target="sessionsId", expression="java(function_mapS(quizz.getSessions()))")
|
||||
@Mapping(target="utilisateurId", source = "createur.id")
|
||||
@Mapping(target="questionsId",expression="java(function_mapQ(quizz.getQuestions()))")
|
||||
QuizzDTO toDTO(Quizz quizz);
|
||||
Quizz toEntity(QuizzDTO quizzDTO);
|
||||
|
||||
List<QuizzDTO> toDTOs(List<Quizz> quizzes);
|
||||
|
||||
default List<Integer> function_mapQ(List<Question> questionList){
|
||||
List<Integer> list=new ArrayList<Integer>();
|
||||
for(Question question : questionList){
|
||||
list.add(question.getId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
default List<Integer> function_mapS(List<Session> sessionList){
|
||||
List<Integer> list=new ArrayList<Integer>();
|
||||
for(Session session : sessionList){
|
||||
list.add(session.getId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.SessionDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SessionMapper {
|
||||
SessionMapper INSTANCE = Mappers.getMapper( SessionMapper.class );
|
||||
|
||||
@Mapping(target="utilisateursId",expression="java(function_mapU(session.getUtilisateurs()))")
|
||||
@Mapping(target="quizzsId",expression="java(function_mapQ(session.getQuizzs()))")
|
||||
SessionDTO toDTO(Session session);
|
||||
Session toEntity(SessionDTO sessionDTO);
|
||||
|
||||
List<SessionDTO> toDTOs(List<Session> sessions);
|
||||
|
||||
//https://www.baeldung.com/mapstruct-map-source-object-target-list
|
||||
default List<Integer> function_mapU(List<Utilisateur> utilisateurList) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (Utilisateur utilisateur : utilisateurList) {
|
||||
result.add(utilisateur.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
default List<Integer> function_mapQ(List<Quizz> quizzList) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (Quizz quizz : quizzList) {
|
||||
result.add(quizz.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package fr.istic.taa.jaxrs;
|
||||
|
||||
import io.undertow.Undertow;
|
||||
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* RESTfull microservice, based on JAX-RS and JBoss Undertow
|
||||
*
|
||||
*/
|
||||
public class RestServer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(RestServer.class.getName());
|
||||
|
||||
public static void main(String[] args) {
|
||||
UndertowJaxrsServer ut = new UndertowJaxrsServer();
|
||||
TestApplication ta = new TestApplication();
|
||||
ut.deploy(ta);
|
||||
ut.start(
|
||||
Undertow.builder()
|
||||
.addHttpListener(8080, "localhost")
|
||||
|
||||
);
|
||||
|
||||
logger.info("JAX-RS based micro-service running!");
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright Red Hat, Inc., and individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package fr.istic.taa.jaxrs;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import fr.istic.taa.jaxrs.rest.*;
|
||||
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
|
||||
import jakarta.ws.rs.ApplicationPath;
|
||||
import jakarta.ws.rs.core.Application;
|
||||
|
||||
@ApplicationPath("/")
|
||||
public class TestApplication extends Application {
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
|
||||
final Set<Class<?>> clazzes = new HashSet<Class<?>>();
|
||||
|
||||
clazzes.add(OpenApiResource.class);
|
||||
clazzes.add(QuestionResource.class);
|
||||
clazzes.add(QuizzResource.class);
|
||||
clazzes.add(UtilisateurResource.class);
|
||||
clazzes.add(SessionResource.class);
|
||||
clazzes.add(SwaggerResource.class);
|
||||
return clazzes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.QuestionDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuestionDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuestionMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Choix;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
|
||||
@Path("question")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class QuestionResource {
|
||||
private final QuestionDAO questionDAO = new QuestionDAO();
|
||||
private final QuestionMapper mapper = QuestionMapper.INSTANCE;
|
||||
|
||||
@GET
|
||||
@Operation(summary = "List all questions",
|
||||
tags = {"Questions"},
|
||||
description = "List all questions.",
|
||||
responses = {
|
||||
@ApiResponse(description = "List of all questions", content = @Content(
|
||||
array = @ArraySchema(schema = @Schema(implementation = Question.class))))
|
||||
}
|
||||
)
|
||||
public List<QuestionDTO> listQuestion() {
|
||||
List<Question> questions = questionDAO.findAll();
|
||||
return mapper.toDTOs(questions);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/addQuestion")
|
||||
@Operation(summary = "Create a new question",
|
||||
tags = {"Questions"},
|
||||
description = "Create a new question",
|
||||
responses = {@ApiResponse(responseCode = "201", description = "Question added.")}
|
||||
)
|
||||
public Response addQuestion(
|
||||
@Parameter(description = "The question details to be added", required = true) QuestionDTO dto) {
|
||||
Question question = mapper.toEntity(dto);
|
||||
questionDAO.create(question);
|
||||
return Response.status(Response.Status.CREATED).entity("Question ajouté avec Succès : \"" + dto.getEnonce() + "\"").build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/changeQuestion/")
|
||||
@Operation(summary = "Update the text of a question",
|
||||
tags = {"Questions"},
|
||||
description = "Update the text of a question.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Question answer updated."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response changeQuestion(
|
||||
@Parameter(description = "ID of the question to modify", required = true) @PathParam("question_id") Integer id,
|
||||
@Parameter(description = "New answer for the question", required = true) String newQuestion) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.changeEnonce(newQuestion, id);
|
||||
return Response.status(Response.Status.CREATED).entity("Enonce de la question mis à jour : " + newQuestion).build();
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{question_id}/getReponse/")
|
||||
@Operation(summary = "Get the correct answer for question",
|
||||
tags = {"Questions"},
|
||||
description = "Get the correct answer for question by ID of question.",
|
||||
responses = {
|
||||
@ApiResponse(description = "The correct answer", content = @Content(
|
||||
schema = @Schema(implementation = Reponse.class))),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response getReponse(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
Reponse result = question.getReponse();
|
||||
return Response.ok(result).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/addReponse/")
|
||||
@Operation(summary = "Add/Update the correct answer for question",
|
||||
tags = {"Questions"},
|
||||
description = "Add/Update the correct answer for question",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Answer text updated."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response addReponse(
|
||||
@Parameter(description = "ID of the question", required = true) @PathParam("question_id") Integer id,
|
||||
@Parameter(description = "The correct answer", required = true) String reponse) {
|
||||
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.addReponse(reponse, id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponse correct \"" + reponse + "\" ajouté à la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{question_id}/deletReponses/")
|
||||
@Operation(summary = "Removes the correct response.",
|
||||
tags = {"Questions"},
|
||||
description = "Removes the correct response.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Response deleted."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response deleteReponses(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.deleteReponse(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses supprimé de la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/setReponse/choix")
|
||||
@Operation(summary = "Set question type to multiple choice",
|
||||
tags = {"Questions"},
|
||||
description = "Set question type to multiple choice type. It could override old answers",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Question type set to multiple choice."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response setChoix(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.setChoix(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses à choix multiple mise sur la question " + id).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/setReponse/reponseCourte")
|
||||
@Operation(summary = "Set question type to short answer",
|
||||
tags = {"Questions"},
|
||||
description = "Set question type to multiple short answer. It could override old answers",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Question type set to short answer."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response setReponseCourte(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.setReponseCourte(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses courte mise sur la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/AddChoix")
|
||||
@Operation(summary = "Add a choice option to a multiple-choice question",
|
||||
tags = {"Questions"},
|
||||
description = "Adds a new choice option to the question (Type Multiple Choice obligatoire)",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Choice added."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found"),
|
||||
@ApiResponse(responseCode = "400", description = "Wrong type")
|
||||
}
|
||||
)
|
||||
public Response addChoix(
|
||||
@Parameter(description = "ID of the question", required = true) @PathParam("question_id") Integer id,
|
||||
@Parameter(description = "The choice", required = true) String choix){
|
||||
Question question = questionDAO.findById(id);
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
if (question.getReponse() instanceof Choix) {
|
||||
return Response.status(Response.Status.EXPECTATION_FAILED).build();
|
||||
}
|
||||
questionDAO.addChoix(id, choix);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses courte mise sur la question " + id).build();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.QuestionDAO;
|
||||
import fr.istic.taa.jaxrs.DAO.QuizzDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuestionDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuizzDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuestionMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuizzMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("quizz")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class QuizzResource {
|
||||
public final QuizzMapper mapper = QuizzMapper.INSTANCE;
|
||||
public final QuizzDAO quizzDAO = new QuizzDAO();
|
||||
public final QuestionDAO questionDAO = new QuestionDAO();
|
||||
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/addQuizz")
|
||||
@Operation(summary = "Create a new quizz",
|
||||
tags = {"Quizz"},
|
||||
description = "Create a new quizz",
|
||||
responses = {@ApiResponse(responseCode = "201", description = "Quizz added.")}
|
||||
)
|
||||
public Response addQuizz(
|
||||
@Parameter(description = "The quizz details to be added", required = true) QuizzDTO dto) {
|
||||
Quizz quizz = mapper.toEntity(dto);
|
||||
quizzDAO.create(quizz);
|
||||
return Response.status(Response.Status.CREATED).entity("Quizz ajouté avec Succès : \"" + dto.getId() + "\"").build();
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Operation(summary = "List all quizz",
|
||||
tags = {"Quizz"},
|
||||
description = "List all quizz.",
|
||||
responses = {
|
||||
@ApiResponse(description = "List of all quizz", content = @Content(
|
||||
array = @ArraySchema(schema = @Schema(implementation = Question.class))))
|
||||
}
|
||||
)
|
||||
public List<QuizzDTO> listQuizz() {
|
||||
List<Quizz> quizz = quizzDAO.findAll();
|
||||
return mapper.toDTOs(quizz);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{quizz_id}")
|
||||
@Operation(summary = "Get a quizz by ID",
|
||||
tags = {"Quizzes"},
|
||||
description = "Get a quizz by ID",
|
||||
responses = {
|
||||
@ApiResponse(description = "The quizz by ID", content = @Content(
|
||||
schema = @Schema(implementation = QuizzDTO.class))),
|
||||
@ApiResponse(responseCode = "404", description = "Quizz not found")
|
||||
}
|
||||
)
|
||||
public Response getQuizzById(
|
||||
@Parameter(description = "ID of the quizz to fetch", required = true)
|
||||
@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
QuizzDTO dto = mapper.toDTO(quizz);
|
||||
return Response.status(Response.Status.OK).entity(dto).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{quizz_id}/questions")
|
||||
@Operation(summary = "List all questions for a quizz",
|
||||
tags = {"Quizzes"},
|
||||
description = "List all questions by quizz ID.",
|
||||
responses = {
|
||||
@ApiResponse(description = "List of questions", content = @Content(
|
||||
array = @ArraySchema(schema = @Schema(implementation = QuestionDTO.class)))),
|
||||
@ApiResponse(responseCode = "404", description = "Quizz not found")
|
||||
}
|
||||
)
|
||||
public Response getQuestions(
|
||||
@Parameter(description = "ID of the quizz", required = true)
|
||||
@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<Question> questionList = quizz.getQuestions();
|
||||
List<QuestionDTO> dtos = QuestionMapper.INSTANCE.toDTOs(questionList);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(dtos).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{quizz_id}/add_question/{question_id}")
|
||||
@Operation(summary = "Add a question to a quizz",
|
||||
tags = {"Quizzes"},
|
||||
description = "Add question to quizz by quizz ID and question ID.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "Question added successfully",
|
||||
content = @Content(schema = @Schema(implementation = QuizzDTO.class))),
|
||||
@ApiResponse(responseCode = "404", description = "Quizz or Question not found")
|
||||
}
|
||||
)
|
||||
public Response addQuestion(
|
||||
@Parameter(description = "ID of the quizz to update", required = true) @PathParam("quizz_id") Integer quizzId,
|
||||
@Parameter(description = "ID of the question to add", required = true) @PathParam("question_id") Integer questionId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
Question question = questionDAO.findById(questionId);
|
||||
if (quizz == null || question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
quizzDAO.addQuestion(quizzId, questionId);
|
||||
quizzDAO.update(quizz);
|
||||
QuizzDTO quizzDTO = mapper.toDTO(quizz);
|
||||
return Response.status(Response.Status.OK).entity(quizzDTO).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{quizz_id}/deleteQ")
|
||||
@Operation(summary = "Remove all questions from a quizz",
|
||||
tags = {"Quizzes"},
|
||||
description = "Removes all questions by ID of quizz.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "Removed all questions"),
|
||||
@ApiResponse(responseCode = "404", description = "Quizz not found")}
|
||||
)
|
||||
public Response deleteQuestion(
|
||||
@Parameter(description = "ID of the quizz", required = true)
|
||||
@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
quizzDAO.deleteAllQuestion(quizzId);
|
||||
quizzDAO.update(quizz);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{quizz_id}/delete")
|
||||
@Operation(summary = "Delete a Quizz",
|
||||
tags = {"Quizzes"},
|
||||
description = "Deletes a Quizz by ID.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "Quizz deleted."),
|
||||
@ApiResponse(responseCode = "404", description = "Quizz not found.")
|
||||
}
|
||||
)
|
||||
public Response deleteQuizz(
|
||||
@Parameter(description = "ID of the Quizz to delete", required = true)
|
||||
@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
quizzDAO.delete(quizz);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.SessionDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuizzDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.SessionDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.UtilisateurDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuizzMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.SessionMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.UtilisateurMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
|
||||
@Path("session")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class SessionResource {
|
||||
private final SessionDAO sessionDAO = new SessionDAO();
|
||||
private final SessionMapper mapper = SessionMapper.INSTANCE;
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/addSession")
|
||||
@Operation(summary = "Create a new session",
|
||||
tags = {"Session"},
|
||||
description = "Create a new session",
|
||||
responses = {@ApiResponse(responseCode = "201", description = "Session added.")}
|
||||
)
|
||||
public Response addQuizz(
|
||||
@Parameter(description = "The session details to be added", required = true) SessionDTO dto) {
|
||||
Session session = mapper.toEntity(dto);
|
||||
sessionDAO.create(session);
|
||||
return Response.status(Response.Status.CREATED).entity("Session ajouté avec Succès : \"" + dto.getTheme() + "\"").build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Operation(summary = "List all session", tags = {"Sessions"},
|
||||
description = "Get a list of all sessions in BDD",
|
||||
responses = {@ApiResponse(description = "List of sessions", content = @Content(
|
||||
schema = @Schema(implementation = Session.class)
|
||||
))
|
||||
}
|
||||
)
|
||||
public List<SessionDTO> listSession() {
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
return mapper.toDTOs(sessions);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@Operation(summary = "Get session by ID",
|
||||
tags = {"Sessions"},
|
||||
description = "Get session by ID.",
|
||||
responses = {
|
||||
@ApiResponse(description = "Session", content = @Content(
|
||||
schema = @Schema(implementation = SessionDTO.class)
|
||||
)),
|
||||
@ApiResponse(responseCode = "404", description = "Session not found")
|
||||
}
|
||||
)
|
||||
public Response getSession(
|
||||
@Parameter(description = "ID of the session to fetch", required = true)
|
||||
@PathParam("id") Integer id) {
|
||||
Session session = sessionDAO.findById(id);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
SessionDTO result = mapper.toDTO(session);
|
||||
return Response.status(Response.Status.OK).entity(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{session_id}/quizzs")
|
||||
@Operation(summary = "Get all quizzes for a session",
|
||||
tags = {"Sessions"},
|
||||
description = "Get all quizzes for a session by ID of session.",
|
||||
responses = {
|
||||
@ApiResponse(description = "List of quizzes", content = @Content(
|
||||
array = @ArraySchema(schema = @Schema(implementation = QuizzDTO.class))
|
||||
)),
|
||||
@ApiResponse(responseCode = "404", description = "Session not found")
|
||||
}
|
||||
)
|
||||
public Response getQuizzs(
|
||||
@Parameter(description = "ID of the session to get quizzes", required = true)
|
||||
@PathParam("session_id") Integer sessionId) {
|
||||
Session session = sessionDAO.findById(sessionId);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<QuizzDTO> results = QuizzMapper.INSTANCE.toDTOs(session.getQuizzs());
|
||||
return Response.status(Response.Status.OK).entity(results).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{session_id}/utilisateurs")
|
||||
@Operation(summary = "Get all users for a session",
|
||||
tags = {"Sessions"},
|
||||
description = "Get all users for a session by ID of session.",
|
||||
responses = {
|
||||
@ApiResponse(description = "List of users", content = @Content(
|
||||
array = @ArraySchema(schema = @Schema(implementation = UtilisateurDTO.class))
|
||||
)),
|
||||
@ApiResponse(responseCode = "404", description = "Session not found")
|
||||
}
|
||||
)
|
||||
public Response getUtilisateurs(
|
||||
@Parameter(description = "ID of the session to get users", required = true)
|
||||
@PathParam("session_id") Integer sessionId) {
|
||||
|
||||
Session session = sessionDAO.findById(sessionId);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<Utilisateur> utilisateurList = session.getUtilisateurs();
|
||||
List<UtilisateurDTO> dtos = UtilisateurMapper.INSTANCE.toDTOs(utilisateurList);
|
||||
return Response.status(Response.Status.OK).entity(dtos).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{session_id}/delete")
|
||||
@Operation(summary = "Delete a session",
|
||||
tags = {"Sessions"},
|
||||
description = "Deletes a session by ID of session.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "Session deleted"),
|
||||
@ApiResponse(responseCode = "404", description = "Session not found")
|
||||
}
|
||||
)
|
||||
public Response deleteSession(
|
||||
@Parameter(description = "ID of the session to delete", required = true)
|
||||
@PathParam("session_id") Integer sessionId) {
|
||||
Session session = sessionDAO.findById(sessionId);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
sessionDAO.delete(session);
|
||||
return Response.status(Response.Status.OK).entity("Session deleted").build();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
|
||||
@Path("/api")
|
||||
public class SwaggerResource {
|
||||
private static final Logger logger = Logger.getLogger(SwaggerResource.class.getName());
|
||||
|
||||
private static final String SWAGGER_BASE_PATH = "swagger/";
|
||||
|
||||
@GET
|
||||
public Response Get1() {
|
||||
return getFileContent("index.html");
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{path:.*}")
|
||||
public Response Get(@PathParam("path") String path) {
|
||||
return getFileContent(path);
|
||||
}
|
||||
|
||||
private Response getFileContent(String fileName) {
|
||||
String fullPath = SWAGGER_BASE_PATH + fileName;
|
||||
try (InputStream is = getClass().getClassLoader().getResourceAsStream(fullPath)) {
|
||||
if (is == null) {
|
||||
logger.warning("File not found: " + fullPath);
|
||||
return Response.status(Response.Status.NOT_FOUND).build(); // HTTP 404
|
||||
}
|
||||
return Response.ok(is.readAllBytes()).build();
|
||||
} catch (IOException e) {
|
||||
logger.severe("Error reading file " + fullPath + ": " + e.getMessage());
|
||||
return Response.serverError().build(); // HTTP 500
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.SessionDAO;
|
||||
import fr.istic.taa.jaxrs.DAO.UtilisateurDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.SessionDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.UtilisateurDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.SessionMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.UtilisateurMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Path("utilisateur")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class UtilisateurResource {
|
||||
private final UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||
private final UtilisateurMapper mapper = UtilisateurMapper.INSTANCE;
|
||||
|
||||
@GET
|
||||
@Operation(summary = "List all users", tags = {"Utilisateurs"},
|
||||
description = "Get a list of all users in BDD",
|
||||
responses = {@ApiResponse(description = "List of users", content = @Content(
|
||||
schema = @Schema(implementation = Utilisateur.class)
|
||||
))
|
||||
}
|
||||
)
|
||||
public List<UtilisateurDTO> listUtilisateur() {
|
||||
List<Utilisateur> utilisateurs = utilisateurDAO.findAll();
|
||||
return mapper.toDTOs(utilisateurs);
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/9269040/which-http-response-code-for-this-email-is-already-registered
|
||||
@POST
|
||||
@Path("/register")
|
||||
@Operation(summary = "Register a new user",
|
||||
tags = {"Utilisateurs"},
|
||||
description = "Registers a new user.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Registration succès"),
|
||||
@ApiResponse(responseCode = "409", description = "Email est déjà registré")
|
||||
}
|
||||
)
|
||||
public Response registerUtilisateur(
|
||||
@Parameter(description = "User details for registration", required = true) UtilisateurDTO dto) {
|
||||
String email_verification = dto.getEmail();
|
||||
Utilisateur existing = utilisateurDAO.findByEmail(email_verification);
|
||||
|
||||
//VERIFACTION S'IL EXISTE DANS BDD
|
||||
if (existing != null) {
|
||||
return Response.status(Response.Status.CONFLICT).entity("Email est déjà registré").build();
|
||||
}
|
||||
|
||||
Utilisateur utilisateur = mapper.toEntity(dto);
|
||||
utilisateurDAO.create(utilisateur);
|
||||
|
||||
return Response.status(Response.Status.CREATED).entity("Registration succès").build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/login")
|
||||
@Operation(summary = "Log in a user",
|
||||
tags = {"Utilisateurs"},
|
||||
description = "Authenticates a user and returns the user's details upon success.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "Successful login", content = @Content(
|
||||
schema = @Schema(implementation = UtilisateurDTO.class)
|
||||
)),
|
||||
@ApiResponse(responseCode = "404", description = "Email n'existe pas"),
|
||||
@ApiResponse(responseCode = "401", description = "Mauvais mdp")
|
||||
}
|
||||
)
|
||||
public Response loginUtilisateur(
|
||||
@Parameter(description = "User credentials (email and password)", required = true) UtilisateurDTO dto) {
|
||||
Utilisateur utilisateur = utilisateurDAO.findByEmail(dto.getEmail());
|
||||
|
||||
if (utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Email n'existe pas").build();
|
||||
} else if (!utilisateur.getPassword().equals(dto.getPassword())) {
|
||||
return Response.status(Response.Status.UNAUTHORIZED).entity("Mauvais mdp").build();
|
||||
}
|
||||
UtilisateurDTO result = mapper.toDTO(utilisateur);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@Operation(summary = "Get user by ID",
|
||||
tags = {"Utilisateurs"},
|
||||
description = "Get User by ID",
|
||||
responses = {
|
||||
@ApiResponse(description = "Utilisateur", content = @Content(
|
||||
schema = @Schema(implementation = Utilisateur.class)
|
||||
)),
|
||||
@ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found")
|
||||
})
|
||||
public Response getUtilisateur(@Parameter(
|
||||
description = "ID of user that needs to be fetched",
|
||||
schema = @Schema(
|
||||
type = "integer",
|
||||
format = "int32",
|
||||
description = "param ID of user that needs to be fetched"
|
||||
),
|
||||
required = true)
|
||||
@PathParam("id") Integer id) {
|
||||
Utilisateur utilisateur = utilisateurDAO.findById(id);
|
||||
if (utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
UtilisateurDTO result = mapper.toDTO(utilisateur);
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{user_id}/add_session/{session_id}")
|
||||
@Operation(summary = "Add a session to a user",
|
||||
tags = {"Utilisateurs"},
|
||||
description = "Add a session to a user existed in BDD",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "Session added successfully", content = @Content(
|
||||
schema = @Schema(implementation = UtilisateurDTO.class) // Returns updated user DTO
|
||||
)),
|
||||
@ApiResponse(responseCode = "404", description = "User or Session not found"),
|
||||
@ApiResponse(responseCode = "409", description = "User is already in the session")
|
||||
}
|
||||
)
|
||||
public Response addSession(
|
||||
@Parameter(description = "ID of the user") @PathParam("user_id") Integer user_id,
|
||||
@Parameter(description = "ID of the session to add") @PathParam("session_id") Integer session_id) {
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
|
||||
Session existingSession = sessionDAO.findById(session_id);
|
||||
Utilisateur utilisateur = utilisateurDAO.findById(user_id);
|
||||
|
||||
if (existingSession == null || utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
//If user already joined
|
||||
if (utilisateur.getSessions().contains(existingSession)) {
|
||||
return Response.status(Response.Status.CONFLICT).build();
|
||||
}
|
||||
utilisateurDAO.addToSession(user_id, session_id);
|
||||
utilisateurDAO.update(utilisateur);
|
||||
|
||||
// We update it so have to return new DTO
|
||||
UtilisateurDTO dto = mapper.toDTO(utilisateur);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(dto).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{user_id}/session")
|
||||
@Operation(summary = "List of all sessions of a user",
|
||||
tags = {"Utilisateurs"},
|
||||
description = "Return a response of all sessions of a user",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "List of user's sessions", content = @Content(
|
||||
schema = @Schema(implementation = SessionDTO.class)
|
||||
)),
|
||||
@ApiResponse(responseCode = "404", description = "User not found")
|
||||
}
|
||||
)
|
||||
public Response listSession(
|
||||
@Parameter(description = "ID of the user") @PathParam("user_id") Integer user_id) {
|
||||
|
||||
Utilisateur utilisateur = utilisateurDAO.findById(user_id);
|
||||
if (utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<Session> sess = utilisateur.getSessions();
|
||||
List<SessionDTO> dtos = SessionMapper.INSTANCE.toDTOs(sess);
|
||||
return Response.status(Response.Status.OK).entity(dtos).build();
|
||||
}
|
||||
@DELETE
|
||||
@Path("{user_id}/delete")
|
||||
@Operation(summary = "Delete a user",
|
||||
tags = {"Utilisateurs"},
|
||||
description = "Delete a user with ID",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "User deleted"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found")
|
||||
}
|
||||
)
|
||||
public Response deleteUtilisateur(
|
||||
@Parameter(description = "ID of the user to delete") @PathParam("user_id") Integer user_id) {
|
||||
Utilisateur existing = utilisateurDAO.findById(user_id);
|
||||
if (existing == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
utilisateurDAO.delete(existing);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
}
|
||||
50
src/main/java/jpa/EntityManagerHelper.java
Normal file
50
src/main/java/jpa/EntityManagerHelper.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package jpa;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
|
||||
public class EntityManagerHelper {
|
||||
|
||||
private static final EntityManagerFactory emf;
|
||||
private static final ThreadLocal<EntityManager> threadLocal;
|
||||
|
||||
static {
|
||||
emf = Persistence.createEntityManagerFactory("dev");
|
||||
threadLocal = new ThreadLocal<EntityManager>();
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
EntityManager em = threadLocal.get();
|
||||
|
||||
if (em == null) {
|
||||
em = emf.createEntityManager();
|
||||
threadLocal.set(em);
|
||||
}
|
||||
return em;
|
||||
}
|
||||
|
||||
public static void closeEntityManager() {
|
||||
EntityManager em = threadLocal.get();
|
||||
if (em != null) {
|
||||
em.close();
|
||||
threadLocal.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeEntityManagerFactory() {
|
||||
emf.close();
|
||||
}
|
||||
|
||||
public static void beginTransaction() {
|
||||
getEntityManager().getTransaction().begin();
|
||||
}
|
||||
|
||||
public static void rollback() {
|
||||
getEntityManager().getTransaction().rollback();
|
||||
}
|
||||
|
||||
public static void commit() {
|
||||
getEntityManager().getTransaction().commit();
|
||||
}
|
||||
}
|
||||
150
src/main/java/jpa/JpaTest.java
Normal file
150
src/main/java/jpa/JpaTest.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package jpa;
|
||||
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.criteria.*;
|
||||
import metier.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JpaTest {
|
||||
private EntityManager manager;
|
||||
|
||||
public JpaTest(EntityManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EntityManager manager = EntityManagerHelper.getEntityManager();
|
||||
|
||||
JpaTest test = new JpaTest(manager);
|
||||
|
||||
EntityTransaction tx = manager.getTransaction();
|
||||
tx.begin();
|
||||
try {
|
||||
test.create_user_test();
|
||||
test.create_session_test();
|
||||
test.create_quizz_test(1,1);
|
||||
test.list_utilisateur();
|
||||
test.list_session();
|
||||
test.list_quizz();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tx.commit();
|
||||
|
||||
manager.close();
|
||||
EntityManagerHelper.closeEntityManagerFactory();
|
||||
System.out.println(".. done");
|
||||
}
|
||||
|
||||
private void create_user_test() {
|
||||
int numUser = manager.createQuery("SELECT u FROM Utilisateur u", Utilisateur.class).getResultList().size();
|
||||
if (numUser == 0) {
|
||||
//Utilisateur
|
||||
Utilisateur utilisateur1 = new Utilisateur();
|
||||
utilisateur1.setName("Titi");
|
||||
utilisateur1.setEmail("titi@email.com");
|
||||
utilisateur1.setPassword("123456");
|
||||
|
||||
Utilisateur utilisateur2 = new Utilisateur();
|
||||
utilisateur2.setName("Toto");
|
||||
|
||||
manager.persist(utilisateur1);
|
||||
manager.persist(utilisateur2);
|
||||
}
|
||||
}
|
||||
|
||||
private void create_session_test() {
|
||||
int numUser = manager.createQuery("SELECT u FROM Session u", Session.class).getResultList().size();
|
||||
if (numUser == 0) {
|
||||
//Utilisateur
|
||||
Session session1 = new Session();
|
||||
session1.setCodePIN(1703);
|
||||
session1.setTheme("Inphormatik");
|
||||
session1.setQuizzs(new ArrayList<>());
|
||||
|
||||
List<Utilisateur> ulist = manager.createQuery("select user from Utilisateur user").getResultList();
|
||||
session1.setUtilisateurs(ulist);
|
||||
|
||||
manager.persist(session1);
|
||||
}
|
||||
}
|
||||
|
||||
private void list_utilisateur() {
|
||||
CriteriaBuilder criteriaBuilder = manager.getCriteriaBuilder();
|
||||
CriteriaQuery<Utilisateur> query = criteriaBuilder.createQuery(Utilisateur.class);
|
||||
Root<Utilisateur> from = query.from(Utilisateur.class);
|
||||
query.select(from);
|
||||
List<Utilisateur> result_utilisatuer_list = manager.createQuery(query).getResultList();
|
||||
for (Utilisateur u : result_utilisatuer_list) {
|
||||
System.out.println(u.getId() + " " + u.getName() + " " + u.getEmail());
|
||||
}
|
||||
}
|
||||
|
||||
private void list_session() {
|
||||
CriteriaBuilder criteriaBuilder = manager.getCriteriaBuilder();
|
||||
CriteriaQuery<Session> query = criteriaBuilder.createQuery(Session.class);
|
||||
Root<Session> from = query.from(Session.class);
|
||||
query.select(from);
|
||||
List<Session> result_session_list = manager.createQuery(query).getResultList();
|
||||
for (Session s : result_session_list) {
|
||||
System.out.println(s.getCodePIN() + " " + s.getTheme());
|
||||
for (Utilisateur u : s.getUtilisateurs()) {
|
||||
System.out.println(u.getId() + " " + u.getName() + " " + u.getEmail());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void create_quizz_test(int userId, int sessionId) {
|
||||
|
||||
CriteriaBuilder cb = manager.getCriteriaBuilder();
|
||||
|
||||
//GET USER
|
||||
CriteriaQuery<Utilisateur> cqUser = cb.createQuery(Utilisateur.class);
|
||||
Root<Utilisateur> userRoot = cqUser.from(Utilisateur.class);
|
||||
cqUser.select(userRoot).where(cb.equal(userRoot.get("id"), userId));
|
||||
Utilisateur u1 = manager.createQuery(cqUser).getSingleResult();
|
||||
|
||||
//GET SESSION
|
||||
CriteriaQuery<Session> cqSess = cb.createQuery(Session.class);
|
||||
Root<Session> sessRoot = cqSess.from(Session.class);
|
||||
cqSess.select(sessRoot).where(cb.equal(sessRoot.get("id"), sessionId));
|
||||
Session s1 = manager.createQuery(cqSess).getSingleResult();
|
||||
|
||||
List<Session> ls= u1.getSessions();
|
||||
ls.add(s1);
|
||||
u1.setSessions(ls);
|
||||
Quizz quizz1 = new Quizz();
|
||||
quizz1.setCreateur(u1);
|
||||
quizz1.getSessions().add(s1);
|
||||
|
||||
manager.persist(quizz1);
|
||||
manager.merge(u1);
|
||||
manager.persist(s1);
|
||||
}
|
||||
|
||||
private void list_quizz() {
|
||||
CriteriaBuilder cb = manager.getCriteriaBuilder();
|
||||
CriteriaQuery<Quizz> cq = cb.createQuery(Quizz.class);
|
||||
Root<Quizz> from = cq.from(Quizz.class);
|
||||
|
||||
List<Integer> sessionIds = new ArrayList<>();
|
||||
sessionIds.add(1);
|
||||
//https://www.w3schools.com/SQL/sql_join_inner.asp
|
||||
//https://stackoverflow.com/questions/15990141/how-to-make-a-criteriabuilder-join-with-a-custom-on-condition
|
||||
Join<Quizz, Session> sessionJoin = from.join("session", JoinType.INNER);
|
||||
cq.select(from).where(sessionJoin.get("id").in(sessionIds));
|
||||
|
||||
List<Quizz> quizzs = manager.createQuery(cq).getResultList();
|
||||
for (Quizz q : quizzs) {
|
||||
System.out.println("Quizz ID: " + q.getId() + ", User: " + q.getCreateur().getName() +
|
||||
", nb session: " + q.getSessions().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Choix extends Reponse{
|
||||
String res = "";
|
||||
|
||||
for (String val : this.choix) {
|
||||
res+=val+"<br/>";
|
||||
res+= val+"<br/>";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -12,7 +11,6 @@ import java.io.Serializable;
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
public class Question implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -14,19 +13,22 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
public class Quizz implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@ManyToMany
|
||||
private List<Session> sessions;
|
||||
private List<Session> sessions = new ArrayList<Session>();
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_utilisateur")
|
||||
private Utilisateur createur;
|
||||
|
||||
@OneToMany(mappedBy = "quizz")
|
||||
@OneToMany(mappedBy = "quizz", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Question> questions=new ArrayList<Question>();
|
||||
|
||||
public void addQuestion(Question question) {
|
||||
this.questions.add(question);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
@@ -23,7 +22,7 @@ public abstract class Reponse implements Serializable {
|
||||
|
||||
@OneToOne
|
||||
private Question question;
|
||||
public List<String> reponses = new ArrayList<String>();
|
||||
public List<String> reponses;
|
||||
|
||||
public String valHTML(){
|
||||
return "";
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||
@@ -16,6 +16,6 @@ public class ReponseCourte extends Reponse{
|
||||
|
||||
@Override
|
||||
public String valHTML(){
|
||||
return "INPUT";
|
||||
return "TEXT INPUT<br/>";
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -14,7 +13,6 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
public class Session implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -22,11 +20,11 @@ public class Session implements Serializable {
|
||||
|
||||
@Column(unique=true)
|
||||
private int codePIN;
|
||||
|
||||
@ManyToMany(mappedBy="sessions", fetch = FetchType.EAGER)
|
||||
|
||||
@ManyToMany(mappedBy="sessions")
|
||||
private List<Quizz> quizzs = new ArrayList<>();
|
||||
|
||||
@ManyToMany(mappedBy = "sessions", fetch = FetchType.EAGER)
|
||||
@ManyToMany(mappedBy = "sessions")
|
||||
private List<Utilisateur> utilisateurs = new ArrayList<>();
|
||||
private String theme;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -11,7 +10,6 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
public class Utilisateur implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -28,8 +26,8 @@ public class Utilisateur implements Serializable {
|
||||
joinColumns = @JoinColumn(name="utilisateur_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "session_id")
|
||||
)
|
||||
private List<Session> sessions= new ArrayList<Session>();
|
||||
private List<Session> sessions= new ArrayList<>();;
|
||||
|
||||
@OneToMany(mappedBy = "createur")
|
||||
private List<Quizz> quizzs = new ArrayList<Quizz>();;
|
||||
private List<Quizz> quizzs;
|
||||
}
|
||||
27
src/main/java/servlet/MyServlet.java
Normal file
27
src/main/java/servlet/MyServlet.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet(name="mytest",
|
||||
urlPatterns={"/myurl"})
|
||||
public class MyServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
PrintWriter p = new PrintWriter(resp.getOutputStream());
|
||||
p.print("Hello world");
|
||||
p.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
super.doPost(req, resp);
|
||||
}
|
||||
}
|
||||
90
src/main/java/servlet/QuestionInfo.java
Normal file
90
src/main/java/servlet/QuestionInfo.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import DAO.*;
|
||||
import metier.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
@WebServlet(name="question",
|
||||
urlPatterns={"/QuestionInfo"})
|
||||
public class QuestionInfo extends HttpServlet {
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.getRequestDispatcher("/Question.html").forward(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
QuestionDAO questionDAO = new QuestionDAO();
|
||||
ReponseDAO reponseDAO = new ReponseDAO();
|
||||
|
||||
|
||||
String ennonce = req.getParameter("question");
|
||||
String type = req.getParameter("type");
|
||||
String choixPossible = req.getParameter("choixPossible");
|
||||
String reponse = req.getParameter("reponse");
|
||||
String idQuizz = req.getParameter("idQuizz");
|
||||
|
||||
Quizz quizz = quizzDAO.findById(Integer.parseInt(idQuizz));
|
||||
if(quizz==null){
|
||||
resp.getWriter().println("<HTML>\n<BODY>\n" +
|
||||
"<H1> Quizz non trouvable </H1>" +
|
||||
"</BODY></HTML>");
|
||||
return ;
|
||||
}
|
||||
Question question = new Question();
|
||||
question.setEnonce(ennonce);
|
||||
|
||||
List<String> listRep = Arrays.asList(reponse.split("\n"));
|
||||
|
||||
questionDAO.create(question);
|
||||
|
||||
if(type.equals("choix")){
|
||||
Choix choix = new Choix();
|
||||
//question.setReponse(choix);
|
||||
List<String> listChoix = Arrays.asList(choixPossible.split("\n"));
|
||||
choix.setChoix(listChoix);
|
||||
choix.setReponses(listRep);
|
||||
|
||||
reponseDAO.create(choix);
|
||||
reponseDAO.addToQuestion(choix, question);
|
||||
|
||||
}
|
||||
else if (type.equals("courte")){
|
||||
ReponseCourte reponseCourte = new ReponseCourte();
|
||||
//question.setReponse(reponseCourte);
|
||||
reponseCourte.setReponses(listRep);
|
||||
|
||||
reponseDAO.create(reponseCourte);
|
||||
reponseDAO.addToQuestion(reponseCourte, question);
|
||||
}
|
||||
else{
|
||||
resp.getWriter().println(
|
||||
"<HTML>\n<BODY>\n" +
|
||||
"<H1> Type de question non trouvé </H1>" +
|
||||
"</BODY></HTML>"
|
||||
);
|
||||
return ;
|
||||
}
|
||||
quizzDAO.addQuestion(quizz,question);
|
||||
|
||||
|
||||
|
||||
|
||||
resp.getWriter().println(
|
||||
"<HTML>\n<BODY>\n" +
|
||||
"<H1> Question \"" + question.getEnonce() + "\" creee </H1>" +
|
||||
"</BODY></HTML>"
|
||||
);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
56
src/main/java/servlet/QuizzInfo.java
Normal file
56
src/main/java/servlet/QuizzInfo.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import DAO.QuizzDAO;
|
||||
import DAO.UtilisateurDAO;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import metier.Quizz;
|
||||
import metier.Utilisateur;
|
||||
|
||||
@WebServlet(name="quizz",
|
||||
urlPatterns={"/QuizzInfo"})
|
||||
public class QuizzInfo extends HttpServlet {
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.getRequestDispatcher("/Quizz.html").forward(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
//Utilisateur
|
||||
UtilisateurDAO uDAO = new UtilisateurDAO();
|
||||
String email_user = req.getParameter("email_User");
|
||||
String id_User = req.getParameter("id_User");
|
||||
|
||||
Utilisateur u_cree_quizz = null;
|
||||
|
||||
if (id_User != null && !id_User.isEmpty()) {
|
||||
int id = Integer.parseInt(id_User);
|
||||
u_cree_quizz=uDAO.findById(id);
|
||||
}else if(email_user != null && !email_user.isEmpty()){
|
||||
u_cree_quizz=uDAO.findByEmail(email_user);
|
||||
}
|
||||
|
||||
if (u_cree_quizz == null) {
|
||||
resp.getWriter().println("<HTML>\n<BODY>\n" +
|
||||
"<H1> Utilisateur non trouvable </H1>" +
|
||||
"</BODY></HTML>");
|
||||
return ;
|
||||
}
|
||||
Quizz quizz = new Quizz();
|
||||
quizz.setCreateur(u_cree_quizz);
|
||||
//quizz.setSession(s_attached);
|
||||
quizzDAO.create(quizz);
|
||||
|
||||
resp.getWriter().println("<HTML>\n<BODY>\n" +
|
||||
"<H1>Quizz cree par " + u_cree_quizz.getName() + "</H1>" +
|
||||
"</BODY></HTML>");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
59
src/main/java/servlet/SessionInfo.java
Normal file
59
src/main/java/servlet/SessionInfo.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import DAO.*;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import metier.Quizz;
|
||||
import metier.Session;
|
||||
|
||||
@WebServlet(name = "session", urlPatterns = {"/SessionInfo"})
|
||||
public class SessionInfo extends HttpServlet {
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
UtilisateurDAO uDAO = new UtilisateurDAO();
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.getRequestDispatcher("/Session.html").forward(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String action = req.getParameter("action");
|
||||
if (action.equals("createSession")) {
|
||||
// Créer une nouvelle session
|
||||
String theme = req.getParameter("theme");
|
||||
String codePin = req.getParameter("codePIN");
|
||||
Session s = new Session();
|
||||
s.setCodePIN(Integer.parseInt(codePin));
|
||||
s.setTheme(theme);
|
||||
sessionDAO.create(s);
|
||||
|
||||
resp.getWriter().println("<h1>Session creee avec id: " +
|
||||
s.getId() + "</h1>");
|
||||
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
||||
s.getCodePIN() + "</h1>");
|
||||
}
|
||||
else if (action.equals("addQuizz")){
|
||||
String idQuizz = req.getParameter("idQuizz");
|
||||
String sessionID = req.getParameter("sessionID");
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
|
||||
Quizz quizz = quizzDAO.findById(Integer.parseInt(idQuizz));
|
||||
if(quizz==null) resp.getWriter().println("<h1>Ce quizz n'existe pas !</h1>");
|
||||
if(quizz==null) resp.getWriter().println("<h1>Cette session n'existe pas !</h1>");
|
||||
Session session = sessionDAO.findById(Integer.parseInt(sessionID));
|
||||
|
||||
sessionDAO.addQuizz(quizz,session);
|
||||
|
||||
|
||||
resp.getWriter().println("<h1>Quizz"+ idQuizz +" est ajouté à la session " + sessionID + " !</h1>");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
140
src/main/java/servlet/Show.java
Normal file
140
src/main/java/servlet/Show.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import DAO.*;
|
||||
import DTO.UtilisateurDTO;
|
||||
import Mapper.UtilisateurMapper;
|
||||
import metier.*;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
||||
@WebServlet(name = "Show", urlPatterns = {"/Show"})
|
||||
public class Show extends HttpServlet {
|
||||
Utilisateur u;
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||
QuestionDAO questionDAO = new QuestionDAO();
|
||||
|
||||
UtilisateurMapper mapper_u = Mappers.getMapper(UtilisateurMapper.class);
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
response.setContentType("text/html");
|
||||
|
||||
String result = "<!DOCTYPE html>" +
|
||||
"<html>" +
|
||||
"<head>" +
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"" + request.getContextPath() + "/css/style.css\">" +
|
||||
"</head>" +
|
||||
"<body>";
|
||||
|
||||
|
||||
|
||||
//UTILISATEUR
|
||||
List<Utilisateur> listUser = utilisateurDAO.findAll();
|
||||
|
||||
result += "<H2>Utilisateurs :</H2>";
|
||||
result +=
|
||||
"<table class=\"show\">" +
|
||||
"<thead class=\"show\">" +
|
||||
"<tr>" +
|
||||
"<th class=\"Id\">Nom</th><th class=\"show\">Nom</th><th class=\"show\">mail</th><th class=\"show\">Password</th>" +
|
||||
"</tr>" +
|
||||
"</thead>" +
|
||||
"<tbody>";
|
||||
for (Utilisateur u : listUser) {
|
||||
UtilisateurDTO dto = mapper_u.toDTO(u);
|
||||
result +=
|
||||
"<tr>" +
|
||||
"<th class=\"show\">" + dto.getId() + "</th><th class=\"show\">" + dto.getName() + "</th><th class=\"show\">" + dto.getEmail() + "</th><th class=\"show\">" + dto.getPassword() + "</th>"+
|
||||
"</tr>";
|
||||
System.out.println(u.getName()+dto.getEmail());
|
||||
}
|
||||
result +=
|
||||
"</tbody>"+
|
||||
"</table>";
|
||||
|
||||
//QUIZZ
|
||||
List<Quizz> listQuizz = quizzDAO.findAll();
|
||||
|
||||
result += "<H2>Quizz :</H2>";
|
||||
for (Quizz quizz : listQuizz) {
|
||||
quizzDAO.refresh(quizz);
|
||||
result += "<div class=\"quizz\">";
|
||||
result += "quizz n°" + quizz.getId() + "<br/>";
|
||||
result += "<div class=\"tabulation\">";
|
||||
result += "Createur : " + quizz.getCreateur().getEmail() + " (id: " + quizz.getCreateur().getId() + ") <br/>";
|
||||
result += "nb Question : " + quizz.getQuestions().size() +"<br/>";
|
||||
|
||||
|
||||
for (Question question : quizz.getQuestions()) {
|
||||
result += "<div class=\"question\">";
|
||||
result += "Q" + question.getId() + " Ennoncé : "+ question.getEnonce() + "<br/>";
|
||||
|
||||
|
||||
result += "<b>Choix de réponse : </b><br/>";
|
||||
result += "<div class=\"tabulation\">";
|
||||
result += question.getReponse().valHTML();
|
||||
result += "</div>";
|
||||
result += "<b>Reponses corrects :</b><br/>";
|
||||
result += "<div class=\"tabulation\">";
|
||||
for (String reponse : question.getReponse().getReponses()) {
|
||||
result += reponse;
|
||||
}
|
||||
result += "</div></div>";
|
||||
}
|
||||
result += "</div></div>";
|
||||
}
|
||||
|
||||
//SESSION
|
||||
List<Session> listSession = sessionDAO.findAll();
|
||||
result += "<H2>Session : </H2>";
|
||||
result +=
|
||||
"<table class=\"show\">"+
|
||||
"<thead class=\"show\">"+
|
||||
"<tr>"+
|
||||
"<th class=\"show\">ID</th><th class=\"show\">Theme</th><th class=\"show\">Code PIN</th><th class=\"show\">Quizzs</th><th class=\"show\">Participants</th>"+
|
||||
"</tr>"+
|
||||
"</thead>"+
|
||||
"<tbody>";
|
||||
|
||||
for(Session session : listSession){
|
||||
sessionDAO.refresh(session);
|
||||
result+=
|
||||
"<tr>"+
|
||||
"<th class=\"show\">"+session.getId()+"</th>"+"<th class=\"show\">"+session.getTheme()+"</th>"+"<th class=\"show\">"+session.getCodePIN()+"</th>";
|
||||
String quizzsID = "";
|
||||
for(Quizz quizz : session.getQuizzs()){
|
||||
quizzsID += quizz.getId() + " ; ";
|
||||
}
|
||||
String UtilisateurID = "";
|
||||
for(Utilisateur utilisateur : session.getUtilisateurs()){
|
||||
UtilisateurID += utilisateur.getEmail() + " ; ";
|
||||
}
|
||||
result += "<th class=\"show\">"+quizzsID+"</th>"+"<th class=\"show\">"+UtilisateurID+"</th>";
|
||||
result+="</tr>";
|
||||
}
|
||||
|
||||
result +=
|
||||
"</tbody>"+
|
||||
"</table>";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//HTML END
|
||||
result += "</body>\n</html>";
|
||||
|
||||
response.getWriter().write(result);
|
||||
}
|
||||
}
|
||||
50
src/main/java/servlet/UserInfo.java
Normal file
50
src/main/java/servlet/UserInfo.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import DAO.UtilisateurDAO;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import metier.Utilisateur;
|
||||
|
||||
@WebServlet(name = "userinfo", urlPatterns = {"/UserInfo"})
|
||||
public class UserInfo extends HttpServlet {
|
||||
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.getRequestDispatcher("/UserInfo.html").forward(req, resp);
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("text/html");
|
||||
String action = request.getParameter("action");
|
||||
|
||||
if ("addUser".equals(action)) {
|
||||
Utilisateur u = new Utilisateur();
|
||||
u.setName(request.getParameter("name"));
|
||||
u.setEmail(request.getParameter("email"));
|
||||
u.setPassword(request.getParameter("password"));
|
||||
|
||||
|
||||
utilisateurDAO.create(u);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println("<HTML>\n<BODY>\n" +
|
||||
"<H1>Recapitulatif des informations de l'utilisateur</H1>\n" +
|
||||
"<UL>\n" + " <LI>Nom: " + request.getParameter("name") +
|
||||
"\n" + " <LI>Email: " + request.getParameter("email") + "\n" +
|
||||
"</BODY></HTML>");
|
||||
} else if ("addSession".equals(action)) {
|
||||
int sessionId = Integer.parseInt(request.getParameter("sessionId"));
|
||||
int userId = Integer.parseInt(request.getParameter("userId"));
|
||||
utilisateurDAO.addToSession(sessionId, userId);
|
||||
response.getWriter().println("<h1> Reussi d'ajouter utilisateur " +
|
||||
userId + " à la session " + sessionId + "</h1>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
src/main/resources/log4j.properties
Normal file
15
src/main/resources/log4j.properties
Normal file
@@ -0,0 +1,15 @@
|
||||
----------------------------------------------log4j.properties
|
||||
|
||||
### direct log messages to stdout
|
||||
###
|
||||
log4j.rootLogger=INFO, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
# Log everything. Good for troubleshooting
|
||||
log4j.logger.org.hibernate=ERROR
|
||||
|
||||
# Log all JDBC parameters
|
||||
log4j.logger.org.hibernate.type=ERROR
|
||||
@@ -1,92 +0,0 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="https://unpkg.com/swagger-ui-dist/swagger-ui.css">
|
||||
<style>
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
style="position:absolute;width:0;height:0">
|
||||
<defs>
|
||||
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="locked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="close">
|
||||
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||
</symbol>
|
||||
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="expand">
|
||||
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||
</symbol>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
|
||||
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-standalone-preset.js"></script>
|
||||
|
||||
<script>
|
||||
window.onload = function () {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "http://localhost:8080/openapi.json",
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
41
src/main/webapp/Question.html
Normal file
41
src/main/webapp/Question.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<html lang="fr">
|
||||
<body>
|
||||
<h1>Creer une Question</h1>
|
||||
<form action="QuestionInfo" method="POST">
|
||||
<input type="hidden" name="action" value="createSession">
|
||||
Ennoncé de la question : <input type="text" name="question"><br/>
|
||||
Type :
|
||||
<select id="type" name="type">
|
||||
<option value="choix">Choix multiple</option>
|
||||
<option value="courte">Réponse courte</option>
|
||||
</select><br/>
|
||||
<div id="DivChoix">
|
||||
Choix possible (séparez avec des retour à la ligne):<br/>
|
||||
<textarea id="choixPossible" name="choixPossible" rows="5" cols="40"></textarea><br/>
|
||||
</div>
|
||||
Réponse autorisée (séparez avec des retour à la ligne):<br/>
|
||||
<textarea id="reponse" name="reponse" rows="5" cols="40"></textarea><br/>
|
||||
ID Quizz: <input type="number" name="idQuizz"><br/>
|
||||
<input type="submit" value="Creer Session">
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
const select = document.getElementById('type');
|
||||
const contenu1 = document.getElementById('DivChoix');
|
||||
|
||||
select.addEventListener('change', function () {
|
||||
if (this.value === 'choix') {
|
||||
contenu1.style.display = 'block';
|
||||
} else{
|
||||
contenu1.style.display = 'none';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
12
src/main/webapp/Quizz.html
Normal file
12
src/main/webapp/Quizz.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<html lang="en">
|
||||
<body>
|
||||
<form action="QuizzInfo" method="POST">
|
||||
<h1>Creer des quizz</h1>
|
||||
Create from user id : <INPUT type="number" name="id_User" size="20"><BR>
|
||||
Create from user email : <INPUT type="text" name="email_User" size="20"><BR>
|
||||
<INPUT type="submit" value="Creer Quizz"></INPUT>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
28
src/main/webapp/Session.html
Normal file
28
src/main/webapp/Session.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<html lang="en">
|
||||
<body>
|
||||
<h1>Creer une session</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<form action="SessionInfo" method="POST">
|
||||
<input type="hidden" name="action" value="createSession">
|
||||
Theme: <input type="text" name="theme"><br/>
|
||||
CodePin <input type="number" name="codePIN"><br/>
|
||||
<input type="submit" value="createSession">
|
||||
</form>
|
||||
|
||||
<h1>Ajouter un quizz à une session</h1>
|
||||
|
||||
<form action="SessionInfo" method="POST">
|
||||
<input type="hidden" name="action" value="addQuizz">
|
||||
session ID <input type="number" name="sessionID"><br/>
|
||||
ID Quizz <input type="number" name="idQuizz"><br/>
|
||||
<input type="submit" value="addQuizz">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
25
src/main/webapp/UserInfo.html
Normal file
25
src/main/webapp/UserInfo.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>User manager</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Creer l'utilisateur</h1>
|
||||
<FORM Method="POST" Action="UserInfo">
|
||||
<input type="hidden" name="action" value="addUser">
|
||||
Name : <INPUT type="text" size="20" name="name"><BR>
|
||||
Email : <INPUT type="text" size="20" name="email"><BR>
|
||||
Passworld : <INPUT type="text" size="20" name="password"><BR>
|
||||
<INPUT type="submit" value="Send">
|
||||
</FORM>
|
||||
|
||||
<h1>Ajouter utilisateur dans une session</h1>
|
||||
<form action="UserInfo" method="POST">
|
||||
<input type="hidden" name="action" value="addSession">
|
||||
ID Session: <input type="number" name="sessionId"><br>
|
||||
ID Utilisateur: <input type="number" name="userId"><br>
|
||||
<input type="submit" value="Ajouter">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
39
src/main/webapp/css/style.css
Normal file
39
src/main/webapp/css/style.css
Normal file
@@ -0,0 +1,39 @@
|
||||
body{
|
||||
|
||||
}
|
||||
|
||||
table.show{
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
border: 2px solid #C0C0C0;
|
||||
|
||||
}
|
||||
|
||||
thead.show{
|
||||
background-color: #F0F0F0;
|
||||
}
|
||||
|
||||
th.show{
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
border: 1px solid #C0C0C0
|
||||
}
|
||||
|
||||
|
||||
.tabulation{
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.question{
|
||||
border: solid;
|
||||
border-color: #C0C0C0;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.quizz{
|
||||
border: solid;
|
||||
border-color: #909090;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
17
src/main/webapp/index.html
Normal file
17
src/main/webapp/index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Kaflop!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Kaflop!</h1>
|
||||
<a href =http://localhost:8080/UserInfo.html>myform</a>
|
||||
<a href =http://localhost:8080/Session.html>session</a>
|
||||
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
||||
<a href =http://localhost:8080/Question.html>Question</a>
|
||||
|
||||
|
||||
<a href =Show>show</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user