From 24e80f96f97ec9507d0771f82cab10e93cb2394b Mon Sep 17 00:00:00 2001 From: "maxime.rocher" Date: Tue, 1 Apr 2025 21:12:47 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A7a=20marche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF-WEBAPI/.gitattributes => .gitattributes | 0 WF-WEBAPI/.gitignore => .gitignore | 0 .idea/encodings.xml | 3 +- .idea/misc.xml | 2 +- .idea/modules.xml | 8 - .../wrapper/maven-wrapper.properties | 0 WF-WEBAPI/Dockerfile => Dockerfile | 0 .../wfwebapi/config/SecurityConfig.java | 33 -- .../src/main/resources/application.properties | 12 - WF-WEBAPI/src/main/resources/init.sql | 338 ------------------ WF-WEBAPI/drone.yaml => drone.yaml | 0 WF-WEBAPI/mvnw => mvnw | 0 WF-WEBAPI/mvnw.cmd => mvnw.cmd | 0 WF-WEBAPI/pom.xml => pom.xml | 33 +- .../example/wfwebapi/WfWebapiApplication.java | 0 .../assembler/QuoteModelAssembler.java | 0 .../assembler/UserModelAssembler.java | 0 .../wfwebapi/config/SecurityConfig.java | 22 ++ .../wfwebapi/controller/AdminController.java | 0 .../wfwebapi/controller/AuthController.java | 0 .../controller/CaracterController.java | 0 .../controller/CommentaryController.java | 0 .../controller/DailyQuoteController.java | 0 .../controller/FavoriteController.java | 0 .../wfwebapi/controller/ImageController.java | 0 .../controller/QuestionController.java | 0 .../wfwebapi/controller/QuizController.java | 0 .../wfwebapi/controller/QuoteController.java | 0 .../controller/RecordQuizController.java | 0 .../wfwebapi/controller/SourceController.java | 0 .../wfwebapi/controller/UserController.java | 0 .../exception/ResourceNotFoundException.java | 0 .../exception/UnauthorizedException.java | 0 .../com/example/wfwebapi/model/Admin.java | 0 .../com/example/wfwebapi/model/Caracter.java | 0 .../example/wfwebapi/model/Commentary.java | 0 .../example/wfwebapi/model/DailyQuote.java | 0 .../com/example/wfwebapi/model/Favorite.java | 0 .../example/wfwebapi/model/FavoriteId.java | 0 .../com/example/wfwebapi/model/Image.java | 0 .../com/example/wfwebapi/model/Question.java | 0 .../java/com/example/wfwebapi/model/Quiz.java | 0 .../example/wfwebapi/model/QuizQuestion.java | 0 .../wfwebapi/model/QuizQuestionId.java | 0 .../com/example/wfwebapi/model/Quote.java | 0 .../example/wfwebapi/model/RecordQuiz.java | 0 .../example/wfwebapi/model/RecordQuizId.java | 0 .../com/example/wfwebapi/model/Source.java | 0 .../java/com/example/wfwebapi/model/User.java | 0 .../wfwebapi/repository/AdminRepository.java | 0 .../repository/CaracterRepository.java | 0 .../repository/CommentaryRepository.java | 0 .../repository/DailyQuoteRepository.java | 0 .../repository/FavoriteRepository.java | 0 .../wfwebapi/repository/ImageRepository.java | 0 .../repository/QuestionRepository.java | 0 .../repository/QuizQuestionRepository.java | 0 .../wfwebapi/repository/QuizRepository.java | 7 + .../wfwebapi/repository/QuoteRepository.java | 0 .../repository/RecordQuizRepository.java | 0 .../wfwebapi/repository/SourceRepository.java | 0 .../wfwebapi/repository/UserRepository.java | 0 .../security/JwtAuthenticationFilter.java | 0 .../wfwebapi/security/JwtTokenProvider.java | 0 src/main/resources/application.properties | 25 ++ src/main/resources/init.sql | 144 ++++++++ .../wfwebapi/WfWebapiApplicationTests.java | 0 67 files changed, 217 insertions(+), 410 deletions(-) rename WF-WEBAPI/.gitattributes => .gitattributes (100%) rename WF-WEBAPI/.gitignore => .gitignore (100%) delete mode 100644 .idea/modules.xml rename {WF-WEBAPI/.mvn => .mvn}/wrapper/maven-wrapper.properties (100%) rename WF-WEBAPI/Dockerfile => Dockerfile (100%) delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/config/SecurityConfig.java delete mode 100644 WF-WEBAPI/src/main/resources/application.properties delete mode 100644 WF-WEBAPI/src/main/resources/init.sql rename WF-WEBAPI/drone.yaml => drone.yaml (100%) rename WF-WEBAPI/mvnw => mvnw (100%) rename WF-WEBAPI/mvnw.cmd => mvnw.cmd (100%) rename WF-WEBAPI/pom.xml => pom.xml (77%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/WfWebapiApplication.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/assembler/QuoteModelAssembler.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/assembler/UserModelAssembler.java (100%) create mode 100644 src/main/java/com/example/wfwebapi/config/SecurityConfig.java rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/AdminController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/AuthController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/CaracterController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/CommentaryController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/DailyQuoteController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/FavoriteController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/ImageController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/QuestionController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/QuizController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/QuoteController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/RecordQuizController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/SourceController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/controller/UserController.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/exception/ResourceNotFoundException.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/exception/UnauthorizedException.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Admin.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Caracter.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Commentary.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/DailyQuote.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Favorite.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/FavoriteId.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Image.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Question.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Quiz.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/QuizQuestion.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/QuizQuestionId.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Quote.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/RecordQuiz.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/RecordQuizId.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/Source.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/model/User.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/AdminRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/CaracterRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/CommentaryRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/DailyQuoteRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/FavoriteRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/ImageRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/QuestionRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/QuizQuestionRepository.java (100%) create mode 100644 src/main/java/com/example/wfwebapi/repository/QuizRepository.java rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/QuoteRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/RecordQuizRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/SourceRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/repository/UserRepository.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/security/JwtAuthenticationFilter.java (100%) rename {WF-WEBAPI/src => src}/main/java/com/example/wfwebapi/security/JwtTokenProvider.java (100%) create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/init.sql rename {WF-WEBAPI/src => src}/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java (100%) diff --git a/WF-WEBAPI/.gitattributes b/.gitattributes similarity index 100% rename from WF-WEBAPI/.gitattributes rename to .gitattributes diff --git a/WF-WEBAPI/.gitignore b/.gitignore similarity index 100% rename from WF-WEBAPI/.gitignore rename to .gitignore diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 3c2154d..aa00ffa 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,7 @@ - + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d3cd869..e122dea 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 73cbac1..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/WF-WEBAPI/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from WF-WEBAPI/.mvn/wrapper/maven-wrapper.properties rename to .mvn/wrapper/maven-wrapper.properties diff --git a/WF-WEBAPI/Dockerfile b/Dockerfile similarity index 100% rename from WF-WEBAPI/Dockerfile rename to Dockerfile diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/config/SecurityConfig.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/config/SecurityConfig.java deleted file mode 100644 index c9c5108..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/config/SecurityConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.wfwebapi.config; - -import com.example.wfwebapi.security.JwtAuthenticationFilter; -import com.example.wfwebapi.security.JwtTokenProvider; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.Customizer; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.web.SecurityFilterChain; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; - -@Configuration -public class SecurityConfig { - - private final JwtTokenProvider tokenProvider; - - public SecurityConfig(JwtTokenProvider tokenProvider) { - this.tokenProvider = tokenProvider; - } - - @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http.csrf(csrf -> csrf.disable()) - .authorizeHttpRequests(authz -> authz - .requestMatchers("/api/v1/auth/**").permitAll() // par exemple, pour la connexion - .anyRequest().authenticated() - ) - .addFilterBefore(new JwtAuthenticationFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class) - .httpBasic(Customizer.withDefaults()); - - return http.build(); - } -} diff --git a/WF-WEBAPI/src/main/resources/application.properties b/WF-WEBAPI/src/main/resources/application.properties deleted file mode 100644 index 0a93e37..0000000 --- a/WF-WEBAPI/src/main/resources/application.properties +++ /dev/null @@ -1,12 +0,0 @@ -spring.application.name=WF-WEBAPI - -# Utilisation de H2 avec le script d'initialisation -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password= -spring.sql.init.mode=always -spring.sql.init.schema-locations=classpath:init.sql -spring.jpa.hibernate.ddl-auto=none -spring.h2.console.enabled=true -server.port=8080 diff --git a/WF-WEBAPI/src/main/resources/init.sql b/WF-WEBAPI/src/main/resources/init.sql deleted file mode 100644 index 843094b..0000000 --- a/WF-WEBAPI/src/main/resources/init.sql +++ /dev/null @@ -1,338 +0,0 @@ --- Suppression des tables -DROP TABLE IF EXISTS Commentary; -DROP TABLE IF EXISTS Favorite; -DROP TABLE IF EXISTS DailyQuote; -DROP TABLE IF EXISTS Quote; -DROP TABLE IF EXISTS Caracter; -DROP TABLE IF EXISTS Source; -DROP TABLE IF EXISTS Record_quiz; -DROP TABLE IF EXISTS Quiz_Question; -DROP TABLE IF EXISTS Quiz; -DROP TABLE IF EXISTS Question; -DROP TABLE IF EXISTS Admin; -DROP TABLE IF EXISTS Users; -DROP TABLE IF EXISTS Image; - --- Création des tables -------------------------------------------------------------------------- - -CREATE TABLE Image( - id_img NUMERIC PRIMARY KEY, - imgPath varchar(300) NOT NULL UNIQUE -); - -------------------------------------------------------------------------- - -CREATE TABLE Users( - id_user SERIAL PRIMARY KEY, - username varchar(50) NOT NULL, - email varchar(50) NOT NULL, - password varchar(100) NOT NULL, - img NUMERIC NOT NULL, - creation date NOT NULL, - CONSTRAINT unique_col UNIQUE (email), - CONSTRAINT fk_img FOREIGN KEY(img) REFERENCES Image(id_img) -); - -Create OR REPLACE Function IfUserIsAdmin() RETURNS trigger AS $$ -DECLARE - -BEGIN - Delete From Admin - where users = OLD.id_user; - - RETURN OLD; -END; -$$ LANGUAGE plpgsql ; - - -Create Trigger IfUserIsAdmin BEFORE DELETE on Users -FOR EACH ROW -EXECUTE FUNCTION IfUserIsAdmin(); - - -Create OR REPLACE Function DeleteUserFavorite() RETURNS trigger AS $$ -DECLARE - -BEGIN - Delete From Favorite - where users = OLD.id_user; - - RETURN OLD; -END; -$$ LANGUAGE plpgsql ; - - -Create Trigger DeleteUserFavorite BEFORE DELETE on Users -FOR EACH ROW -EXECUTE FUNCTION DeleteUserFavorite(); - -Create OR REPLACE Function DeleteUserCommentary() RETURNS trigger AS $$ -DECLARE - -BEGIN - Delete From Commentary - where users = OLD.id_user; - - RETURN OLD; -END; -$$ LANGUAGE plpgsql ; - - -Create Trigger DeleteUserCommentary BEFORE DELETE on Users -FOR EACH ROW -EXECUTE FUNCTION DeleteUserCommentary(); -------------------------------------------------------------------------- - -CREATE TABLE Admin( - users SERIAL PRIMARY KEY, - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) -); - -------------------------------------------------------------------------- - -CREATE TABLE Question( - id_question SERIAL PRIMARY KEY, - texte text NOT NULL UNIQUE, - answerA varchar(30) NOT NULL, - answerB varchar(30) NOT NULL, - answerC varchar(30) NOT NULL, - answerD varchar(30) NOT NULL, - cAnswer varchar(30) NOT NULL, - CONSTRAINT check_cAnswer CHECK (cAnswer = answerA OR cAnswer = answerB OR cAnswer = answerC OR cAnswer = answerD) -); - -------------------------------------------------------------------------- - -CREATE TABLE Quiz( - id_quiz SERIAL PRIMARY KEY, - title varchar(40) NOT NULL, - img NUMERIC NOT NULL, - nb_quest numeric Default 0, - CONSTRAINT fk_img FOREIGN KEY(img) REFERENCES Image(id_img) -); - -Create OR REPLACE Function DeleteQuiz() RETURNS trigger AS $$ -DECLARE - -BEGIN - Delete From Quiz_Question - where quiz=OLD.id_quiz; - - Delete From Record_quiz - where quiz=OLD.id_quiz; -END; -$$ LANGUAGE plpgsql ; - -Create Trigger DeleteQuiz BEFORE DELETE on Quiz -FOR EACH ROW -EXECUTE FUNCTION DeleteQuiz(); -------------------------------------------------------------------------- - -CREATE TABLE Quiz_Question( - quiz SERIAL NOT NULL, - question SERIAL NOT NULL, - PRIMARY KEY (quiz, question), - CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz), - CONSTRAINT fk_question FOREIGN KEY(question) REFERENCES Question(id_question) -); - -Create OR REPLACE Function NombreQuestionQuiz() RETURNS trigger AS $$ -DECLARE - nb numeric; -BEGIN - - IF TG_OP='DELETE' Then - SELECT count(quiz) INTO nb - FROM Quiz_Question - WHERE quiz = OLD.quiz; - Else - SELECT count(quiz) INTO nb - FROM Quiz_Question - WHERE quiz = NEW.quiz; - End IF; - - - Update Quiz - set nb_quest=nb - where id_quiz=NEW.quiz; - - Return OLD; -END; -$$ LANGUAGE plpgsql ; - -Create Trigger NombreQuestionQuiz AFTER INSERT or UPDATE or DELETE on Quiz_Question -FOR EACH ROW -EXECUTE FUNCTION NombreQuestionQuiz(); - -------------------------------------------------------------------------- - -CREATE TABLE Record_quiz( - users SERIAL NOT NULL, - quiz SERIAL NOT NULL, - nbPoint numeric DEFAULT 0, - timeQ numeric DEFAULT 0, - PRIMARY KEY (users, quiz), - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user), - CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz), - CONSTRAINT err_nbPoint CHECK(nbPoint >= 0), - CONSTRAINT err_timeQ CHECK(timeQ >= 0) -); - -------------------------------------------------------------------------- - -CREATE TABLE Source( - id_source SERIAL PRIMARY KEY, - title varchar(100) NOT NULL, - dateS numeric(4) NOT NULL -); - -------------------------------------------------------------------------- - -CREATE TABLE Caracter( - id_caracter SERIAL PRIMARY KEY, - caracter varchar(100) NOT NULL, - id_img NUMERIC NOT NULL -); - -------------------------------------------------------------------------- - -CREATE TABLE Quote( - id_quote SERIAL PRIMARY KEY, - content text NOT NULL, - likes numeric DEFAULT '0', - langue char(2) NOT NULL, - isValide boolean NOT NULL DEFAULT 'false', - reason varchar(100) NOT NULL, - id_caracter SERIAL NOT NULL, - id_source SERIAL NOT NULL, - id_user_verif SERIAL NOT NULL, - CONSTRAINT fk_caracter FOREIGN KEY(id_caracter) REFERENCES Caracter(id_caracter), - CONSTRAINT fk_source FOREIGN KEY(id_source) REFERENCES Source(id_source), - CONSTRAINT fk_userverif FOREIGN KEY(id_user_verif) REFERENCES Users(id_user), - CONSTRAINT err_nbLike CHECK (likes >= 0), - CONSTRAINT err_language CHECK (langue = 'fr' OR langue = 'en') -); - -Create OR REPLACE Function DeleteQuoteBEFORE() RETURNS trigger AS $$ -DECLARE - -BEGIN - Delete From Favorite - where quote=OLD.id_quote; - - - Delete From Commentary - where quote=OLD.id_quote; - - - If OLD.id_quote in (Select citation_id From DailyQuote) Then - Update DailyQuote - set citation_id = (Select id_quote - From Quote - Where id_quote!=OLD.id_quote - ORDER BY RAND() - LIMIT 1) - Where citation_id=OLD.id_quote; - END IF; - - Return OLD; -END; -$$ LANGUAGE plpgsql ; - -Create Trigger DeleteQuoteBEFORE BEFORE DELETE on Quote -FOR EACH ROW -EXECUTE FUNCTION DeleteQuoteBEFORE(); - - -Create OR REPLACE Function DeleteQuoteAFTER() RETURNS trigger AS $$ -DECLARE - nb numeric; -BEGIN - Select count(id_caracter) into nb - from Quote - where id_caracter=OLD.id_caracter; - - IF nb <= 1 Then - Delete from Caracter - where id_caracter=OLD.id_caracter; - END IF; - - - Select count(id_source) into nb - from Quote - where id_source=OLD.id_source; - - IF nb <= 1 Then - Delete from Source - where id_source=OLD.id_source; - END IF; - - Return OLD; -END; -$$ LANGUAGE plpgsql ; - -Create Trigger DeleteQuoteAFTER AFTER DELETE on Quote -FOR EACH ROW -EXECUTE FUNCTION DeleteQuoteAFTER(); - -------------------------------------------------------------------------- - -CREATE TABLE DailyQuote( - citation_id INT PRIMARY KEY, - FOREIGN KEY (citation_id) REFERENCES Quote(id_quote) ON DELETE CASCADE -); - -Create OR REPLACE Function UniqueDailyQuote() RETURNS trigger AS $$ -DECLARE - nb numeric; -BEGIN - Select count(*) into nb - from DailyQuote; - - IF nb = 0 Then - INSERT INTO DailyQuote (citation_id) - VALUES( (Select id_quote - From Quote - Where id_quote!=OLD.id_quote - ORDER BY RAND() - LIMIT 1 ) ); - - ELSIF nb>1 then - - DELETE From DailyQuote - where citation_id!=NEW.citation_id; - END IF; - RETURN OLD; -END; -$$ LANGUAGE plpgsql ; - -Create Trigger UniqueDailyQuote AFTER INSERT or DELETE on DailyQuote -FOR EACH ROW -EXECUTE FUNCTION UniqueDailyQuote(); - -------------------------------------------------------------------------- - - -CREATE TABLE Favorite( - users SERIAL NOT NULL, - quote SERIAL NOT NULL, - PRIMARY KEY (users, quote), - CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote), - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) -); - -------------------------------------------------------------------------- - -CREATE TABLE Commentary( - id_comment SERIAL PRIMARY KEY, - quote SERIAL NOT NULL, - users SERIAL NOT NULL, - dateC date NOT NULL, - comment text NOT NULL, - CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote), - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) -); - -------------------------------------------------------------------------- - diff --git a/WF-WEBAPI/drone.yaml b/drone.yaml similarity index 100% rename from WF-WEBAPI/drone.yaml rename to drone.yaml diff --git a/WF-WEBAPI/mvnw b/mvnw similarity index 100% rename from WF-WEBAPI/mvnw rename to mvnw diff --git a/WF-WEBAPI/mvnw.cmd b/mvnw.cmd similarity index 100% rename from WF-WEBAPI/mvnw.cmd rename to mvnw.cmd diff --git a/WF-WEBAPI/pom.xml b/pom.xml similarity index 77% rename from WF-WEBAPI/pom.xml rename to pom.xml index cc4f084..d1cece5 100644 --- a/WF-WEBAPI/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -13,20 +14,9 @@ 0.0.1-SNAPSHOT WF-WEBAPI WF-WEBAPI - - - - - - - - - - - - - + UTF-8 + 6969 21 @@ -73,16 +63,25 @@ 0.11.5 runtime - - + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + UTF-8 + + @ + + false + + org.springframework.boot spring-boot-maven-plugin - diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/WfWebapiApplication.java b/src/main/java/com/example/wfwebapi/WfWebapiApplication.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/WfWebapiApplication.java rename to src/main/java/com/example/wfwebapi/WfWebapiApplication.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/assembler/QuoteModelAssembler.java b/src/main/java/com/example/wfwebapi/assembler/QuoteModelAssembler.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/assembler/QuoteModelAssembler.java rename to src/main/java/com/example/wfwebapi/assembler/QuoteModelAssembler.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/assembler/UserModelAssembler.java b/src/main/java/com/example/wfwebapi/assembler/UserModelAssembler.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/assembler/UserModelAssembler.java rename to src/main/java/com/example/wfwebapi/assembler/UserModelAssembler.java diff --git a/src/main/java/com/example/wfwebapi/config/SecurityConfig.java b/src/main/java/com/example/wfwebapi/config/SecurityConfig.java new file mode 100644 index 0000000..bcb4f0d --- /dev/null +++ b/src/main/java/com/example/wfwebapi/config/SecurityConfig.java @@ -0,0 +1,22 @@ +package com.example.wfwebapi.config; + +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 + // Désactive CSRF + .csrf(csrf -> csrf.disable()) + // Désactive la protection des frames (utile pour la console H2) + .headers(headers -> headers.frameOptions().disable()) + // Autorise toutes les requêtes sans authentification + .authorizeHttpRequests(authorize -> authorize.anyRequest().permitAll()); + return http.build(); + } +} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/AdminController.java b/src/main/java/com/example/wfwebapi/controller/AdminController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/AdminController.java rename to src/main/java/com/example/wfwebapi/controller/AdminController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/AuthController.java b/src/main/java/com/example/wfwebapi/controller/AuthController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/AuthController.java rename to src/main/java/com/example/wfwebapi/controller/AuthController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/CaracterController.java b/src/main/java/com/example/wfwebapi/controller/CaracterController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/CaracterController.java rename to src/main/java/com/example/wfwebapi/controller/CaracterController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/CommentaryController.java b/src/main/java/com/example/wfwebapi/controller/CommentaryController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/CommentaryController.java rename to src/main/java/com/example/wfwebapi/controller/CommentaryController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/DailyQuoteController.java b/src/main/java/com/example/wfwebapi/controller/DailyQuoteController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/DailyQuoteController.java rename to src/main/java/com/example/wfwebapi/controller/DailyQuoteController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/FavoriteController.java b/src/main/java/com/example/wfwebapi/controller/FavoriteController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/FavoriteController.java rename to src/main/java/com/example/wfwebapi/controller/FavoriteController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/ImageController.java b/src/main/java/com/example/wfwebapi/controller/ImageController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/ImageController.java rename to src/main/java/com/example/wfwebapi/controller/ImageController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/QuestionController.java b/src/main/java/com/example/wfwebapi/controller/QuestionController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/QuestionController.java rename to src/main/java/com/example/wfwebapi/controller/QuestionController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/QuizController.java b/src/main/java/com/example/wfwebapi/controller/QuizController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/QuizController.java rename to src/main/java/com/example/wfwebapi/controller/QuizController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/QuoteController.java b/src/main/java/com/example/wfwebapi/controller/QuoteController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/QuoteController.java rename to src/main/java/com/example/wfwebapi/controller/QuoteController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/RecordQuizController.java b/src/main/java/com/example/wfwebapi/controller/RecordQuizController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/RecordQuizController.java rename to src/main/java/com/example/wfwebapi/controller/RecordQuizController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/SourceController.java b/src/main/java/com/example/wfwebapi/controller/SourceController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/SourceController.java rename to src/main/java/com/example/wfwebapi/controller/SourceController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/UserController.java b/src/main/java/com/example/wfwebapi/controller/UserController.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/controller/UserController.java rename to src/main/java/com/example/wfwebapi/controller/UserController.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/exception/ResourceNotFoundException.java b/src/main/java/com/example/wfwebapi/exception/ResourceNotFoundException.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/exception/ResourceNotFoundException.java rename to src/main/java/com/example/wfwebapi/exception/ResourceNotFoundException.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/exception/UnauthorizedException.java b/src/main/java/com/example/wfwebapi/exception/UnauthorizedException.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/exception/UnauthorizedException.java rename to src/main/java/com/example/wfwebapi/exception/UnauthorizedException.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Admin.java b/src/main/java/com/example/wfwebapi/model/Admin.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Admin.java rename to src/main/java/com/example/wfwebapi/model/Admin.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Caracter.java b/src/main/java/com/example/wfwebapi/model/Caracter.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Caracter.java rename to src/main/java/com/example/wfwebapi/model/Caracter.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Commentary.java b/src/main/java/com/example/wfwebapi/model/Commentary.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Commentary.java rename to src/main/java/com/example/wfwebapi/model/Commentary.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/DailyQuote.java b/src/main/java/com/example/wfwebapi/model/DailyQuote.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/DailyQuote.java rename to src/main/java/com/example/wfwebapi/model/DailyQuote.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Favorite.java b/src/main/java/com/example/wfwebapi/model/Favorite.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Favorite.java rename to src/main/java/com/example/wfwebapi/model/Favorite.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/FavoriteId.java b/src/main/java/com/example/wfwebapi/model/FavoriteId.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/FavoriteId.java rename to src/main/java/com/example/wfwebapi/model/FavoriteId.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Image.java b/src/main/java/com/example/wfwebapi/model/Image.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Image.java rename to src/main/java/com/example/wfwebapi/model/Image.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Question.java b/src/main/java/com/example/wfwebapi/model/Question.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Question.java rename to src/main/java/com/example/wfwebapi/model/Question.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quiz.java b/src/main/java/com/example/wfwebapi/model/Quiz.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quiz.java rename to src/main/java/com/example/wfwebapi/model/Quiz.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestion.java b/src/main/java/com/example/wfwebapi/model/QuizQuestion.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestion.java rename to src/main/java/com/example/wfwebapi/model/QuizQuestion.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java b/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java rename to src/main/java/com/example/wfwebapi/model/QuizQuestionId.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quote.java b/src/main/java/com/example/wfwebapi/model/Quote.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quote.java rename to src/main/java/com/example/wfwebapi/model/Quote.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuiz.java b/src/main/java/com/example/wfwebapi/model/RecordQuiz.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuiz.java rename to src/main/java/com/example/wfwebapi/model/RecordQuiz.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuizId.java b/src/main/java/com/example/wfwebapi/model/RecordQuizId.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuizId.java rename to src/main/java/com/example/wfwebapi/model/RecordQuizId.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Source.java b/src/main/java/com/example/wfwebapi/model/Source.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Source.java rename to src/main/java/com/example/wfwebapi/model/Source.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/User.java b/src/main/java/com/example/wfwebapi/model/User.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/model/User.java rename to src/main/java/com/example/wfwebapi/model/User.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/AdminRepository.java b/src/main/java/com/example/wfwebapi/repository/AdminRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/AdminRepository.java rename to src/main/java/com/example/wfwebapi/repository/AdminRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/CaracterRepository.java b/src/main/java/com/example/wfwebapi/repository/CaracterRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/CaracterRepository.java rename to src/main/java/com/example/wfwebapi/repository/CaracterRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/CommentaryRepository.java b/src/main/java/com/example/wfwebapi/repository/CommentaryRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/CommentaryRepository.java rename to src/main/java/com/example/wfwebapi/repository/CommentaryRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/DailyQuoteRepository.java b/src/main/java/com/example/wfwebapi/repository/DailyQuoteRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/DailyQuoteRepository.java rename to src/main/java/com/example/wfwebapi/repository/DailyQuoteRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/FavoriteRepository.java b/src/main/java/com/example/wfwebapi/repository/FavoriteRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/FavoriteRepository.java rename to src/main/java/com/example/wfwebapi/repository/FavoriteRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/ImageRepository.java b/src/main/java/com/example/wfwebapi/repository/ImageRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/ImageRepository.java rename to src/main/java/com/example/wfwebapi/repository/ImageRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/QuestionRepository.java b/src/main/java/com/example/wfwebapi/repository/QuestionRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/QuestionRepository.java rename to src/main/java/com/example/wfwebapi/repository/QuestionRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/QuizQuestionRepository.java b/src/main/java/com/example/wfwebapi/repository/QuizQuestionRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/QuizQuestionRepository.java rename to src/main/java/com/example/wfwebapi/repository/QuizQuestionRepository.java diff --git a/src/main/java/com/example/wfwebapi/repository/QuizRepository.java b/src/main/java/com/example/wfwebapi/repository/QuizRepository.java new file mode 100644 index 0000000..5d14f1a --- /dev/null +++ b/src/main/java/com/example/wfwebapi/repository/QuizRepository.java @@ -0,0 +1,7 @@ +package com.example.wfwebapi.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.example.wfwebapi.model.Quiz; + +public interface QuizRepository extends JpaRepository { +} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/QuoteRepository.java b/src/main/java/com/example/wfwebapi/repository/QuoteRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/QuoteRepository.java rename to src/main/java/com/example/wfwebapi/repository/QuoteRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/RecordQuizRepository.java b/src/main/java/com/example/wfwebapi/repository/RecordQuizRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/RecordQuizRepository.java rename to src/main/java/com/example/wfwebapi/repository/RecordQuizRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/SourceRepository.java b/src/main/java/com/example/wfwebapi/repository/SourceRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/SourceRepository.java rename to src/main/java/com/example/wfwebapi/repository/SourceRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/UserRepository.java b/src/main/java/com/example/wfwebapi/repository/UserRepository.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/repository/UserRepository.java rename to src/main/java/com/example/wfwebapi/repository/UserRepository.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/security/JwtAuthenticationFilter.java b/src/main/java/com/example/wfwebapi/security/JwtAuthenticationFilter.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/security/JwtAuthenticationFilter.java rename to src/main/java/com/example/wfwebapi/security/JwtAuthenticationFilter.java diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/security/JwtTokenProvider.java b/src/main/java/com/example/wfwebapi/security/JwtTokenProvider.java similarity index 100% rename from WF-WEBAPI/src/main/java/com/example/wfwebapi/security/JwtTokenProvider.java rename to src/main/java/com/example/wfwebapi/security/JwtTokenProvider.java diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e08706e --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,25 @@ +# Configuration de la base de données H2 (en mémoire) +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= + +# Initialisation de la BDD avec le script +spring.sql.init.mode=always +spring.sql.init.schema-locations=classpath:init.sql + +# Configuration de JPA/Hibernate +spring.jpa.hibernate.ddl-auto=none +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true + +# Console H2 pour le débogage +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +# Port du serveur (filtré via Maven) +server.port=@server.port@ + +# (Optionnel) Niveaux de log pour SQL +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql new file mode 100644 index 0000000..45130e8 --- /dev/null +++ b/src/main/resources/init.sql @@ -0,0 +1,144 @@ +-- Suppression des tables (si elles existent) +DROP TABLE IF EXISTS commentary; +DROP TABLE IF EXISTS favorite; +DROP TABLE IF EXISTS daily_quote; +DROP TABLE IF EXISTS quote; +DROP TABLE IF EXISTS caracter; +DROP TABLE IF EXISTS source; +DROP TABLE IF EXISTS record_quiz; +DROP TABLE IF EXISTS quiz_question; +DROP TABLE IF EXISTS quiz; +DROP TABLE IF EXISTS question; +DROP TABLE IF EXISTS admin; +DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS image; + +-- Création des tables + +-- Table image (l'id est auto-incrémenté) +CREATE TABLE image ( + id_img INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + img_path VARCHAR(300) NOT NULL UNIQUE +); + +-- Table users (l'id est auto-incrémenté) +CREATE TABLE users ( + id_user INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + username VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL, + password VARCHAR(100) NOT NULL, + img INTEGER NOT NULL, + creation DATE NOT NULL, + CONSTRAINT unique_col UNIQUE (email), + CONSTRAINT fk_users_img FOREIGN KEY (img) REFERENCES image(id_img) +); + +-- Table admin +-- La colonne 'users' doit contenir l'id d'un utilisateur existant (pas auto-incrémenté ici) +CREATE TABLE admin ( + users INTEGER PRIMARY KEY, + CONSTRAINT fk_admin_user FOREIGN KEY (users) REFERENCES users(id_user) +); + +-- Table question (l'id est auto-incrémenté) +CREATE TABLE question ( + id_question INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + texte TEXT NOT NULL UNIQUE, + answer_a VARCHAR(30) NOT NULL, + answer_b VARCHAR(30) NOT NULL, + answer_c VARCHAR(30) NOT NULL, + answer_d VARCHAR(30) NOT NULL, + c_answer VARCHAR(30) NOT NULL, + CONSTRAINT check_c_answer CHECK (c_answer = answer_a OR c_answer = answer_b OR c_answer = answer_c OR c_answer = answer_d) +); + +-- Table quiz (l'id est auto-incrémenté) +CREATE TABLE quiz ( + id_quiz INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + title VARCHAR(40) NOT NULL, + img INTEGER NOT NULL, + nb_quest NUMERIC DEFAULT 0, + CONSTRAINT fk_quiz_img FOREIGN KEY (img) REFERENCES image(id_img) +); + +-- Table quiz_question +-- Les colonnes ici sont des clés étrangères et doivent être de type INTEGER (les valeurs proviennent des tables quiz et question) +CREATE TABLE quiz_question ( + quiz INTEGER NOT NULL, + question INTEGER NOT NULL, + PRIMARY KEY (quiz, question), + CONSTRAINT fk_quiz_question_quiz FOREIGN KEY (quiz) REFERENCES quiz(id_quiz), + CONSTRAINT fk_quiz_question_question FOREIGN KEY (question) REFERENCES question(id_question) +); + +-- Table record_quiz +CREATE TABLE record_quiz ( + users INTEGER NOT NULL, + quiz INTEGER NOT NULL, + nb_point NUMERIC DEFAULT 0, + time_q NUMERIC DEFAULT 0, + PRIMARY KEY (users, quiz), + CONSTRAINT fk_recordquiz_user FOREIGN KEY (users) REFERENCES users(id_user), + CONSTRAINT fk_recordquiz_quiz FOREIGN KEY (quiz) REFERENCES quiz(id_quiz), + CONSTRAINT err_nb_point CHECK (nb_point >= 0), + CONSTRAINT err_time_q CHECK (time_q >= 0) +); + +-- Table source (l'id est auto-incrémenté) +CREATE TABLE source ( + id_source INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + title VARCHAR(100) NOT NULL, + date_s NUMERIC(4) NOT NULL +); + +-- Table caracter (l'id est auto-incrémenté) +CREATE TABLE caracter ( + id_caracter INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + caracter VARCHAR(100) NOT NULL, + id_img INTEGER NOT NULL, + CONSTRAINT fk_caracter_image FOREIGN KEY (id_img) REFERENCES image(id_img) +); + +-- Table quote (l'id est auto-incrémenté) +CREATE TABLE quote ( + id_quote INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + content TEXT NOT NULL, + likes NUMERIC DEFAULT 0, + langue CHAR(2) NOT NULL, + is_valide BOOLEAN NOT NULL DEFAULT FALSE, + reason VARCHAR(100) NOT NULL, + id_caracter INTEGER NOT NULL, + id_source INTEGER NOT NULL, + id_user_verif INTEGER NOT NULL, + CONSTRAINT fk_quote_caracter FOREIGN KEY (id_caracter) REFERENCES caracter(id_caracter), + CONSTRAINT fk_quote_source FOREIGN KEY (id_source) REFERENCES source(id_source), + CONSTRAINT fk_quote_userverif FOREIGN KEY (id_user_verif) REFERENCES users(id_user), + CONSTRAINT err_nb_like CHECK (likes >= 0), + CONSTRAINT err_language CHECK (langue = 'fr' OR langue = 'en') +); + +-- Table daily_quote +CREATE TABLE daily_quote ( + citation_id INTEGER PRIMARY KEY, + FOREIGN KEY (citation_id) REFERENCES quote(id_quote) ON DELETE CASCADE +); + +-- Table favorite +CREATE TABLE favorite ( + users INTEGER NOT NULL, + quote INTEGER NOT NULL, + PRIMARY KEY (users, quote), + CONSTRAINT fk_favorite_quote FOREIGN KEY (quote) REFERENCES quote(id_quote), + CONSTRAINT fk_favorite_user FOREIGN KEY (users) REFERENCES users(id_user) +); + +-- Table commentary (l'id est auto-incrémenté) +CREATE TABLE commentary ( + id_comment INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + quote INTEGER NOT NULL, + users INTEGER NOT NULL, + date_c DATE NOT NULL, + comment TEXT NOT NULL, + CONSTRAINT fk_commentary_quote FOREIGN KEY (quote) REFERENCES quote(id_quote), + CONSTRAINT fk_commentary_user FOREIGN KEY (users) REFERENCES users(id_user) +); diff --git a/WF-WEBAPI/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java b/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java similarity index 100% rename from WF-WEBAPI/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java rename to src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java