From 236378e0cb214a62d21794fb36d2d990b5798e4f Mon Sep 17 00:00:00 2001 From: tomivt Date: Tue, 1 Apr 2025 17:12:15 +0200 Subject: [PATCH] Brand new Web services project --- WF-WEBAPI/Dockerfile | 13 - WF-WEBAPI/drone.yaml | 14 - WF-WEBAPI/pom.xml | 88 ----- .../example/wfwebapi/WfWebapiApplication.java | 11 - .../com/example/wfwebapi/model/Admin.java | 21 -- .../com/example/wfwebapi/model/Caracter.java | 27 -- .../example/wfwebapi/model/Commentary.java | 39 -- .../example/wfwebapi/model/DailyQuote.java | 21 -- .../com/example/wfwebapi/model/Favorite.java | 28 -- .../example/wfwebapi/model/FavoriteId.java | 37 -- .../com/example/wfwebapi/model/Image.java | 21 -- .../com/example/wfwebapi/model/Question.java | 46 --- .../java/com/example/wfwebapi/model/Quiz.java | 32 -- .../example/wfwebapi/model/QuizQuestion.java | 28 -- .../wfwebapi/model/QuizQuestionId.java | 37 -- .../com/example/wfwebapi/model/Quote.java | 59 --- .../example/wfwebapi/model/RecordQuiz.java | 38 -- .../example/wfwebapi/model/RecordQuizId.java | 37 -- .../com/example/wfwebapi/model/Source.java | 26 -- .../java/com/example/wfwebapi/model/User.java | 43 --- .../src/main/resources/application.properties | 12 - WF-WEBAPI/src/main/resources/init.sql | 338 ------------------ wtf/.gitattributes | 2 + wtf/.gitignore | 33 ++ .../.mvn/wrapper/maven-wrapper.properties | 0 {WF-WEBAPI => wtf}/mvnw | 0 {WF-WEBAPI => wtf}/mvnw.cmd | 0 wtf/pom.xml | 96 +++++ .../java/com/example/wtf/WtfApplication.java | 13 + .../wtf/controller/questionController.java | 114 ++++++ .../wtf/exception/ResourceNotFound.java | 10 + .../java/com/example/wtf/model/Question.java | 87 +++++ .../wtf/repository/questionRepository.java | 10 + wtf/src/main/resources/application.properties | 1 + .../com/example/wtf/WtfApplicationTests.java | 10 +- 35 files changed, 371 insertions(+), 1021 deletions(-) delete mode 100644 WF-WEBAPI/Dockerfile delete mode 100644 WF-WEBAPI/drone.yaml delete mode 100644 WF-WEBAPI/pom.xml delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/WfWebapiApplication.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Admin.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Caracter.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Commentary.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/DailyQuote.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Favorite.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/FavoriteId.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Image.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Question.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quiz.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestion.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quote.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuiz.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuizId.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Source.java delete mode 100644 WF-WEBAPI/src/main/java/com/example/wfwebapi/model/User.java delete mode 100644 WF-WEBAPI/src/main/resources/application.properties delete mode 100644 WF-WEBAPI/src/main/resources/init.sql create mode 100644 wtf/.gitattributes create mode 100644 wtf/.gitignore rename {WF-WEBAPI => wtf}/.mvn/wrapper/maven-wrapper.properties (100%) rename {WF-WEBAPI => wtf}/mvnw (100%) mode change 100644 => 100755 rename {WF-WEBAPI => wtf}/mvnw.cmd (100%) create mode 100644 wtf/pom.xml create mode 100644 wtf/src/main/java/com/example/wtf/WtfApplication.java create mode 100644 wtf/src/main/java/com/example/wtf/controller/questionController.java create mode 100644 wtf/src/main/java/com/example/wtf/exception/ResourceNotFound.java create mode 100644 wtf/src/main/java/com/example/wtf/model/Question.java create mode 100644 wtf/src/main/java/com/example/wtf/repository/questionRepository.java create mode 100644 wtf/src/main/resources/application.properties rename WF-WEBAPI/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java => wtf/src/test/java/com/example/wtf/WtfApplicationTests.java (52%) diff --git a/WF-WEBAPI/Dockerfile b/WF-WEBAPI/Dockerfile deleted file mode 100644 index 4f53606..0000000 --- a/WF-WEBAPI/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# Étape de build -FROM maven:3.8.6-openjdk-21 AS build -WORKDIR /app -COPY pom.xml . -COPY src ./src -RUN mvn clean package -DskipTests - -# Étape d'exécution -FROM openjdk:21-jdk -WORKDIR /app -COPY --from=build /app/target/demo-1.0.0.jar app.jar -EXPOSE 8080 -ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/WF-WEBAPI/drone.yaml b/WF-WEBAPI/drone.yaml deleted file mode 100644 index 98339c9..0000000 --- a/WF-WEBAPI/drone.yaml +++ /dev/null @@ -1,14 +0,0 @@ -kind: pipeline -type: docker -name: default - -steps: - - name: build - image: maven:3.8.6-openjdk-21 - commands: - - mvn clean package -DskipTests - - - name: test - image: maven:3.8.6-openjdk-21 - commands: - - mvn test diff --git a/WF-WEBAPI/pom.xml b/WF-WEBAPI/pom.xml deleted file mode 100644 index cc4f084..0000000 --- a/WF-WEBAPI/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.4 - - - com.example - WF-WEBAPI - 0.0.1-SNAPSHOT - WF-WEBAPI - WF-WEBAPI - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-hateoas - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-test - test - - - io.jsonwebtoken - jjwt-api - 0.11.5 - - - io.jsonwebtoken - jjwt-impl - 0.11.5 - runtime - - - io.jsonwebtoken - jjwt-jackson - 0.11.5 - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/WfWebapiApplication.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/WfWebapiApplication.java deleted file mode 100644 index 2f3716a..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/WfWebapiApplication.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.wfwebapi; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class WfWebapiApplication { - public static void main(String[] args) { - SpringApplication.run(WfWebapiApplication.class, args); - } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Admin.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Admin.java deleted file mode 100644 index 88b37db..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Admin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Admin") -public class Admin { - @Id - @Column(name = "users") - private Long userId; - - @OneToOne - @JoinColumn(name = "users", insertable = false, updatable = false) - private User user; - - // Getters et setters - public Long getUserId() { return userId; } - public void setUserId(Long userId) { this.userId = userId; } - public User getUser() { return user; } - public void setUser(User user) { this.user = user; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Caracter.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Caracter.java deleted file mode 100644 index 8b1311b..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Caracter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Caracter") -public class Caracter { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_caracter") - private Long id; - - @Column(name = "caracter", nullable = false, length = 100) - private String caracter; - - @ManyToOne - @JoinColumn(name = "id_img", nullable = false) - private Image image; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getCaracter() { return caracter; } - public void setCaracter(String caracter) { this.caracter = caracter; } - public Image getImage() { return image; } - public void setImage(Image image) { this.image = image; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Commentary.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Commentary.java deleted file mode 100644 index bfef8ac..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Commentary.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; -import java.time.LocalDate; - -@Entity -@Table(name = "Commentary") -public class Commentary { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_comment") - private Long id; - - @ManyToOne - @JoinColumn(name = "quote", nullable = false) - private Quote quote; - - @ManyToOne - @JoinColumn(name = "users", nullable = false) - private User user; - - @Column(name = "dateC", nullable = false) - private LocalDate dateC; - - @Column(name = "comment", nullable = false, columnDefinition = "text") - private String comment; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public Quote getQuote() { return quote; } - public void setQuote(Quote quote) { this.quote = quote; } - public User getUser() { return user; } - public void setUser(User user) { this.user = user; } - public LocalDate getDateC() { return dateC; } - public void setDateC(LocalDate dateC) { this.dateC = dateC; } - public String getComment() { return comment; } - public void setComment(String comment) { this.comment = comment; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/DailyQuote.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/DailyQuote.java deleted file mode 100644 index c74387b..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/DailyQuote.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "DailyQuote") -public class DailyQuote { - @Id - @Column(name = "citation_id") - private Long citationId; - - @OneToOne - @JoinColumn(name = "citation_id", insertable = false, updatable = false) - private Quote quote; - - // Getters et setters - public Long getCitationId() { return citationId; } - public void setCitationId(Long citationId) { this.citationId = citationId; } - public Quote getQuote() { return quote; } - public void setQuote(Quote quote) { this.quote = quote; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Favorite.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Favorite.java deleted file mode 100644 index 6658451..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Favorite.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Favorite") -public class Favorite { - @EmbeddedId - private FavoriteId id; - - @ManyToOne - @MapsId("user") - @JoinColumn(name = "users") - private User user; - - @ManyToOne - @MapsId("quote") - @JoinColumn(name = "quote") - private Quote quote; - - // Getters et setters - public FavoriteId getId() { return id; } - public void setId(FavoriteId id) { this.id = id; } - public User getUser() { return user; } - public void setUser(User user) { this.user = user; } - public Quote getQuote() { return quote; } - public void setQuote(Quote quote) { this.quote = quote; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/FavoriteId.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/FavoriteId.java deleted file mode 100644 index a94f061..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/FavoriteId.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.example.wfwebapi.model; - -import java.io.Serializable; -import java.util.Objects; -import jakarta.persistence.Embeddable; - -@Embeddable -public class FavoriteId implements Serializable { - private Long user; - private Long quote; - - public FavoriteId() {} - - public FavoriteId(Long user, Long quote) { - this.user = user; - this.quote = quote; - } - - public Long getUser() { return user; } - public void setUser(Long user) { this.user = user; } - public Long getQuote() { return quote; } - public void setQuote(Long quote) { this.quote = quote; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof FavoriteId)) return false; - FavoriteId that = (FavoriteId) o; - return Objects.equals(getUser(), that.getUser()) && - Objects.equals(getQuote(), that.getQuote()); - } - - @Override - public int hashCode() { - return Objects.hash(getUser(), getQuote()); - } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Image.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Image.java deleted file mode 100644 index 0821a9d..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Image.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Image") -public class Image { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_img") - private Long id; - - @Column(name = "imgPath", nullable = false, unique = true, length = 300) - private String imgPath; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getImgPath() { return imgPath; } - public void setImgPath(String imgPath) { this.imgPath = imgPath; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Question.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Question.java deleted file mode 100644 index 1692c5a..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Question.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Question") -public class Question { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_question") - private Long id; - - @Column(name = "texte", nullable = false, columnDefinition = "text", unique = true) - private String texte; - - @Column(name = "answerA", nullable = false, length = 30) - private String answerA; - - @Column(name = "answerB", nullable = false, length = 30) - private String answerB; - - @Column(name = "answerC", nullable = false, length = 30) - private String answerC; - - @Column(name = "answerD", nullable = false, length = 30) - private String answerD; - - @Column(name = "cAnswer", nullable = false, length = 30) - private String cAnswer; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getTexte() { return texte; } - public void setTexte(String texte) { this.texte = texte; } - public String getAnswerA() { return answerA; } - public void setAnswerA(String answerA) { this.answerA = answerA; } - public String getAnswerB() { return answerB; } - public void setAnswerB(String answerB) { this.answerB = answerB; } - public String getAnswerC() { return answerC; } - public void setAnswerC(String answerC) { this.answerC = answerC; } - public String getAnswerD() { return answerD; } - public void setAnswerD(String answerD) { this.answerD = answerD; } - public String getCAnswer() { return cAnswer; } - public void setCAnswer(String cAnswer) { this.cAnswer = cAnswer; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quiz.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quiz.java deleted file mode 100644 index d4e52e0..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quiz.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Quiz") -public class Quiz { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_quiz") - private Long id; - - @Column(name = "title", nullable = false, length = 40) - private String title; - - @ManyToOne - @JoinColumn(name = "img", nullable = false) - private Image image; - - @Column(name = "nb_quest") - private Integer nbQuest; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getTitle() { return title; } - public void setTitle(String title) { this.title = title; } - public Image getImage() { return image; } - public void setImage(Image image) { this.image = image; } - public Integer getNbQuest() { return nbQuest; } - public void setNbQuest(Integer nbQuest) { this.nbQuest = nbQuest; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestion.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestion.java deleted file mode 100644 index 9bb4456..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestion.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Quiz_Question") -public class QuizQuestion { - @EmbeddedId - private QuizQuestionId id; - - @ManyToOne - @MapsId("quiz") - @JoinColumn(name = "quiz") - private Quiz quiz; - - @ManyToOne - @MapsId("question") - @JoinColumn(name = "question") - private Question question; - - // Getters et setters - public QuizQuestionId getId() { return id; } - public void setId(QuizQuestionId id) { this.id = id; } - public Quiz getQuiz() { return quiz; } - public void setQuiz(Quiz quiz) { this.quiz = quiz; } - public Question getQuestion() { return question; } - public void setQuestion(Question question) { this.question = question; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java deleted file mode 100644 index fe72b5f..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/QuizQuestionId.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.example.wfwebapi.model; - -import java.io.Serializable; -import java.util.Objects; -import jakarta.persistence.Embeddable; - -@Embeddable -public class QuizQuestionId implements Serializable { - private Long quiz; - private Long question; - - public QuizQuestionId() {} - - public QuizQuestionId(Long quiz, Long question) { - this.quiz = quiz; - this.question = question; - } - - public Long getQuiz() { return quiz; } - public void setQuiz(Long quiz) { this.quiz = quiz; } - public Long getQuestion() { return question; } - public void setQuestion(Long question) { this.question = question; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof QuizQuestionId)) return false; - QuizQuestionId that = (QuizQuestionId) o; - return Objects.equals(getQuiz(), that.getQuiz()) && - Objects.equals(getQuestion(), that.getQuestion()); - } - - @Override - public int hashCode() { - return Objects.hash(getQuiz(), getQuestion()); - } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quote.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quote.java deleted file mode 100644 index ec57184..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Quote.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Quote") -public class Quote { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_quote") - private Long id; - - @Column(name = "content", nullable = false, columnDefinition = "text") - private String content; - - @Column(name = "likes") - private Integer likes; - - @Column(name = "langue", nullable = false, length = 2) - private String langue; - - @Column(name = "isValide", nullable = false) - private Boolean isValide; - - @Column(name = "reason", nullable = false, length = 100) - private String reason; - - @ManyToOne - @JoinColumn(name = "id_caracter", nullable = false) - private Caracter caracter; - - @ManyToOne - @JoinColumn(name = "id_source", nullable = false) - private Source source; - - @ManyToOne - @JoinColumn(name = "id_user_verif", nullable = false) - private User userVerif; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getContent() { return content; } - public void setContent(String content) { this.content = content; } - public Integer getLikes() { return likes; } - public void setLikes(Integer likes) { this.likes = likes; } - public String getLangue() { return langue; } - public void setLangue(String langue) { this.langue = langue; } - public Boolean getIsValide() { return isValide; } - public void setIsValide(Boolean isValide) { this.isValide = isValide; } - public String getReason() { return reason; } - public void setReason(String reason) { this.reason = reason; } - public Caracter getCaracter() { return caracter; } - public void setCaracter(Caracter caracter) { this.caracter = caracter; } - public Source getSource() { return source; } - public void setSource(Source source) { this.source = source; } - public User getUserVerif() { return userVerif; } - public void setUserVerif(User userVerif) { this.userVerif = userVerif; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuiz.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuiz.java deleted file mode 100644 index 3883c31..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuiz.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Record_quiz") -public class RecordQuiz { - @EmbeddedId - private RecordQuizId id; - - @ManyToOne - @MapsId("user") - @JoinColumn(name = "users") - private User user; - - @ManyToOne - @MapsId("quiz") - @JoinColumn(name = "quiz") - private Quiz quiz; - - @Column(name = "nbPoint") - private Integer nbPoint; - - @Column(name = "timeQ") - private Integer timeQ; - - // Getters et setters - public RecordQuizId getId() { return id; } - public void setId(RecordQuizId id) { this.id = id; } - public User getUser() { return user; } - public void setUser(User user) { this.user = user; } - public Quiz getQuiz() { return quiz; } - public void setQuiz(Quiz quiz) { this.quiz = quiz; } - public Integer getNbPoint() { return nbPoint; } - public void setNbPoint(Integer nbPoint) { this.nbPoint = nbPoint; } - public Integer getTimeQ() { return timeQ; } - public void setTimeQ(Integer timeQ) { this.timeQ = timeQ; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuizId.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuizId.java deleted file mode 100644 index d73335b..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/RecordQuizId.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.example.wfwebapi.model; - -import java.io.Serializable; -import java.util.Objects; -import jakarta.persistence.Embeddable; - -@Embeddable -public class RecordQuizId implements Serializable { - private Long user; - private Long quiz; - - public RecordQuizId() {} - - public RecordQuizId(Long user, Long quiz) { - this.user = user; - this.quiz = quiz; - } - - public Long getUser() { return user; } - public void setUser(Long user) { this.user = user; } - public Long getQuiz() { return quiz; } - public void setQuiz(Long quiz) { this.quiz = quiz; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RecordQuizId)) return false; - RecordQuizId that = (RecordQuizId) o; - return Objects.equals(getUser(), that.getUser()) && - Objects.equals(getQuiz(), that.getQuiz()); - } - - @Override - public int hashCode() { - return Objects.hash(getUser(), getQuiz()); - } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Source.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Source.java deleted file mode 100644 index 68d8869..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/Source.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; - -@Entity -@Table(name = "Source") -public class Source { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_source") - private Long id; - - @Column(name = "title", nullable = false, length = 100) - private String title; - - @Column(name = "dateS", nullable = false) - private Integer dateS; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getTitle() { return title; } - public void setTitle(String title) { this.title = title; } - public Integer getDateS() { return dateS; } - public void setDateS(Integer dateS) { this.dateS = dateS; } -} diff --git a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/User.java b/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/User.java deleted file mode 100644 index 21299fc..0000000 --- a/WF-WEBAPI/src/main/java/com/example/wfwebapi/model/User.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.example.wfwebapi.model; - -import jakarta.persistence.*; -import java.time.LocalDate; - -@Entity -@Table(name = "Users", uniqueConstraints = @UniqueConstraint(columnNames = "email")) -public class User { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id_user") - private Long id; - - @Column(name = "username", nullable = false, length = 50) - private String username; - - @Column(name = "email", nullable = false, length = 50) - private String email; - - @Column(name = "password", nullable = false, length = 100) - private String password; - - @ManyToOne - @JoinColumn(name = "img", nullable = false) - private Image image; - - @Column(name = "creation", nullable = false) - private LocalDate creation; - - // Getters et setters - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - public String getUsername() { return username; } - public void setUsername(String username) { this.username = username; } - public String getEmail() { return email; } - public void setEmail(String email) { this.email = email; } - public String getPassword() { return password; } - public void setPassword(String password) { this.password = password; } - public Image getImage() { return image; } - public void setImage(Image image) { this.image = image; } - public LocalDate getCreation() { return creation; } - public void setCreation(LocalDate creation) { this.creation = creation; } -} 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/wtf/.gitattributes b/wtf/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/wtf/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/wtf/.gitignore b/wtf/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/wtf/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/WF-WEBAPI/.mvn/wrapper/maven-wrapper.properties b/wtf/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from WF-WEBAPI/.mvn/wrapper/maven-wrapper.properties rename to wtf/.mvn/wrapper/maven-wrapper.properties diff --git a/WF-WEBAPI/mvnw b/wtf/mvnw old mode 100644 new mode 100755 similarity index 100% rename from WF-WEBAPI/mvnw rename to wtf/mvnw diff --git a/WF-WEBAPI/mvnw.cmd b/wtf/mvnw.cmd similarity index 100% rename from WF-WEBAPI/mvnw.cmd rename to wtf/mvnw.cmd diff --git a/wtf/pom.xml b/wtf/pom.xml new file mode 100644 index 0000000..f2f69a3 --- /dev/null +++ b/wtf/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.example + wtf + 0.0.1-SNAPSHOT + wtf + Demo project for Spring Boot + + + + + + + + + + + + + + + 17 + + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-data-rest + + + org.springframework.boot + spring-boot-starter-hateoas + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/wtf/src/main/java/com/example/wtf/WtfApplication.java b/wtf/src/main/java/com/example/wtf/WtfApplication.java new file mode 100644 index 0000000..e42c74c --- /dev/null +++ b/wtf/src/main/java/com/example/wtf/WtfApplication.java @@ -0,0 +1,13 @@ +package com.example.wtf; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WtfApplication { + + public static void main(String[] args) { + SpringApplication.run(WtfApplication.class, args); + } + +} diff --git a/wtf/src/main/java/com/example/wtf/controller/questionController.java b/wtf/src/main/java/com/example/wtf/controller/questionController.java new file mode 100644 index 0000000..74794bb --- /dev/null +++ b/wtf/src/main/java/com/example/wtf/controller/questionController.java @@ -0,0 +1,114 @@ +package com.example.wtf.controller; + +import com.example.wtf.exception.ResourceNotFound; +import com.example.wtf.model.Question; +import com.example.wtf.repository.questionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.CollectionModel; +import org.springframework.hateoas.EntityModel; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; + +@RestController +@RequestMapping("/questions") +public class questionController { + @Autowired + private questionRepository repo; + + @GetMapping("/get") + public @ResponseBody CollectionModel> getQuestions() { + List> questions = new ArrayList<>(); + + for (Question question : repo.findAll()) { + EntityModel questionResource = EntityModel.of( + question, + linkTo(methodOn(questionController.class).getQuestion(question.getId())).withSelfRel(), + linkTo(methodOn(questionController.class).updateQuestion(question.getId(), null)).withRel("Update question"), + linkTo(methodOn(questionController.class).deleteQuestion(question.getId())).withRel("Delete question") + ); + questions.add(questionResource); + } + + return CollectionModel.of( + questions, + linkTo(methodOn(questionController.class).addQuestion(null)).withRel("Add Question") + ); + } + + @GetMapping("/get/{id}") + public @ResponseBody EntityModel getQuestion(@PathVariable Long id) { + Question question = repo.findQuestionById(id); + if (question == null) { + throw new ResourceNotFound(HttpStatus.NOT_FOUND, "Question not found"); + } + return EntityModel.of( + question, + linkTo(methodOn(questionController.class).updateQuestion(question.getId(), null)).withRel("Update question"), + linkTo(methodOn(questionController.class).deleteQuestion(question.getId())).withRel("Delete question"), + linkTo(methodOn(questionController.class).getQuestions()).withRel("Questions") + ); + } + + @PostMapping("/add") + public @ResponseBody EntityModel addQuestion(@RequestBody Question question) { + repo.save(question); + return EntityModel.of( + question, + linkTo(methodOn(questionController.class).getQuestion(question.getId())).withSelfRel(), + linkTo(methodOn(questionController.class).updateQuestion(question.getId(), null)).withRel("Update question"), + linkTo(methodOn(questionController.class).deleteQuestion(question.getId())).withRel("Delete question"), + linkTo(methodOn(questionController.class).getQuestions()).withRel("Questions") + ); + } + + @PutMapping("/update/{id}") + public @ResponseBody EntityModel updateQuestion(@PathVariable Long id, + @RequestBody Question question) { + Question q = repo.findQuestionById(id); + if (q == null) throw new ResourceNotFound(HttpStatus.NOT_FOUND, "Question not found"); + if (question.getContent() != null && !question.getContent().isEmpty()) { + q.setContent(question.getContent()); + } + if (question.getAnswerA() != null && !question.getAnswerA().isEmpty()) { + q.setAnswerA(question.getAnswerA()); + } + if (question.getAnswerB() != null && !question.getAnswerB().isEmpty()) { + q.setAnswerB(question.getAnswerB()); + } + if (question.getAnswerC() != null && !question.getAnswerC().isEmpty()) { + q.setAnswerC(question.getAnswerC()); + } + if (question.getAnswerD() != null && !question.getAnswerD().isEmpty()) { + q.setAnswerD(question.getAnswerD()); + } + if (question.getcAnswer() != null && !question.getcAnswer().isEmpty()) { + q.setcAnswer(question.getcAnswer()); + } + repo.save(q); + return EntityModel.of( + q, + linkTo(methodOn(questionController.class).getQuestion(id)).withSelfRel(), + linkTo(methodOn(questionController.class).deleteQuestion(id)).withRel("Delete question"), + linkTo(methodOn(questionController.class).getQuestions()).withRel("Questions") + ); + } + + @DeleteMapping("delete/{id}") + public @ResponseBody EntityModel deleteQuestion(@PathVariable Long id) { + Question q = repo.findQuestionById(id); + if (q == null) throw new ResourceNotFound(HttpStatus.NOT_FOUND, "Question not found"); + + repo.delete(q); + + return EntityModel.of( + q, + linkTo(methodOn(questionController.class).getQuestions()).withRel("Questions") + ); + } +} diff --git a/wtf/src/main/java/com/example/wtf/exception/ResourceNotFound.java b/wtf/src/main/java/com/example/wtf/exception/ResourceNotFound.java new file mode 100644 index 0000000..6af61d7 --- /dev/null +++ b/wtf/src/main/java/com/example/wtf/exception/ResourceNotFound.java @@ -0,0 +1,10 @@ +package com.example.wtf.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +public class ResourceNotFound extends ResponseStatusException { + public ResourceNotFound(HttpStatus error, String message) { + super(error, message); + } +} diff --git a/wtf/src/main/java/com/example/wtf/model/Question.java b/wtf/src/main/java/com/example/wtf/model/Question.java new file mode 100644 index 0000000..37b7d38 --- /dev/null +++ b/wtf/src/main/java/com/example/wtf/model/Question.java @@ -0,0 +1,87 @@ +package com.example.wtf.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Question { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + private String content; + private String answerA; + private String answerB; + private String answerC; + private String answerD; + private String cAnswer; + + public Question() {} + + public Question(String content, String answerB, String answerA, String answerC, String answerD, String cAnswer) { + this.content = content; + this.answerB = answerB; + this.answerA = answerA; + this.answerC = answerC; + this.answerD = answerD; + this.cAnswer = cAnswer; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getAnswerA() { + return answerA; + } + + public void setAnswerA(String answerA) { + this.answerA = answerA; + } + + public String getAnswerB() { + return answerB; + } + + public void setAnswerB(String answerB) { + this.answerB = answerB; + } + + public String getAnswerC() { + return answerC; + } + + public void setAnswerC(String answerC) { + this.answerC = answerC; + } + + public String getAnswerD() { + return answerD; + } + + public void setAnswerD(String answerD) { + this.answerD = answerD; + } + + public String getcAnswer() { + return cAnswer; + } + + public void setcAnswer(String cAnswer) { + this.cAnswer = cAnswer; + } +} diff --git a/wtf/src/main/java/com/example/wtf/repository/questionRepository.java b/wtf/src/main/java/com/example/wtf/repository/questionRepository.java new file mode 100644 index 0000000..d4120d0 --- /dev/null +++ b/wtf/src/main/java/com/example/wtf/repository/questionRepository.java @@ -0,0 +1,10 @@ +package com.example.wtf.repository; + +import com.example.wtf.model.Question; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface questionRepository extends CrudRepository { + Question findQuestionById(Long id); +} diff --git a/wtf/src/main/resources/application.properties b/wtf/src/main/resources/application.properties new file mode 100644 index 0000000..56ba0d3 --- /dev/null +++ b/wtf/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=wtf diff --git a/WF-WEBAPI/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java b/wtf/src/test/java/com/example/wtf/WtfApplicationTests.java similarity index 52% rename from WF-WEBAPI/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java rename to wtf/src/test/java/com/example/wtf/WtfApplicationTests.java index 19174da..55bc274 100644 --- a/WF-WEBAPI/src/test/java/com/example/wfwebapi/WfWebapiApplicationTests.java +++ b/wtf/src/test/java/com/example/wtf/WtfApplicationTests.java @@ -1,13 +1,13 @@ -package com.example.wfwebapi; +package com.example.wtf; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class WfWebapiApplicationTests { +class WtfApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } }