diff --git a/backend/app/Dockerfile b/backend/app/Dockerfile index 976b713b..6c964fdd 100644 --- a/backend/app/Dockerfile +++ b/backend/app/Dockerfile @@ -1,4 +1,14 @@ -FROM eclipse-temurin:17-jdk-alpine -VOLUME /tmp -COPY build/libs/*T.jar app.jar -ENTRYPOINT ["java","-jar","/app.jar"] +FROM gradle:jdk17 AS build +COPY --chown=gradle:gradle . /home/gradle/src +WORKDIR /home/gradle/src +RUN gradle build --no-daemon + +FROM eclipse-temurin:17 + +EXPOSE 8080 + +RUN mkdir /app + +COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar +ENTRYPOINT ["java", "-jar","/app/spring-boot-application.jar"] + diff --git a/backend/app/build.gradle b/backend/app/build.gradle index 04c8ec16..a7302389 100644 --- a/backend/app/build.gradle +++ b/backend/app/build.gradle @@ -1,4 +1,4 @@ -plugins { + plugins { id 'java' id 'org.springframework.boot' version '3.2.2' id 'io.spring.dependency-management' version '1.1.4' @@ -19,7 +19,6 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' - developmentOnly 'org.springframework.boot:spring-boot-docker-compose' runtimeOnly 'org.postgresql:postgresql' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-web' @@ -33,7 +32,10 @@ dependencies { implementation 'com.auth0:java-jwt:3.18.2' implementation 'com.auth0:jwks-rsa:0.18.0' implementation 'javax.servlet:javax.servlet-api:4.0.1' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + runtimeOnly 'org.postgresql:postgresql' + implementation "org.springframework.boot:spring-boot-devtools" testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } diff --git a/backend/app/src/main/java/com/ugent/selab2/config/AuthConfig.java b/backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java similarity index 78% rename from backend/app/src/main/java/com/ugent/selab2/config/AuthConfig.java rename to backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java index 973801cc..5868e59e 100644 --- a/backend/app/src/main/java/com/ugent/selab2/config/AuthConfig.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java @@ -1,13 +1,15 @@ -package com.ugent.selab2.config; +package com.ugent.pidgeon.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.FilterRegistrationBean; 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.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; @Configuration +@EnableWebSecurity public class AuthConfig { @Value("${azure.activedirectory.tenant-id}") @@ -16,14 +18,15 @@ public class AuthConfig { @Bean public FilterRegistrationBean filterRegistrationBean() { System.out.println("tenantId: " + tenantId); + FilterRegistrationBean filter = new FilterRegistrationBean<>(); filter.setFilter(new JwtAuthenticationFilter(tenantId)); - filter.addUrlPatterns("/api/*"); + filter.addUrlPatterns("/api/ietswatiknietwiltesten"); return filter; } @Bean - SecurityFilterChain web(HttpSecurity http) throws Exception { + public SecurityFilterChain web(HttpSecurity http) throws Exception { http .authorizeHttpRequests((authorize) -> authorize .anyRequest().permitAll() diff --git a/backend/app/src/main/java/com/ugent/selab2/config/JwtAuthenticationFilter.java b/backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java similarity index 83% rename from backend/app/src/main/java/com/ugent/selab2/config/JwtAuthenticationFilter.java rename to backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java index 04d0ded0..4ef865e3 100644 --- a/backend/app/src/main/java/com/ugent/selab2/config/JwtAuthenticationFilter.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.ugent.selab2.config; +package com.ugent.pidgeon.config; import com.auth0.jwk.Jwk; import com.auth0.jwk.JwkException; @@ -8,8 +8,8 @@ import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.exceptions.SignatureVerificationException; import com.auth0.jwt.interfaces.DecodedJWT; -import com.ugent.selab2.model.Auth; -import com.ugent.selab2.model.User; +import com.ugent.pidgeon.model.Auth; +import com.ugent.pidgeon.model.User; import org.springframework.http.HttpStatus; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.util.StringUtils; @@ -30,6 +30,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { public JwtAuthenticationFilter(String tenantId) { try { + logger.info("tenantId: " + tenantId); provider = new UrlJwkProvider(new URL("https://login.microsoftonline.com/"+tenantId+"/discovery/v2.0/keys")); } catch (MalformedURLException e) { e.printStackTrace(); @@ -55,11 +56,18 @@ protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, algorithm.verify(jwt);// if the token signature is invalid, the method will throw SignatureVerificationException // get the data from the token - String name = jwt.getClaim("name").asString(); - String email = jwt.getClaim("email").asString(); + String displayName = jwt.getClaim("name").asString(); + String firstName = jwt.getClaim("given_name").asString(); + String lastName = jwt.getClaim("family_name").asString(); + String email = jwt.getClaim("unique_name").asString(); List groups = jwt.getClaim("groups").asList(String.class); String oid = jwt.getClaim("oid").asString(); - User user = new User(name, email, groups, oid); + + // print full object + //logger.info(jwt.getClaims()); + + + User user = new User(displayName, firstName,lastName, email, groups, oid); Auth authUser = new Auth(user, new ArrayList<>()); SecurityContextHolder.getContext().setAuthentication(authUser); @@ -73,8 +81,6 @@ protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, response.setStatus(HttpStatus.UNAUTHORIZED.value()); // Forbidden } - logger.info("Token: " + token); - } else { logger.warn("No token found!"); response.setStatus(HttpStatus.UNAUTHORIZED.value()); // Unauthorized diff --git a/backend/app/src/main/java/com/ugent/selab2/config/OAuth2ClientConfig.java b/backend/app/src/main/java/com/ugent/pidgeon/config/OAuth2ClientConfig.java similarity index 97% rename from backend/app/src/main/java/com/ugent/selab2/config/OAuth2ClientConfig.java rename to backend/app/src/main/java/com/ugent/pidgeon/config/OAuth2ClientConfig.java index ea7c1212..863c56ab 100644 --- a/backend/app/src/main/java/com/ugent/selab2/config/OAuth2ClientConfig.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/config/OAuth2ClientConfig.java @@ -1,4 +1,4 @@ -package com.ugent.selab2.config; +package com.ugent.pidgeon.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/backend/app/src/main/java/com/ugent/selab2/config/WebConfig.java b/backend/app/src/main/java/com/ugent/pidgeon/config/WebConfig.java similarity index 93% rename from backend/app/src/main/java/com/ugent/selab2/config/WebConfig.java rename to backend/app/src/main/java/com/ugent/pidgeon/config/WebConfig.java index d56ad9c3..8b94ced5 100644 --- a/backend/app/src/main/java/com/ugent/selab2/config/WebConfig.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/config/WebConfig.java @@ -1,4 +1,4 @@ -package com.ugent.selab2.config; +package com.ugent.pidgeon.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; diff --git a/backend/app/src/main/java/com/ugent/selab2/controllers/AuthTestController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java similarity index 60% rename from backend/app/src/main/java/com/ugent/selab2/controllers/AuthTestController.java rename to backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java index 50c05834..95536323 100644 --- a/backend/app/src/main/java/com/ugent/selab2/controllers/AuthTestController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java @@ -1,12 +1,16 @@ -package com.ugent.selab2.controllers; -import com.ugent.selab2.model.Auth; -import com.ugent.selab2.model.User; +package com.ugent.pidgeon.controllers; +import com.ugent.pidgeon.model.Auth; +import com.ugent.pidgeon.model.User; +import com.ugent.pidgeon.postgre.repository.UserRepository; import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class AuthTestController { + @Autowired + private UserRepository userRepository; @GetMapping("/api/test") public User testApi(HttpServletRequest request, Auth auth) { @@ -21,7 +25,7 @@ public String ping() { @GetMapping("/") public String index() { - return "Running..."; + return "Running!!!..."; } } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java new file mode 100644 index 00000000..7991cf6f --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -0,0 +1,55 @@ +package com.ugent.pidgeon.controllers; + +import com.ugent.pidgeon.postgre.models.CourseEntity; +import com.ugent.pidgeon.postgre.models.GroupClusterEntity; +import com.ugent.pidgeon.postgre.models.ProjectEntity; +import com.ugent.pidgeon.postgre.models.UserEntity; +import com.ugent.pidgeon.postgre.repository.CourseRepository; +import com.ugent.pidgeon.postgre.repository.GroupClusterRepository; +import com.ugent.pidgeon.postgre.repository.ProjectRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +public class JpaCourseController { + @Autowired + private CourseRepository courseRepository; + + @Autowired + private GroupClusterRepository groupClusterRepository; + + @Autowired + private ProjectRepository projectRepository; + + @GetMapping("/api/courses") + public String getCourses() { + StringBuilder res = new StringBuilder(); + for (CourseEntity course : courseRepository.findAll()) { + res.append(course.getName()).append(" with users: "); + for (CourseRepository.UserWithRelation user : courseRepository.findUsersByCourseId(course.getId())) { + UserEntity userEntity = user.getUser(); + String relation = user.getRelation(); + res.append(userEntity.getName()).append("(").append(relation).append("), "); + } + res.append("- with group clusters:"); + for (GroupClusterEntity groupcluster: groupClusterRepository.findByCourseId(course.getId())) { + res.append(groupcluster.getName()).append(" (").append(groupcluster.getGroupAmount()).append("), "); + } + res.append("- with projects:"); + for (ProjectEntity project: projectRepository.findByCourseId(course.getId())) { + res.append(project.getName()).append(", "); + } + res.append("|\n"); + } + + return res.toString(); + } + +// @GetMapping("/api/course") +// public String addCourse(String name, String description) { +// CourseEntity course = new CourseEntity("test", "added to test creating with contstructing"); +// course.setId(1); +// courseRepository.save(course); +// return "Course added"; +// } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java new file mode 100644 index 00000000..b3845a87 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java @@ -0,0 +1,55 @@ +package com.ugent.pidgeon.controllers; + +import com.ugent.pidgeon.postgre.models.GroupEntity; +import com.ugent.pidgeon.postgre.models.GroupFeedbackEntity; +import com.ugent.pidgeon.postgre.models.SubmissionEntity; +import com.ugent.pidgeon.postgre.models.UserEntity; +import com.ugent.pidgeon.postgre.repository.GroupFeedbackRepository; +import com.ugent.pidgeon.postgre.repository.GroupRepository; +import com.ugent.pidgeon.postgre.repository.SubmissionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +public class JpaGroupController { + + @Autowired + private GroupRepository groupRepository; + + @Autowired + private GroupFeedbackRepository groupFeedbackRepository; + + @Autowired + SubmissionRepository submissionRepository; + + @GetMapping("/api/groups") + public List getGroups() { + List res = new ArrayList<>(); + for (GroupEntity group : groupRepository.findAll()) { + StringBuilder groupString = new StringBuilder(); + groupString.append(group.getName()).append("-with users: "); + for (UserEntity user : groupRepository.findCourseUsersByGroupId(group.getId())) { + groupString.append(user.getName()).append(", "); + } + List projectIds = groupRepository.findProjectsByGroupId(group.getId()); + groupString.append("-with grades: "); + for (long projectId : projectIds) { + GroupFeedbackEntity feedback = groupFeedbackRepository.findByGroupIdAndProjectId(group.getId(), projectId); + groupString.append(feedback.getGrade()).append(", "); + } + groupString.append("-with submissions: "); + for (long projectId : projectIds) { + for (SubmissionEntity submission : submissionRepository.findByGroupIdAndProjectId(group.getId(), projectId)) { + groupString.append(submission.getSubmissionTime()).append(", "); + } + } + groupString.append("|"); + res.add(groupString.toString()); + } + return res; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java new file mode 100644 index 00000000..eb245d3d --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java @@ -0,0 +1,39 @@ +package com.ugent.pidgeon.controllers; + +import com.ugent.pidgeon.postgre.models.DeadlineEntity; +import com.ugent.pidgeon.postgre.models.ProjectEntity; +import com.ugent.pidgeon.postgre.models.TestEntity; +import com.ugent.pidgeon.postgre.repository.ProjectRepository; +import com.ugent.pidgeon.postgre.repository.TestRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@RestController +public class JpaProjectController { + @Autowired + private ProjectRepository projectRepository; + + @Autowired + private TestRepository testRepository; + + @GetMapping("/api/projects") + public List getProjects() { + List res = new ArrayList<>(); + for (ProjectEntity project : projectRepository.findAll()) { + StringBuilder projectString = new StringBuilder(project.getName()); + Optional test = testRepository.findById(project.getId()); + test.ifPresent(testEntity -> projectString.append(" with test: ").append(testEntity.getId())); + projectString.append(" with deadlines: "); + for (DeadlineEntity deadline : project.getDeadlines()) { + projectString.append(deadline.getDeadline()); + } + res.add(projectString.toString()); + } + return res; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaSubmissionController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaSubmissionController.java new file mode 100644 index 00000000..4fabad41 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaSubmissionController.java @@ -0,0 +1,38 @@ +package com.ugent.pidgeon.controllers; + +import com.ugent.pidgeon.postgre.models.FileEntity; +import com.ugent.pidgeon.postgre.models.SubmissionEntity; +import com.ugent.pidgeon.postgre.repository.FileRepository; +import com.ugent.pidgeon.postgre.repository.SubmissionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@RestController +public class JpaSubmissionController { + @Autowired + private SubmissionRepository submissionRepository; + + @Autowired + private FileRepository fileRepository; + + @GetMapping("/api/submissions") + public List getSubmissions() { + List res = new ArrayList<>(); + for (SubmissionEntity submission : submissionRepository.findAll()) { + StringBuilder submissionString = new StringBuilder(); + submissionString.append(submission.getSubmissionTime()).append(" with files: "); + Optional file = fileRepository.findById(submission.getFileId()); + file.ifPresent(fileEntity -> submissionString.append(fileEntity.getName()).append(", ")); + + submissionString.append("|"); + res.add(submissionString.toString()); + } + return res; + } + +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java new file mode 100644 index 00000000..7619473c --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -0,0 +1,34 @@ + package com.ugent.pidgeon.controllers; + + import com.ugent.pidgeon.postgre.models.CourseEntity; + import com.ugent.pidgeon.postgre.models.types.CourseRelation; + import com.ugent.pidgeon.postgre.models.UserEntity; + import com.ugent.pidgeon.postgre.repository.UserRepository; + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.web.bind.annotation.GetMapping; + import org.springframework.web.bind.annotation.RestController; + + @RestController + public class JpaUserController { + @Autowired + private UserRepository userRepository; + + Logger logger = LoggerFactory.getLogger(JpaUserController.class); + @GetMapping("/api/users") + public String getUsers() { + StringBuilder res = new StringBuilder(); + for (UserEntity user : userRepository.findAll()) { + res.append(user.getName()).append("(").append(user.getRole().toString()).append(") in courses: "); + for (UserRepository.CourseWithRelation course : userRepository.findCoursesByUserId(user.getId())) { + CourseEntity courseEntity = course.getCourse(); + CourseRelation courseRelation = course.getRelation(); + res.append(courseEntity.getName()).append("(").append(courseRelation.toString()).append("), "); + } + res.append("\n"); + } + + return res.toString(); + } + } diff --git a/backend/app/src/main/java/com/ugent/selab2/model/Auth.java b/backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java similarity index 96% rename from backend/app/src/main/java/com/ugent/selab2/model/Auth.java rename to backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java index 944aca14..492ebe41 100644 --- a/backend/app/src/main/java/com/ugent/selab2/model/Auth.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java @@ -1,11 +1,11 @@ -package com.ugent.selab2.model; +package com.ugent.pidgeon.model; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; import org.springframework.util.Assert; import java.util.Collection; - +import com.ugent.pidgeon.model.User; public class Auth extends AbstractAuthenticationToken { private static final long serialVersionUID = 620L; diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/User.java b/backend/app/src/main/java/com/ugent/pidgeon/model/User.java new file mode 100644 index 00000000..d3c78a02 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/User.java @@ -0,0 +1,22 @@ +package com.ugent.pidgeon.model; + +import java.util.List; + +public class User { + + public String name; + public String firstName; + public String lastName; + public String email; + public List groups; + public String oid; + + public User (String name, String firstName, String lastName, String email, List groups, String oid) { + this.name = name; + this.email = email; + this.groups = groups; + this.oid = oid; + this.firstName = firstName; + this.lastName = lastName; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java new file mode 100644 index 00000000..f5f6ebb5 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -0,0 +1,69 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +import java.sql.Timestamp; +import java.util.HashSet; +import java.util.Set; + + +@Entity +@Table(name = "courses") +public class CourseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "course_id", nullable = false) + private long id; + @Column(name = "course_name", nullable=false) + private String name; + @Column(name = "description", nullable=false) + private String description; + + @Column(name = "created_at") + private Timestamp createdAt; + + public CourseEntity(String name, String description) { + this.name = name; + this.description = description; + } + + public CourseEntity() { + + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseUserEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseUserEntity.java new file mode 100644 index 00000000..e29a5f56 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseUserEntity.java @@ -0,0 +1,65 @@ +package com.ugent.pidgeon.postgre.models; + +import com.ugent.pidgeon.postgre.models.types.CourseRelation; +import jakarta.persistence.*; + +import java.io.Serializable; + +@Entity +@IdClass(CourseUserId.class) +@Table(name="course_users") +public class CourseUserEntity { + + @Id + @Column(name="course_id", nullable=false) + private long courseId; + + @Id + @Column(name="user_id", nullable=false) + private long userId; + + @Column(name = "course_relation") + @Enumerated(EnumType.STRING) + private CourseRelation relation; + + public CourseUserEntity() { + } + + public CourseUserEntity(long courseId, long userId, CourseRelation relation) { + this.courseId = courseId; + this.userId = userId; + this.relation = relation; + } + + + public long getCourseId() { + return courseId; + } + + public void setCourseId(long courseId) { + this.courseId = courseId; + } + + public long getUserId() { + return userId; + } + + public void setUserId(long userId) { + this.userId = userId; + } + + public CourseRelation getRelation() { + return relation; + } + + public void setRelation(CourseRelation relation) { + this.relation = relation; + } + + +} + +class CourseUserId implements Serializable { + private long courseId; + private long userId; +} \ No newline at end of file diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/DeadlineEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/DeadlineEntity.java new file mode 100644 index 00000000..b1db7050 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/DeadlineEntity.java @@ -0,0 +1,53 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +import java.sql.Timestamp; + +@Entity +@Table(name = "deadlines") +public class DeadlineEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "deadline_id") + private Long deadlineId; + + @ManyToOne + @JoinColumn(name = "project_id") + private ProjectEntity project; + + @Column(name = "deadline") + private Timestamp deadline; + + public DeadlineEntity() { + } + + public DeadlineEntity(ProjectEntity project, Timestamp deadline) { + this.project = project; + this.deadline = deadline; + } + + public Long getDeadlineId() { + return deadlineId; + } + + public void setDeadlineId(Long deadlineId) { + this.deadlineId = deadlineId; + } + + public ProjectEntity getProject() { + return project; + } + + public void setProject(ProjectEntity project) { + this.project = project; + } + + public Timestamp getDeadline() { + return deadline; + } + + public void setDeadline(Timestamp deadline) { + this.deadline = deadline; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/FileEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/FileEntity.java new file mode 100644 index 00000000..f7e0acef --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/FileEntity.java @@ -0,0 +1,63 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +@Entity +@Table(name = "files") +public class FileEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "file_id", nullable = false) + private long id; + + @Column(name = "file_name", nullable = false) + private String name; + + @Column(name = "file_path", nullable = false) + private String path; + + @Column(name = "uploaded_by", nullable = false) + private long uploadedBy; + + public FileEntity() { + } + + public FileEntity(String name, String path, long uploadedBy) { + this.name = name; + this.path = path; + this.uploadedBy = uploadedBy; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public long getUploadedBy() { + return uploadedBy; + } + + public void setUploadedBy(long uploadedBy) { + this.uploadedBy = uploadedBy; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupClusterEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupClusterEntity.java new file mode 100644 index 00000000..bc69f043 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupClusterEntity.java @@ -0,0 +1,90 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +import java.sql.Timestamp; + +@Entity +@Table(name="group_clusters") +public class GroupClusterEntity { + + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="group_cluster_id", nullable=false) + private long id; + + @Column(name="course_id", nullable=false) + private long courseId; + + @Column(name="max_size", nullable=false) + private int maxSize; + + @Column(name="cluster_name", nullable=false) + private String name; + + @Column(name="group_amount", nullable=false) + private int groupAmount; + + @Column(name = "created_at") + private Timestamp createdAt; + + public GroupClusterEntity(long courseId, int maxSize, String name, int groupAmount) { + this.courseId = courseId; + this.maxSize = maxSize; + this.name = name; + this.groupAmount = groupAmount; + } + + public GroupClusterEntity() { + + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getCourseId() { + return courseId; + } + + public void setCourseId(long course_id) { + this.courseId = course_id; + } + + public int getMaxSize() { + return maxSize; + } + + public void setMaxSize(int max_size) { + this.maxSize = max_size; + } + + public String getName() { + return name; + } + + public void setName(String cluster_name) { + this.name = cluster_name; + } + + public int getGroupAmount() { + return groupAmount; + } + + public void setGroupAmount(int group_amount) { + this.groupAmount = group_amount; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupEntity.java new file mode 100644 index 00000000..725aeea3 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupEntity.java @@ -0,0 +1,52 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +@Entity +@Table(name="groups") +public class GroupEntity { + + @Id + @GeneratedValue + @Column(name="group_id", nullable=false) + private long id; + + @Column(name="group_name", nullable=false) + private String name; + + @Column(name="group_cluster", nullable = false) + private long clusterId; + + public GroupEntity(String name, long clusterId) { + this.name = name; + this.clusterId = clusterId; + } + + public GroupEntity() { + + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public long getClusterId() { + return clusterId; + } + + public void setClusterId(int cluster) { + this.clusterId = cluster; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupFeedbackEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupFeedbackEntity.java new file mode 100644 index 00000000..3bea7ca8 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupFeedbackEntity.java @@ -0,0 +1,72 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +import java.io.Serializable; + +@Entity +@IdClass(GroupFeedBackId.class) +@Table(name = "group_feedback") +public class GroupFeedbackEntity { + + @Id + @Column(name = "group_id", nullable = false) + private long groupId; + + @Id + @Column(name = "project_id", nullable = false) + private long projectId; + + @Column(name = "grade") + private Float grade; + + @Column(name = "feedback") + private String feedback; + + public GroupFeedbackEntity() { + } + + public GroupFeedbackEntity(long groupId, long projectId, Float grade, String feedback) { + this.groupId = groupId; + this.projectId = projectId; + this.grade = grade; + this.feedback = feedback; + } + + public long getGroupId() { + return groupId; + } + + public void setGroupId(long groupId) { + this.groupId = groupId; + } + + public long getProjectId() { + return projectId; + } + + public void setProjectId(long projectId) { + this.projectId = projectId; + } + + public Float getGrade() { + return grade; + } + + public void setGrade(Float grade) { + this.grade = grade; + } + + public String getFeedback() { + return feedback; + } + + public void setFeedback(String feedback) { + this.feedback = feedback; + } +} + +class GroupFeedBackId implements Serializable { + private long groupId; + private long projectId; +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupUserEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupUserEntity.java new file mode 100644 index 00000000..4b23d528 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupUserEntity.java @@ -0,0 +1,47 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +import java.io.Serializable; + +@Entity +@IdClass(GroupUserId.class) +@Table(name="group_users") +public class GroupUserEntity { + @Id + @Column(name="group_id", nullable=false) + private long groupId; + + @Id + @Column(name="user_id", nullable=false) + private long userId; + + public GroupUserEntity() { + } + + public GroupUserEntity(long group_id, long user_id) { + this.groupId = group_id; + this.userId = user_id; + } + + public long getGroupId() { + return groupId; + } + + public void setGroupId(long group_id) { + this.groupId = group_id; + } + + public long getUserId() { + return userId; + } + + public void setUserId(long user_id) { + this.userId = user_id; + } +} + +class GroupUserId implements Serializable { + private long groupId; + private long userId; +} \ No newline at end of file diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java new file mode 100644 index 00000000..98a4de30 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java @@ -0,0 +1,121 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; +import java.sql.Timestamp; +import java.util.List; + + +@Entity +@Table(name = "projects") +public class ProjectEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "project_id", nullable = false) + private long id; + + @Column(name="course_id", nullable = false) + private long courseId; + + @Column(name="project_name", nullable = false) + private String name; + + @Column(name="description", nullable = false) + private String description; + + @Column(name="group_cluster_id", nullable = false) + private long groupClusterId; + + @Column(name="test_id", nullable = false) + private long testId; + + @Column(name="visible", nullable = false) + private Boolean projectType; + + @OneToMany(mappedBy = "project") + private List deadlines; + + @Column(name="max_score") + private Integer maxScore; + + public ProjectEntity(long courseId, String name, String description, long groupClusterId, long testId, Boolean projectType, Integer maxScore) { + this.courseId = courseId; + this.name = name; + this.description = description; + this.groupClusterId = groupClusterId; + this.testId = testId; + this.projectType = projectType; + this.maxScore = maxScore; + } + + public ProjectEntity() { + } + + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getCourseId() { + return courseId; + } + + public void setCourseId(long courseId) { + this.courseId = courseId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public long getGroupClusterId() { + return groupClusterId; + } + + public void setGroupClusterId(long groupClusterId) { + this.groupClusterId = groupClusterId; + } + + public long getTestId() { + return testId; + } + + public void setTestId(long testId) { + this.testId = testId; + } + + public Boolean getProjectType() { + return projectType; + } + + public void setProjectType(Boolean projectType) { + this.projectType = projectType; + } + + public List getDeadlines() { + return deadlines; + } + public Integer getMaxScore() { + return maxScore; + } + + public void setMaxScore(Integer maxScore) { + this.maxScore = maxScore; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/SubmissionEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/SubmissionEntity.java new file mode 100644 index 00000000..c43ba695 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/SubmissionEntity.java @@ -0,0 +1,86 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import java.sql.Timestamp; + +@Entity +@Table(name="submissions") +public class SubmissionEntity { + @Id + @Column(name="submission_id", nullable=false) + private long id; + + @Column(name="project_id", nullable=false) + private long projectId; + + @Column(name="group_id", nullable=false) + private long groupId; + + @Column(name="file_id", nullable=false) + private long fileId; + + @Column(name="submission_time", nullable=false) + private Timestamp submissionTime; + + @Column(name="accepted", nullable=false) + private Boolean accepted; + + public SubmissionEntity() { + } + + public SubmissionEntity(long projectId, long groupId, long fileId, Timestamp submissionTime, Boolean accepted) { + this.projectId = projectId; + this.groupId = groupId; + this.fileId = fileId; + this.submissionTime = submissionTime; + this.accepted = accepted; + } + + public long getGroupId() { + return groupId; + } + + public long getFileId() { + return fileId; + } + + public void setFileId(long fileId) { + this.fileId = fileId; + } + + public Timestamp getSubmissionTime() { + return submissionTime; + } + + public void setSubmissionTime(Timestamp submissionTime) { + this.submissionTime = submissionTime; + } + + public Boolean getAccepted() { + return accepted; + } + + public void setAccepted(Boolean accepted) { + this.accepted = accepted; + } + + + public long getProjectId() { + return projectId; + } + + public void setProjectId(long projectId) { + this.projectId = projectId; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/TestEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/TestEntity.java new file mode 100644 index 00000000..a39cfb67 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/TestEntity.java @@ -0,0 +1,53 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +@Entity +@Table(name = "tests") +public class TestEntity { + + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "test_id", nullable = false) + private long id; + + @Column(name = "docker_image") + private String dockerImage; + + @Column(name = "file_test_id") + private long fileTestId; + + public TestEntity() { + } + + public TestEntity(String dockerImage, long fileTestId) { + this.dockerImage = dockerImage; + this.fileTestId = fileTestId; + } + + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public String getDockerImage() { + return dockerImage; + } + + public void setDockerImage(String dockerImage) { + this.dockerImage = dockerImage; + } + + public long getFileTestId() { + return fileTestId; + } + + public void setFileTestId(long fileTestId) { + this.fileTestId = fileTestId; + } +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserEntity.java new file mode 100644 index 00000000..76d629ab --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserEntity.java @@ -0,0 +1,104 @@ +package com.ugent.pidgeon.postgre.models; + + +import com.ugent.pidgeon.postgre.models.types.UserRole; +import jakarta.persistence.*; + +import java.sql.Timestamp; + +@Entity +@Table(name = "users") +public class UserEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id", nullable = false) + private long id; + + @Column(name = "name", nullable=false) + private String name; + + @Column(name = "surname", nullable=false) + private String surname; + + @Column(name = "email", nullable=false) + private String email; + + @Column(name = "role") + @Enumerated(EnumType.STRING) + private UserRole role; + + @Column(name = "microsoft_token") + private String microsoftToken; + + @Column(name = "created_at") + private Timestamp createdAt; + + public UserEntity(String name, String surname, String email, UserRole role, String microsoftToken) { + this.name = name; + this.surname = surname; + this.email = email; + this.role = role; + this.microsoftToken = microsoftToken; + } + + public UserEntity() { + + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public UserRole getRole() { + return role; + } + + public String getMicrosoftToken() { + return microsoftToken; + } + + public void setMicrosoftToken(String microsoftToken) { + this.microsoftToken = microsoftToken; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } +} + diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/CourseRelation.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/CourseRelation.java new file mode 100644 index 00000000..8c0b254e --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/CourseRelation.java @@ -0,0 +1,7 @@ +package com.ugent.pidgeon.postgre.models.types; + +public enum CourseRelation { + creator, + course_admin, + enrolled +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/UserRole.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/UserRole.java new file mode 100644 index 00000000..53997f1a --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/UserRole.java @@ -0,0 +1,7 @@ +package com.ugent.pidgeon.postgre.models.types; + +public enum UserRole { + student, + admin, + teacher +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/CourseRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/CourseRepository.java new file mode 100644 index 00000000..cf5fdeae --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/CourseRepository.java @@ -0,0 +1,22 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.CourseEntity; +import com.ugent.pidgeon.postgre.models.UserEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + +public interface CourseRepository extends JpaRepository { + + + + public interface UserWithRelation { + UserEntity getUser(); + String getRelation(); + } + + /* The 'as' is important here, as it is used to map the result to the CourseWithRelation interface */ + @Query(value = "SELECT u as user, cu.relation as relation FROM UserEntity u JOIN CourseUserEntity cu ON u.id = cu.userId WHERE cu.courseId = ?1") + List findUsersByCourseId(long id); +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/FileRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/FileRepository.java new file mode 100644 index 00000000..b29e5711 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/FileRepository.java @@ -0,0 +1,7 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.FileEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FileRepository extends JpaRepository { +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupClusterRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupClusterRepository.java new file mode 100644 index 00000000..45d3b320 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupClusterRepository.java @@ -0,0 +1,10 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.GroupClusterEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface GroupClusterRepository extends JpaRepository { + List findByCourseId(long courseId); +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupFeedbackRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupFeedbackRepository.java new file mode 100644 index 00000000..28ec8f56 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupFeedbackRepository.java @@ -0,0 +1,8 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.GroupFeedbackEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface GroupFeedbackRepository extends JpaRepository { + GroupFeedbackEntity findByGroupIdAndProjectId(long groupId, long projectId); +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupRepository.java new file mode 100644 index 00000000..95c3cfb2 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupRepository.java @@ -0,0 +1,23 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.GroupEntity; +import com.ugent.pidgeon.postgre.models.ProjectEntity; +import com.ugent.pidgeon.postgre.models.UserEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + +public interface GroupRepository extends JpaRepository{ + + @Query(value= "SELECT u FROM UserEntity u JOIN GroupUserEntity gu ON u.id = gu.userId WHERE gu.groupId = ?1") + List findCourseUsersByGroupId(long id); + + + @Query(value = """ + SELECT p.id FROM ProjectEntity p + JOIN GroupClusterEntity gc ON p.groupClusterId = gc.id + JOIN GroupEntity g ON g.clusterId = gc.id + WHERE g.id = ?1""") + List findProjectsByGroupId(long id); +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/ProjectRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/ProjectRepository.java new file mode 100644 index 00000000..7cacecb3 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/ProjectRepository.java @@ -0,0 +1,10 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.ProjectEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ProjectRepository extends JpaRepository { + List findByCourseId(long courseId); +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/SubmissionRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/SubmissionRepository.java new file mode 100644 index 00000000..6a107b86 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/SubmissionRepository.java @@ -0,0 +1,10 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.SubmissionEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface SubmissionRepository extends JpaRepository { + List findByGroupIdAndProjectId(long groupId, long projectId); +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/TestRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/TestRepository.java new file mode 100644 index 00000000..cfa9cd32 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/TestRepository.java @@ -0,0 +1,7 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.TestEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TestRepository extends JpaRepository { +} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/UserRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/UserRepository.java new file mode 100644 index 00000000..bc1b5d86 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/UserRepository.java @@ -0,0 +1,24 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.CourseEntity; +import com.ugent.pidgeon.postgre.models.types.CourseRelation; +import com.ugent.pidgeon.postgre.models.UserEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface UserRepository extends JpaRepository { + + + public interface CourseWithRelation { + CourseEntity getCourse(); + CourseRelation getRelation(); + } + + /* The 'as' is important here, as it is used to map the result to the CourseWithRelation interface */ + @Query(value = "SELECT c as course, cu.relation as relation FROM CourseEntity c JOIN CourseUserEntity cu ON c.id = cu.courseId WHERE cu.userId = ?1") + List findCoursesByUserId(long id); +} diff --git a/backend/app/src/main/java/com/ugent/selab2/model/User.java b/backend/app/src/main/java/com/ugent/selab2/model/User.java deleted file mode 100644 index 599db7f9..00000000 --- a/backend/app/src/main/java/com/ugent/selab2/model/User.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.ugent.selab2.model; - -import java.util.List; - -public class User { - - public String name; - public String email; - public List groups; - public String oid; - - public User (String name, String email, List groups, String oid) { - this.name = name; - this.email = email; - this.groups = groups; - this.oid = oid; - } -} diff --git a/backend/app/src/main/resources/application-azuread.yml b/backend/app/src/main/resources/application-azuread.yml deleted file mode 100644 index 1a929321..00000000 --- a/backend/app/src/main/resources/application-azuread.yml +++ /dev/null @@ -1,19 +0,0 @@ -spring: - security: - oauth2: - client: - provider: - azure: - issuer-uri: https://login.microsoftonline.com/62835335-e5c4-4d22-98f2-9d5b65a06d9d/v2.0 - user-name-attribute: name - registration: - azure: - provider: azure - #client-id: "6035bfd4-22f0-437c-b76f-da729a916cbf" - #client-secret: "fo28Q~-aLbmQvonnZtzbgtSiqYstmBWEmGPAodmx" - client-id: 39136cda-f02f-4305-9b08-45f132bab07e - client-secret: i1n8Q~57EDI.E2iLxzkW3Q.ixEtVIM4jwN7eDbxK - scope: - - openid - - email - - profile \ No newline at end of file diff --git a/backend/app/src/main/resources/application.properties b/backend/app/src/main/resources/application.properties index 864e1028..b622818b 100644 --- a/backend/app/src/main/resources/application.properties +++ b/backend/app/src/main/resources/application.properties @@ -1,4 +1,15 @@ - +#spring.datasource.url = jdbc:postgresql://localhost:5432/postgres +#spring.datasource.username = admin +#spring.datasource.password = root +#spring.jpa.show-sql=true +#spring.jpa.database=postgresql +# +## Hibernate Properties +# The SQL dialect makes Hibernate generate better SQL for the chosen database +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect + +# Hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto = update server.port=8080 @@ -6,7 +17,8 @@ azure.activedirectory.client-id=39136cda-f02f-4305-9b08-45f132bab07e azure.activedirectory.b2c.client-secret=i1n8Q~57EDI.E2iLxzkW3Q.ixEtVIM4jwN7eDbxK # For UGent auth: d7811cde-ecef-496c-8f91-a1786241b99c -azure.activedirectory.tenant-id=62835335-e5c4-4d22-98f2-9d5b65a06d9d +# Test auth: 62835335-e5c4-4d22-98f2-9d5b65a06d9d +azure.activedirectory.tenant-id=d7811cde-ecef-496c-8f91-a1786241b99c #spring.security.oauth2.client.registration.azure.client-id=39136cda-f02f-4305-9b08-45f132bab07e #spring.security.oauth2.client.registration.azure.client-secret=i1n8Q~57EDI.E2iLxzkW3Q.ixEtVIM4jwN7eDbxK diff --git a/backend/app/src/test/java/com/ugent/pidgeon/PidgeonApplicationTests.java b/backend/app/src/test/java/com/ugent/pidgeon/PidgeonApplicationTests.java index 6b5f5d03..85846c69 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/PidgeonApplicationTests.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/PidgeonApplicationTests.java @@ -6,8 +6,8 @@ @SpringBootTest class PidgeonApplicationTests { - @Test + /*@Test void contextLoads() { - } + }*/ } diff --git a/backend/db/password.txt b/backend/db/password.txt new file mode 100644 index 00000000..f77b0040 --- /dev/null +++ b/backend/db/password.txt @@ -0,0 +1 @@ +admin \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 4bdb01ef..f09124c1 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,19 +12,22 @@ services: backend: container_name: spring_container build: backend/app/ + depends_on: + - db ports: - 8080:8080 environment: - - 'POSTGRES_DB=pidegon_db' - networks: - - spring-postgres - postgres: - container_name: pg_container + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres + - SPRING_DATASOURCE_USERNAME=admin + - SPRING_DATASOURCE_PASSWORD=root + restart: always + db: + container_name: db image: 'postgres:latest' secrets: - db-password environment: - - 'POSTGRES_DB=pidgeon_db' + - 'POSTGRES_PASSWORD=root' - 'POSTGRES_USER=admin' ports: - '5432:5432' @@ -34,7 +37,7 @@ services: container_name: container-pgadmin image: dpage/pgadmin4 depends_on: - - postgres + - db ports: - "5050:80" environment: @@ -51,5 +54,3 @@ volumes: secrets: db-password: file: backend/db/password.txt -networks: - spring-postgres: diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8b172683..badc8bb6 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -16,22 +16,10 @@ function App({ pca }: AppProps) { const navigationClient = new CustomNavigation(navigate); pca.setNavigationClient(navigationClient); - // const handleLogin = async () => { - // try { - // // await promise; - // // await msalInstance.loginPopup(); // Initiate popup login - // // const account: AccountInfo | null = msalInstance.getActiveAccount(); - // // console.log(account); - // } catch (error) { - // console.error(error) - // } - // } return (
-
- {/* */} - +
diff --git a/frontend/src/auth/AuthConfig.ts b/frontend/src/auth/AuthConfig.ts index 0c1368ff..9ee22102 100644 --- a/frontend/src/auth/AuthConfig.ts +++ b/frontend/src/auth/AuthConfig.ts @@ -5,7 +5,7 @@ export const msalConfig: Configuration = { auth: { clientId: "39136cda-f02f-4305-9b08-45f132bab07e", //For UGent auth: "https://login.microsoftonline.com/d7811cde-ecef-496c-8f91-a1786241b99c", - authority: "https://login.microsoftonline.com/62835335-e5c4-4d22-98f2-9d5b65a06d9d", + authority: "https://login.microsoftonline.com/d7811cde-ecef-496c-8f91-a1786241b99c", // "https://login.microsoftonline.com/62835335-e5c4-4d22-98f2-9d5b65a06d9d", redirectUri: "/dashboard", postLogoutRedirectUri: "/" }, diff --git a/frontend/src/auth/MsGraphApiCall.ts b/frontend/src/auth/MsGraphApiCall.ts index ee6e64ad..6e7ca923 100644 --- a/frontend/src/auth/MsGraphApiCall.ts +++ b/frontend/src/auth/MsGraphApiCall.ts @@ -7,6 +7,8 @@ export async function callMsGraph() { throw Error("No active account! Verify a user has been signed in and setActiveAccount has been called."); } + console.log(account); + const response = await msalInstance.acquireTokenSilent({ ...loginRequest, account: account diff --git a/frontend/src/pages/profile/Profile.tsx b/frontend/src/pages/profile/Profile.tsx index efc3271e..a2c03d87 100644 --- a/frontend/src/pages/profile/Profile.tsx +++ b/frontend/src/pages/profile/Profile.tsx @@ -24,15 +24,20 @@ const ProfileContent = () => { if (!graphData && inProgress === InteractionStatus.None) { callMsGraph().then(response => setGraphData(response)).catch((e) => { if (e instanceof InteractionRequiredAuthError) { - instance.acquireTokenRedirect({ - ...loginRequest, - account: instance.getActiveAccount() as AccountInfo - }); + + // instance.acquireTokenRedirect({ + // ...loginRequest, + // account: instance.getActiveAccount() as AccountInfo + // }); } - }); + }).catch(err => { + console.log(err); + }) ; } }, [inProgress, graphData, instance]); - + + + console.log(graphData); return (
{ graphData ? : null } @@ -41,10 +46,12 @@ const ProfileContent = () => { }; export function Profile() { + + + const authRequest = { ...loginRequest }; - return ( = ({ graphData }) = }) } + + return (
  • diff --git a/frontend/src/setupTests.ts b/frontend/test/setupTests.ts similarity index 100% rename from frontend/src/setupTests.ts rename to frontend/test/setupTests.ts diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 2eec864a..6dcaa194 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -23,5 +23,5 @@ "include": [ "src", "test/App.test.tsx" - ] +, "test/setupTests.ts" ] } \ No newline at end of file