From cb750b8505f956717eb137a06f161eb89210c446 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 2 Apr 2024 21:40:52 +0200 Subject: [PATCH] Database creation (Tables) --- backend/build.gradle.kts | 2 ++ .../ovh/herisson/Clyde/Tables/Course.java | 9 ++++++ .../herisson/Clyde/Tables/Msg/Answers.java | 32 +++++++++++++++++++ .../ovh/herisson/Clyde/Tables/Msg/Forum.java | 28 ++++++++++++++++ .../ovh/herisson/Clyde/Tables/Msg/Topic.java | 26 +++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index b7cabcd..794631f 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -16,6 +16,8 @@ repositories { } dependencies { + compileOnly("org.projectlombok:lombok") + annotationProcessor("org.projectlombok:lombok") implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-mail") diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java index df0421d..8870618 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,6 +1,10 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import ovh.herisson.Clyde.Tables.Msg.Forum; + +import java.util.List; + import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -17,6 +21,11 @@ public class Course { @JoinColumn(name = "Users") private User owner; + //// Extension Messagerie ///// + @OneToMany + private List forums; + /////////////////////////////// + public Course(int credits, String title, User owner){ this.credits = credits; this.title = title; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java new file mode 100644 index 0000000..2f4d452 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java @@ -0,0 +1,32 @@ +package ovh.herisson.Clyde.Tables.Msg; + + +import java.util.Date; + +import org.hibernate.annotations.CreationTimestamp; + +import jakarta.persistence.*; +import lombok.Data; +import ovh.herisson.Clyde.Tables.User; + +@Entity +@Data +public class Answers { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @CreationTimestamp + private Date creation; + + @ManyToOne + private Topic topic; + + private String content; + + @OneToOne + private User author; + + private boolean anonymous; + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java new file mode 100644 index 0000000..e021c18 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java @@ -0,0 +1,28 @@ +package ovh.herisson.Clyde.Tables.Msg; + +import java.util.List; + +import jakarta.persistence.*; +import lombok.Data; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.User; + +@Entity +@Data +public class Forum { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne(cascade = CascadeType.ALL) + private Course course; + + private String name; + + @OneToMany + private List writers; // User who are authorized to create a post + + @OneToMany + private List register; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java new file mode 100644 index 0000000..d63b3e1 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java @@ -0,0 +1,26 @@ +package ovh.herisson.Clyde.Tables.Msg; + +import java.util.List; + +import jakarta.persistence.*; +import lombok.Data; +import ovh.herisson.Clyde.Tables.User; + +@Entity +@Data +public class Topic { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + private String subject, content; + + @OneToOne + private User author; + + @OneToMany(mappedBy = "topic", cascade = CascadeType.ALL) + private List answers; + + private boolean locked; // true if new messages can be posted +}