diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 007222b..eabd3e3 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -20,6 +20,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-mail") implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-data-jpa") // implementation("org.springframework.session:spring-session-jdbc") developmentOnly("org.springframework.boot:spring-boot-devtools") developmentOnly("org.springframework.boot:spring-boot-docker-compose") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java new file mode 100644 index 0000000..affb301 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -0,0 +1,44 @@ +package ovh.herisson.Clyde.EndPoints; + + +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Repositories.UserRepository; +import ovh.herisson.Clyde.Tables.User; + + +@RestController +@CrossOrigin(origins = "http://localhost:5173") +public class UserController { + + private final UserRepository userRepo; + + public UserController(UserRepository userRepo){ + this.userRepo = userRepo; + } + + @GetMapping("/user") + public ResponseEntity getUsers(@RequestHeader("Authorization") String token){ + //TODO + // Get the token thru the data base + // tokenRepo.findToken(token) => User userFromToken + // si role != secretary => return error : ResponseEntity(null, HttpStatus.UNAUTHORIZED) + return new ResponseEntity(/**userRepo.findById(userFromToken.id),**/ HttpStatus.OK); + } + + @PostMapping("/user") + public ResponseEntity postUser(@RequestBody User user){ + userRepo.save(user); + return new ResponseEntity(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED); + } + + @GetMapping("/users") + public Iterable getAllUsers(){//TODO ne l'accepter que si c'est le secrétariat + return userRepo.findAll(); + } + + +} + diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java new file mode 100644 index 0000000..38f9ae0 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java @@ -0,0 +1,16 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.User; + +import java.util.List; + +public interface UserRepository extends CrudRepository { + + User findById(long id); + + /** + @Query(value = "select a.* from Users a ",nativeQuery = true) + Iterable findAllUsers();**/ +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java new file mode 100644 index 0000000..54e167a --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -0,0 +1,52 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Course { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int courseID; + private int credits; + private String title; + private String faculty; + + public Course(int credits, String title, String faculty){ + this.credits = credits; + this.title = title; + this.faculty = faculty; + } + + public Course() {} + + public int getCourseID() { + return courseID; + } + + public int getCredits() { + return credits; + } + + public void setCredits(int credits){ + this.credits = credits; + } + + public String getFaculty() { + return faculty; + } + + public void setFaculty(String faculty){ + this.faculty = faculty; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title){ + this.title = title; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java new file mode 100644 index 0000000..5167197 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java @@ -0,0 +1,43 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Cursus { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int cursusId; + private int year; + private String option; + + public Cursus(int year, String option){ + this.year = year; + this.option = option; + } + + public Cursus() {} + + public int getCursusId(){ + return this.cursusId; + } + + public int getYear(){ + return this.year; + } + + public void setYear(int year){ + this.year = year; + } + + public String getOption(){ + return this.option; + } + + public void setOption(String option){ + this.option = option; + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java new file mode 100644 index 0000000..e48e6a3 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java @@ -0,0 +1,43 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class CursusCourse { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @JoinColumn(name = "Cursus") + private int cursusId; + + @JoinColumn(name = "Course") + private int courseId; + + public CursusCourse(int cursusId, int courseId){ + this.cursusId = cursusId; + this.courseId = courseId; + } + + public CursusCourse() {} + + public int getId() { + return id; + } + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId){ + this.courseId = courseId; + } + + public int getCursusId() { + return cursusId; + } + + public void setCursusId(int cursusId) { + this.cursusId = cursusId; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java new file mode 100644 index 0000000..bb14f3f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Tables; + +public enum Role { + Teacher, + Student, + Admin, + Secretary; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java new file mode 100644 index 0000000..cf533a0 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java @@ -0,0 +1,41 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class Secretary { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @JoinColumn(name = "Users") + private int regNo; + private String faculty; + + public Secretary(int regNo, String faculty){ + this.regNo = regNo; + this.faculty = faculty; + } + + public Secretary() {} + + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public String getFaculty() { + return faculty; + } + + public void setFaculty(String faculty) { + this.faculty = faculty; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java new file mode 100644 index 0000000..9cb931e --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java @@ -0,0 +1,55 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class TeacherGivenCourse { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @JoinColumn(name = "Users") + private int regNo; + + @JoinColumn(name = "Course") + private int courseId; + + //This flag helps make the difference between an assistant or a Teacher (who owns the course) + private boolean owned; + + public TeacherGivenCourse(int regNo, int courseId, boolean owned){ + this.regNo = regNo; + this.courseId = courseId; + this.owned = owned; + } + + public TeacherGivenCourse() {} + + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId) { + this.courseId = courseId; + } + + public boolean isOwned() { + return owned; + } + + public void setOwned(boolean owned) { + this.owned = owned; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java new file mode 100644 index 0000000..ec59cbf --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java @@ -0,0 +1,40 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class Token { + @GeneratedValue(strategy = GenerationType.AUTO) + @Id + private int id; + + @JoinColumn(name ="Users") + private int regNo; + private String token; + + public Token(int regNo, String token){ + this.regNo = regNo; + this.token = token; + } + + public Token(){} + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public String getToken(){ + return token; + } + + public void setToken(String data) { + this.token = data; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java new file mode 100644 index 0000000..746ac3b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -0,0 +1,103 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +import java.util.Date; + +//Classe représentant un utilisateur l'attribut password demande surement un peu de rafinement niveau sécurité +//et l'attribut tokenApi doit encore être ajouté vu qu'il faut en discuter + +@Entity +//Je rajoute un s au nom de la table pour éviter les conflits avec les mots réservés +@Table(name = "Users") +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int regNo; + private String lastName; + private String firstName; + private String email; + private String address; + private String country; + private Date birthDate; + private ovh.herisson.Clyde.Tables.Role role; + private String password; + public User(String lastName, String firstName, String email, String address, String country, Date birthDate, Role role, String password){ + this.lastName = lastName; + this.firstName = firstName; + this.email = email; + this.address = address; + this.country = country; + this.birthDate = birthDate; + this.role = role; + this.password = password; + } + + public User() {} + + public int getRegNo(){ + return this.regNo; + } + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getAddress() { + return address; + } + + public void setAddress(String adress) { + this.address = adress; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + + public ovh.herisson.Clyde.Tables.Role getRole() { + return role; + } + + public void setRole(ovh.herisson.Clyde.Tables.Role role) { + this.role = role; + } + public String getPassword(){ + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java new file mode 100644 index 0000000..4de1559 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java @@ -0,0 +1,42 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class UserCursus { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + @JoinColumn(name = "Users") + private int regNo; + + @JoinColumn(name = "Cursus") + private int cursusId; + + public UserCursus(int regNo, int cursusId){ + this.regNo = regNo; + this.cursusId = cursusId; + } + + public UserCursus() {} + + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public int getCursusId() { + return cursusId; + } + + public void setCursusId(int cursusId) { + this.cursusId = cursusId; + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index ef0c300..df288a6 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1 +1,2 @@ +spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect