Merge pull request 'LeoMoulin/Backend/Leo' (#55) from LeoMoulin/Backend/Leo into master
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build and test backend / Build-backend (push) Successful in 2m2s
				
			
		
			
				
	
				Build and test backend / Test-backend (push) Successful in 1m19s
				
			
		
			
				
	
				deploy to production / deploy-frontend (push) Successful in 21s
				
			
		
			
				
	
				deploy to production / deploy-backend (push) Successful in 2m13s
				
			
		
			
				
	
				Build and test FrontEnd / Build-frontend (push) Successful in 19s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build and test backend / Build-backend (push) Successful in 2m2s
				
			Build and test backend / Test-backend (push) Successful in 1m19s
				
			deploy to production / deploy-frontend (push) Successful in 21s
				
			deploy to production / deploy-backend (push) Successful in 2m13s
				
			Build and test FrontEnd / Build-frontend (push) Successful in 19s
				
			Reviewed-on: #55
This commit is contained in:
		| @ -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") | ||||
|  | ||||
| @ -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<User> getUsers(@RequestHeader("Authorization") String token){ | ||||
|         //TODO | ||||
|         // Get the token thru the data base | ||||
|         // tokenRepo.findToken(token) => User userFromToken | ||||
|         // si role != secretary => return error : ResponseEntity<User>(null, HttpStatus.UNAUTHORIZED) | ||||
|         return new ResponseEntity<User>(/**userRepo.findById(userFromToken.id),**/ HttpStatus.OK); | ||||
|     } | ||||
|  | ||||
|     @PostMapping("/user") | ||||
|     public ResponseEntity<String> postUser(@RequestBody User user){ | ||||
|         userRepo.save(user); | ||||
|         return new ResponseEntity<String>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/users") | ||||
|     public Iterable<User> getAllUsers(){//TODO ne l'accepter que si c'est le secrétariat | ||||
|         return userRepo.findAll(); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -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, Long> { | ||||
|  | ||||
|     User findById(long id); | ||||
|  | ||||
|     /** | ||||
|     @Query(value = "select a.* from Users a ",nativeQuery = true) | ||||
|     Iterable<User> findAllUsers();**/ | ||||
| } | ||||
							
								
								
									
										52
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java
									
									
									
									
									
										Normal file
									
								
							| @ -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; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										43
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java
									
									
									
									
									
										Normal file
									
								
							| @ -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; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,8 @@ | ||||
| package ovh.herisson.Clyde.Tables; | ||||
|  | ||||
| public enum Role { | ||||
|     Teacher, | ||||
|     Student, | ||||
|     Admin, | ||||
|     Secretary; | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										40
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java
									
									
									
									
									
										Normal file
									
								
							| @ -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; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										103
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/User.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								backend/src/main/java/ovh/herisson/Clyde/Tables/User.java
									
									
									
									
									
										Normal file
									
								
							| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -1 +1,2 @@ | ||||
| spring.jpa.hibernate.ddl-auto=create-drop | ||||
| spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect | ||||
|  | ||||
		Reference in New Issue
	
	Block a user