QuestionController, creat et update fonctionent
This commit is contained in:
BIN
data/test.lck
BIN
data/test.lck
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
/*C1*/SET SCHEMA SYSTEM_LOBS
|
||||
INSERT INTO BLOCKS VALUES(0,2147483647,0)
|
||||
COMMIT
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#HSQL Database Engine 2.7.2
|
||||
#Sat Oct 11 11:14:13 CEST 2025
|
||||
modified=no
|
||||
tx_timestamp=153
|
||||
#Sat Oct 11 15:53:59 CEST 2025
|
||||
modified=yes
|
||||
tx_timestamp=1
|
||||
version=2.7.2
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
SET DATABASE UNIQUE NAME HSQLDB999B2B92D0
|
||||
SET DATABASE UNIQUE NAME HSQLDB99D38CBBE0
|
||||
SET DATABASE DEFAULT RESULT MEMORY ROWS 0
|
||||
SET DATABASE EVENT LOG LEVEL 0
|
||||
SET DATABASE TRANSACTION CONTROL LOCKS
|
||||
@@ -29,32 +29,12 @@ SET FILES NIO TRUE
|
||||
SET FILES NIO SIZE 256
|
||||
SET FILES LOG TRUE
|
||||
SET FILES LOG SIZE 50
|
||||
SET FILES CHECK 153
|
||||
SET DATABASE COLLATION "SQL_TEXT" PAD SPACE
|
||||
SET FILES CHECK 1
|
||||
SET DATABASE COLLATION SQL_TEXT PAD SPACE
|
||||
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
|
||||
ALTER USER SA SET LOCAL TRUE
|
||||
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
|
||||
CREATE SEQUENCE PUBLIC.QUIZZ_SEQ AS INTEGER START WITH 1 INCREMENT BY 50
|
||||
CREATE SEQUENCE PUBLIC.REPONSE_SEQ AS INTEGER START WITH 1 INCREMENT BY 50
|
||||
CREATE MEMORY TABLE PUBLIC.CHOIX(CHOIX_ID INTEGER NOT NULL PRIMARY KEY,CHOIX VARCHAR(255) ARRAY)
|
||||
CREATE MEMORY TABLE PUBLIC.QUESTION(BONNE_REPONSE INTEGER,ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,ID_QUIZZ INTEGER,QUESTION VARCHAR(255),UNIQUE(BONNE_REPONSE))
|
||||
ALTER TABLE PUBLIC.QUESTION ALTER COLUMN ID RESTART WITH 4
|
||||
CREATE MEMORY TABLE PUBLIC.QUIZZ(ID INTEGER NOT NULL PRIMARY KEY,ID_UTILISATEUR INTEGER,SESSION_ID INTEGER)
|
||||
CREATE MEMORY TABLE PUBLIC.REPONSE(ID INTEGER NOT NULL PRIMARY KEY,QUESTION_ID INTEGER,TYPE_REPONSE VARCHAR(31) NOT NULL,REPONSES VARCHAR(255) ARRAY,UNIQUE(QUESTION_ID),CONSTRAINT FKGDR6SI626NQIXG8QYFX6S0PJL FOREIGN KEY(QUESTION_ID) REFERENCES PUBLIC.QUESTION(ID))
|
||||
CREATE MEMORY TABLE PUBLIC.REPONSECOURTE(RC_ID INTEGER NOT NULL PRIMARY KEY,VALUE VARCHAR(255),CONSTRAINT FKOCS5T60OV4KWOOM69761AY7QD FOREIGN KEY(RC_ID) REFERENCES PUBLIC.REPONSE(ID))
|
||||
CREATE MEMORY TABLE PUBLIC.SESSION(CODEPIN INTEGER,ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,THEME VARCHAR(255),UNIQUE(CODEPIN))
|
||||
ALTER TABLE PUBLIC.SESSION ALTER COLUMN ID RESTART WITH 2
|
||||
CREATE MEMORY TABLE PUBLIC.UTILISATEUR(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,EMAIL VARCHAR(255),NAME VARCHAR(255),PASSWORD VARCHAR(255),UNIQUE(EMAIL))
|
||||
ALTER TABLE PUBLIC.UTILISATEUR ALTER COLUMN ID RESTART WITH 2
|
||||
CREATE MEMORY TABLE PUBLIC.UTILISATEUR_SESSION(SESSION_ID INTEGER NOT NULL,UTILISATEUR_ID INTEGER NOT NULL,CONSTRAINT FK2RIP0K622CEQL0W3UFF4Y6W9X FOREIGN KEY(SESSION_ID) REFERENCES PUBLIC.SESSION(ID),CONSTRAINT FK4F5DGIWF12KD9VRHSC6S4X2PK FOREIGN KEY(UTILISATEUR_ID) REFERENCES PUBLIC.UTILISATEUR(ID))
|
||||
ALTER TABLE PUBLIC.CHOIX ADD CONSTRAINT FK15F4FGMTOCO1TG4RRA1VUALR5 FOREIGN KEY(CHOIX_ID) REFERENCES PUBLIC.REPONSE(ID)
|
||||
ALTER TABLE PUBLIC.QUESTION ADD CONSTRAINT FKG1JHCNX0GW81N3IOGGW38LDED FOREIGN KEY(ID_QUIZZ) REFERENCES PUBLIC.QUIZZ(ID)
|
||||
ALTER TABLE PUBLIC.QUESTION ADD CONSTRAINT FKHT8PE2O5V6SFF88MR3PBH40F6 FOREIGN KEY(BONNE_REPONSE) REFERENCES PUBLIC.REPONSE(ID)
|
||||
ALTER TABLE PUBLIC.QUIZZ ADD CONSTRAINT FK6EAR00W55TL7EU04GX1UR3K20 FOREIGN KEY(SESSION_ID) REFERENCES PUBLIC.SESSION(ID)
|
||||
ALTER TABLE PUBLIC.QUIZZ ADD CONSTRAINT FKLSVN0PVGA68UMMFYIVIDLWGGH FOREIGN KEY(ID_UTILISATEUR) REFERENCES PUBLIC.UTILISATEUR(ID)
|
||||
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1
|
||||
ALTER SEQUENCE PUBLIC.QUIZZ_SEQ RESTART WITH 101
|
||||
ALTER SEQUENCE PUBLIC.REPONSE_SEQ RESTART WITH 151
|
||||
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
|
||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC
|
||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC
|
||||
@@ -62,20 +42,3 @@ GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC
|
||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
|
||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
|
||||
GRANT DBA TO SA
|
||||
SET SCHEMA SYSTEM_LOBS
|
||||
INSERT INTO BLOCKS VALUES(0,2147483647,0)
|
||||
SET SCHEMA PUBLIC
|
||||
INSERT INTO CHOIX VALUES(1, ARRAY['a\u000d','a\u000d','a\u000d','a'])
|
||||
INSERT INTO CHOIX VALUES(2, ARRAY['Kesterman\u000d','Kesteman\u000d','Kasterman\u000d','Kasteman'])
|
||||
INSERT INTO QUESTION VALUES(1,1,1,'a')
|
||||
INSERT INTO QUESTION VALUES(2,2,1,'Quel est le nom de famille d''Amael')
|
||||
INSERT INTO QUESTION VALUES(52,3,1,'Quel est le nom de famille d''Amael (mode difficile)')
|
||||
INSERT INTO QUIZZ VALUES(1,1,1)
|
||||
INSERT INTO QUIZZ VALUES(2,1,NULL)
|
||||
INSERT INTO REPONSE VALUES(1,1,'Choix', ARRAY['aaaa'])
|
||||
INSERT INTO REPONSE VALUES(2,2,'Choix', ARRAY['Kesteman'])
|
||||
INSERT INTO REPONSE VALUES(52,3,'ReponseCourte', ARRAY['Kesteman'])
|
||||
INSERT INTO REPONSECOURTE VALUES(52,NULL)
|
||||
INSERT INTO SESSION VALUES(1234,1,'ThemA')
|
||||
INSERT INTO UTILISATEUR VALUES(1,'a@a','a',NULL)
|
||||
INSERT INTO UTILISATEUR_SESSION VALUES(1,1)
|
||||
|
||||
21
src/main/java/sample/data/jpa/SecurityConfig.java
Normal file
21
src/main/java/sample/data/jpa/SecurityConfig.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package sample.data.jpa;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.anyRequest().permitAll()
|
||||
);
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class Question implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
private String question;
|
||||
private String enonce;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name ="bonne_reponse", referencedColumnName = "id")
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@@ -18,37 +22,49 @@ import sample.data.jpa.service.QuestionDao;
|
||||
@Controller
|
||||
@RequestMapping("/question")
|
||||
public class QuestionController {
|
||||
@Autowired
|
||||
|
||||
@Autowired
|
||||
private QuestionDao qDao;
|
||||
|
||||
|
||||
@RequestMapping("/create")
|
||||
/*
|
||||
* Utiliser un Json pour mettre : String enonce
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@ResponseBody
|
||||
public String create(String email, String name) {
|
||||
public String create(@RequestBody Map<String, String> body) {
|
||||
String qId = "";
|
||||
Question q = new Question();
|
||||
try {
|
||||
Question question = new Question();
|
||||
qDao.save(question);
|
||||
qId = String.valueOf(question.getId());
|
||||
if(body.containsKey("enonce")){
|
||||
q.setEnonce(body.get("enonce"));
|
||||
}
|
||||
else q.setEnonce("");
|
||||
qDao.save(q);
|
||||
qId = String.valueOf(q.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error creating the question : " + ex.toString();
|
||||
}
|
||||
return "Question succesfully created with id = " + qId;
|
||||
return "Question \""+q.getEnonce()+"\" succesfully created with id = " + qId;
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
/*
|
||||
* Utiliser un Json pour mettre : String enonce
|
||||
* l'id se met dans l'url
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@ResponseBody
|
||||
public String updateQuestion(int id, String newQ) {
|
||||
public String updateQuestion(@PathVariable("id") int id, @RequestBody Map<String, String> body) {
|
||||
Question q;
|
||||
try {
|
||||
Question q = qDao.findById(id).get();
|
||||
q.setQuestion(newQ);
|
||||
q = qDao.findById(id).get();
|
||||
q.setEnonce(body.get("enonce"));
|
||||
qDao.save(q);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error updating the question: " + ex.toString();
|
||||
}
|
||||
return "Question succesfully updated!";
|
||||
return "Question "+id+" succesfully updated! : " + q.getEnonce();
|
||||
}
|
||||
|
||||
@RequestMapping("/getReponse")
|
||||
|
||||
Binary file not shown.
BIN
target/classes/sample/data/jpa/SecurityConfig.class
Normal file
BIN
target/classes/sample/data/jpa/SecurityConfig.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user