From 09f4fab36899922e3ac856b6744abc02a301abc8 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Wed, 28 Feb 2024 14:09:39 +0100 Subject: [PATCH 01/33] added jpa dependency --- backend/app/build.gradle | 1 + backend/db/password.txt | 0 2 files changed, 1 insertion(+) create mode 100644 backend/db/password.txt diff --git a/backend/app/build.gradle b/backend/app/build.gradle index 700530b7..9d467b8c 100644 --- a/backend/app/build.gradle +++ b/backend/app/build.gradle @@ -33,6 +33,7 @@ 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' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' diff --git a/backend/db/password.txt b/backend/db/password.txt new file mode 100644 index 00000000..e69de29b From c39317fdbc9e12388c6a2bda25a05b65dd703894 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Thu, 29 Feb 2024 09:48:22 +0100 Subject: [PATCH 02/33] start jpa database --- .../ugent/pidgeon/config/JwtAuthenticationFilter.java | 2 +- .../src/main/java/com/ugent/pidgeon/model/Auth.java | 2 +- .../src/main/java/com/ugent/pidgeon/model/User.java | 8 ++++++-- backend/app/src/main/resources/application.properties | 10 ++++++++++ backend/db/password.txt | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java b/backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java index 598d7897..4ef865e3 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/config/JwtAuthenticationFilter.java @@ -67,7 +67,7 @@ protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, //logger.info(jwt.getClaims()); - User user = new User(displayName,firstName,lastName, email, groups, oid); + User user = new User(displayName, firstName,lastName, email, groups, oid); Auth authUser = new Auth(user, new ArrayList<>()); SecurityContextHolder.getContext().setAuthentication(authUser); diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java b/backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java index 9e286d90..492ebe41 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/Auth.java @@ -5,7 +5,7 @@ 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 index 599db7f9..d3c78a02 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/User.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/User.java @@ -1,18 +1,22 @@ -package com.ugent.selab2.model; +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 email, List groups, 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/resources/application.properties b/backend/app/src/main/resources/application.properties index 4d7742de..ce1390e3 100644 --- a/backend/app/src/main/resources/application.properties +++ b/backend/app/src/main/resources/application.properties @@ -1,4 +1,14 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/pidgeon_db +spring.datasource.username=admin +spring.datasource.password=admin +spring.jpa.show-sql=true +## 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 diff --git a/backend/db/password.txt b/backend/db/password.txt index e69de29b..f77b0040 100644 --- a/backend/db/password.txt +++ b/backend/db/password.txt @@ -0,0 +1 @@ +admin \ No newline at end of file From caba523bfac58b6b9d8b91676645d34d12451118 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Thu, 29 Feb 2024 10:51:54 +0100 Subject: [PATCH 03/33] Created entity+repo+route for user ! Nog niet kunnen testen door problemen met connectie databank ! --- .../controllers/JpaUserController.java | 18 +++++++ .../pidgeon/postgre/models/UserEntity.java | 48 +++++++++++++++++++ .../postgre/repository/UserRepository.java | 10 ++++ 3 files changed, 76 insertions(+) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/UserRepository.java 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..4bf0780b --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -0,0 +1,18 @@ +package com.ugent.pidgeon.controllers; + + +import com.ugent.pidgeon.postgre.repository.UserRepository; +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;*/ + + @GetMapping("/api/users") + public String getUsers() { + return "kaas+: "; + } +} 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..bd3251be --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserEntity.java @@ -0,0 +1,48 @@ +package com.ugent.pidgeon.postgre.models; + + +import jakarta.persistence.*; + +@Entity +public class UserEntity { + private long id; + private String name; + private String surname; + private String email; + + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id", nullable = false) + public long getId() { + return id; + } + + @Column(name = "name", nullable=false) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Column(name = "surname", nullable=false) + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + @Column(name = "email", nullable=false) + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} + 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..c686d37a --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/UserRepository.java @@ -0,0 +1,10 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.model.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository { + +} From f900adea43249cf23121a0f2b04a656aa6e1f431 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 29 Feb 2024 11:28:29 +0100 Subject: [PATCH 04/33] Update docker-compose.yaml --- docker-compose.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 56e4273c..8a2c5a4f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -25,6 +25,7 @@ services: secrets: - db-password environment: + - 'POSTGRES_PASSWORD=/run/secrets/db_password' - 'POSTGRES_DB=pidgeon_db' - 'POSTGRES_USER=admin' ports: From 01c309e0ebbadbce2e022a3ac91f83dca29f07ba Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 29 Feb 2024 11:44:01 +0100 Subject: [PATCH 05/33] Create label.yml --- .github/workflows/label.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/label.yml diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml new file mode 100644 index 00000000..46135690 --- /dev/null +++ b/.github/workflows/label.yml @@ -0,0 +1,22 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: [pull_request_target] + +jobs: + label: + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v4 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" From 67c6567cdb9113720fe0fa4770a11a5d1aa6298d Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 29 Feb 2024 13:38:18 +0100 Subject: [PATCH 06/33] testing automated testing --- .github/workflows/docker_test.yml | 14 ++++++++++++++ backend/app/build.gradle | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker_test.yml diff --git a/.github/workflows/docker_test.yml b/.github/workflows/docker_test.yml new file mode 100644 index 00000000..2066d9c0 --- /dev/null +++ b/.github/workflows/docker_test.yml @@ -0,0 +1,14 @@ +name: running test with github actions +on: workflow_dispatch + +jobs: + test: + runs-on: ubuntu-latest + name: run unit tests on java 17 + steps: + - uses: actions/checkout@master + - name: setup java + uses: actions/setup-java@v1 + with: + java-version: 17 + - run: gradle test diff --git a/backend/app/build.gradle b/backend/app/build.gradle index 700530b7..04c8ec16 100644 --- a/backend/app/build.gradle +++ b/backend/app/build.gradle @@ -38,6 +38,11 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' } -tasks.named('test') { +tasks.named('test',Test) { useJUnitPlatform() + maxHeapSize = '1G' + + testLogging { + events "passed" + } } From 22ed6bf28648396ac2c39bc038b75dab10dd9324 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 29 Feb 2024 13:44:43 +0100 Subject: [PATCH 07/33] Create testing.yml --- .github/workflows/testing.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000..2066d9c0 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,14 @@ +name: running test with github actions +on: workflow_dispatch + +jobs: + test: + runs-on: ubuntu-latest + name: run unit tests on java 17 + steps: + - uses: actions/checkout@master + - name: setup java + uses: actions/setup-java@v1 + with: + java-version: 17 + - run: gradle test From 8ce86b2037a38429bcb8a4ac9b664deb481647ae Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 29 Feb 2024 13:50:40 +0100 Subject: [PATCH 08/33] adding correct dir --- .github/workflows/docker_test.yml | 14 -------------- .github/workflows/testing.yml | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 .github/workflows/docker_test.yml diff --git a/.github/workflows/docker_test.yml b/.github/workflows/docker_test.yml deleted file mode 100644 index 2066d9c0..00000000 --- a/.github/workflows/docker_test.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: running test with github actions -on: workflow_dispatch - -jobs: - test: - runs-on: ubuntu-latest - name: run unit tests on java 17 - steps: - - uses: actions/checkout@master - - name: setup java - uses: actions/setup-java@v1 - with: - java-version: 17 - - run: gradle test diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 2066d9c0..20532b65 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -11,4 +11,4 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 - - run: gradle test + - run: gradle test -p backend/app/ From 81deeb8fd2001b295679f49b39245d6755676bf5 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 29 Feb 2024 13:58:37 +0100 Subject: [PATCH 09/33] Update testing.yml --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 20532b65..7f5cac91 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,5 +1,5 @@ name: running test with github actions -on: workflow_dispatch +on: pull_request jobs: test: From 9f971d0a60c3a084639da5c625ec94ec8d7bbb82 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:51:34 +0100 Subject: [PATCH 10/33] fixed some issues with UserEntity&Repo --- .../java/com/ugent/pidgeon/postgre/models/UserEntity.java | 6 +++++- .../ugent/pidgeon/postgre/repository/UserRepository.java | 3 ++- backend/app/src/main/resources/application.properties | 2 +- docker-compose.yaml | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) 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 index bd3251be..a4a77a28 100644 --- 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 @@ -4,13 +4,13 @@ import jakarta.persistence.*; @Entity +@Table(name = "users") public class UserEntity { private long id; private String name; private String surname; private String email; - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id", nullable = false) @@ -18,6 +18,10 @@ public long getId() { return id; } + public void setId(long id) { + this.id = id; + } + @Column(name = "name", nullable=false) public String getName() { return name; 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 index c686d37a..e262c7f3 100644 --- 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 @@ -1,10 +1,11 @@ package com.ugent.pidgeon.postgre.repository; import com.ugent.pidgeon.model.User; +import com.ugent.pidgeon.postgre.models.UserEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { } diff --git a/backend/app/src/main/resources/application.properties b/backend/app/src/main/resources/application.properties index ce1390e3..69c60a6b 100644 --- a/backend/app/src/main/resources/application.properties +++ b/backend/app/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/pidgeon_db spring.datasource.username=admin -spring.datasource.password=admin +spring.datasource.password=root spring.jpa.show-sql=true ## Hibernate Properties diff --git a/docker-compose.yaml b/docker-compose.yaml index 8a2c5a4f..42e9d046 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,7 +15,7 @@ services: ports: - 8080:8080 environment: - - 'POSTGRES_DB=pidegon_db' + - 'POSTGRES_DB=pidgeon_db' networks: - spring-postgres restart: always From 9b8ddbb35163864cba1511cae7b47cc23375f482 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 1 Mar 2024 10:56:51 +0100 Subject: [PATCH 11/33] postgres spring fix --- docker-compose.yaml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 8a2c5a4f..697d077a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,23 +11,28 @@ services: - ./certbot/www/:/var/www/certbot/:ro backend: container_name: spring_container + image: 'docker-spring-boot-postgres:latest' build: backend/app/ + depends_on: + - postgres ports: - 8080:8080 environment: - - 'POSTGRES_DB=pidegon_db' + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/pidgeon + - SPRING_DATASOURCE_USERNAME=pidgeon + - SPRING_DATASOURCE_PASSWORD=admin + - SPRING_JPA_HIBERNATE_DDL_AUTO=update networks: - spring-postgres restart: always postgres: - container_name: pg_container + container_name: db image: 'postgres:latest' secrets: - db-password environment: - - 'POSTGRES_PASSWORD=/run/secrets/db_password' - - 'POSTGRES_DB=pidgeon_db' - - 'POSTGRES_USER=admin' + - 'POSTGRES_PASSWORD=admin' + - 'POSTGRES_USER=pidgeon' ports: - '5432:5432' volumes: From 14799ac703eda77afe2b8e70fa15e4bb781f4985 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:20:22 +0100 Subject: [PATCH 12/33] temp. commented out some not working code --- backend/app/build.gradle | 3 ++- .../pidgeon/controllers/JpaUserController.java | 14 +++++++------- .../app/src/main/resources/application.properties | 7 ++++--- .../com/ugent/pidgeon/PidgeonApplicationTests.java | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/backend/app/build.gradle b/backend/app/build.gradle index fb1a8537..e95a8f82 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' @@ -33,6 +33,7 @@ dependencies { 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' 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 index 4bf0780b..a66b20e2 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -8,11 +8,11 @@ @RestController public class JpaUserController { - /*@Autowired - private UserRepository userRepository;*/ - - @GetMapping("/api/users") - public String getUsers() { - return "kaas+: "; - } +// @Autowired +// private UserRepository userRepository; +// +// @GetMapping("/api/users") +// public String getUsers() { +// return "kaas+: "; +// } } diff --git a/backend/app/src/main/resources/application.properties b/backend/app/src/main/resources/application.properties index 69c60a6b..47e0ead4 100644 --- a/backend/app/src/main/resources/application.properties +++ b/backend/app/src/main/resources/application.properties @@ -1,7 +1,8 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/pidgeon_db -spring.datasource.username=admin -spring.datasource.password=root +spring.datasource.url = jdbc:postgresql://db:5432/pidgeon +spring.datasource.username = pidgeon +spring.datasource.password = admin spring.jpa.show-sql=true +spring.jpa.database=postgresql ## Hibernate Properties # The SQL dialect makes Hibernate generate better SQL for the chosen database 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() { - } + }*/ } From 3f4259530ade78b2ac2599a5c03276ee29e8f7f9 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 1 Mar 2024 15:47:11 +0100 Subject: [PATCH 13/33] ik miss tristan --- .../src/main/resources/application.properties | 6 +++--- docker-compose.yaml | 18 ++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/backend/app/src/main/resources/application.properties b/backend/app/src/main/resources/application.properties index 47e0ead4..a0eade67 100644 --- a/backend/app/src/main/resources/application.properties +++ b/backend/app/src/main/resources/application.properties @@ -1,6 +1,6 @@ -spring.datasource.url = jdbc:postgresql://db:5432/pidgeon -spring.datasource.username = pidgeon -spring.datasource.password = admin +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 diff --git a/docker-compose.yaml b/docker-compose.yaml index 697d077a..ccd4c855 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,28 +11,24 @@ services: - ./certbot/www/:/var/www/certbot/:ro backend: container_name: spring_container - image: 'docker-spring-boot-postgres:latest' build: backend/app/ depends_on: - postgres ports: - 8080:8080 environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/pidgeon - - SPRING_DATASOURCE_USERNAME=pidgeon - - SPRING_DATASOURCE_PASSWORD=admin - - SPRING_JPA_HIBERNATE_DDL_AUTO=update - networks: - - spring-postgres + - SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/admin + - SPRING_DATASOURCE_USERNAME=admin + - SPRING_DATASOURCE_PASSWORD=root restart: always postgres: - container_name: db + container_name: postgres image: 'postgres:latest' secrets: - db-password environment: - - 'POSTGRES_PASSWORD=admin' - - 'POSTGRES_USER=pidgeon' + - 'POSTGRES_PASSWORD=root' + - 'POSTGRES_USER=admin' ports: - '5432:5432' volumes: @@ -58,5 +54,3 @@ volumes: secrets: db-password: file: backend/db/password.txt -networks: - spring-postgres: From 758abe5e59fdb8b8991b4036d24afd6a817d9bec Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 1 Mar 2024 16:08:28 +0100 Subject: [PATCH 14/33] JDBC WERKT --- .../app/src/main/resources/application.properties | 12 ++++++------ docker-compose.yaml | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/app/src/main/resources/application.properties b/backend/app/src/main/resources/application.properties index a0eade67..b622818b 100644 --- a/backend/app/src/main/resources/application.properties +++ b/backend/app/src/main/resources/application.properties @@ -1,9 +1,9 @@ -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 - +#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 diff --git a/docker-compose.yaml b/docker-compose.yaml index ccd4c855..f09124c1 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,16 +13,16 @@ services: container_name: spring_container build: backend/app/ depends_on: - - postgres + - db ports: - 8080:8080 environment: - - SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/admin + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres - SPRING_DATASOURCE_USERNAME=admin - SPRING_DATASOURCE_PASSWORD=root restart: always - postgres: - container_name: postgres + db: + container_name: db image: 'postgres:latest' secrets: - db-password @@ -37,7 +37,7 @@ services: container_name: container-pgadmin image: dpage/pgadmin4 depends_on: - - postgres + - db ports: - "5050:80" environment: From 8ebaf7052381706f1aab289438becf6b3242630b Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:33:09 +0100 Subject: [PATCH 15/33] Added testroute and findUserById query --- .../com/ugent/pidgeon/config/AuthConfig.java | 2 +- .../controllers/AuthTestController.java | 8 +++++++ .../controllers/JpaUserController.java | 22 ++++++++++++------- .../postgre/repository/UserRepository.java | 4 +++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java b/backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java index f0cdbef8..5868e59e 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/config/AuthConfig.java @@ -21,7 +21,7 @@ public FilterRegistrationBean filterRegistrationBean() FilterRegistrationBean filter = new FilterRegistrationBean<>(); filter.setFilter(new JwtAuthenticationFilter(tenantId)); - filter.addUrlPatterns("/api/*"); + filter.addUrlPatterns("/api/ietswatiknietwiltesten"); return filter; } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java index 1ca65bc2..f02cd135 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java @@ -1,18 +1,26 @@ 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) { return auth.getUser(); } + @GetMapping("/api/users") + public String getUsers() { + return "kaas+: " /*+ userRepository.findAll().get(0).getName()*/; + } @GetMapping("/ping") public String ping() { 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 index a66b20e2..7d494b40 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -1,18 +1,24 @@ package com.ugent.pidgeon.controllers; - +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; 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; -// -// @GetMapping("/api/users") -// public String getUsers() { -// return "kaas+: "; -// } + @Autowired + private UserRepository userRepository; + + Logger logger = LoggerFactory.getLogger(JpaUserController.class); + @GetMapping("/api/users2") + public String getUsers() { + logger.info("test"); + userRepository.findAll().forEach(user -> logger.info(user.getName())); + return "kaas+: " + userRepository.findById(2).get(0).getName(); + } } 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 index e262c7f3..70e545fc 100644 --- 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 @@ -5,7 +5,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface UserRepository extends JpaRepository { - + List findById(long id); } From 72402162f1aa3a98efbfeb65ac894b95c800b8b2 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Fri, 1 Mar 2024 22:36:40 +0100 Subject: [PATCH 16/33] trying out the join so we can get all user courses doesn't work that --- .../controllers/JpaUserController.java | 40 +++++++-------- .../pidgeon/postgre/models/CourseEntity.java | 50 +++++++++++++++++++ .../postgre/models/CourseUserEntity.java | 33 ++++++++++++ .../pidgeon/postgre/models/UserEntity.java | 14 ++++++ .../postgre/repository/UserRepository.java | 5 ++ 5 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseUserEntity.java 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 index 7d494b40..b48ad523 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -1,24 +1,24 @@ -package com.ugent.pidgeon.controllers; + package com.ugent.pidgeon.controllers; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.logging.Log; -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; + import org.apache.commons.logging.LogFactory; + import org.apache.commons.logging.Log; + 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; + @RestController + public class JpaUserController { + @Autowired + private UserRepository userRepository; - Logger logger = LoggerFactory.getLogger(JpaUserController.class); - @GetMapping("/api/users2") - public String getUsers() { - logger.info("test"); - userRepository.findAll().forEach(user -> logger.info(user.getName())); - return "kaas+: " + userRepository.findById(2).get(0).getName(); + Logger logger = LoggerFactory.getLogger(JpaUserController.class); + @GetMapping("/api/users2") + public String getUsers() { + logger.info("coursessize: " + userRepository.findById(2).get(0).get); + userRepository.findAll().forEach(user -> user.courses.forEach(course -> logger.info(course.getName()))); + return "kaas+: " + userRepository.findById(2).get(0).getName(); + } } -} 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..85f30dd2 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -0,0 +1,50 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +import java.util.HashSet; +import java.util.Set; + + +@Entity +@Table(name = "courses") +public class CourseEntity { + private long id; + private String name; + private String description; + + @ManyToMany(mappedBy = "users") + private Set users = new HashSet<>(); + + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "course_id", nullable = false) + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Column(name = "course_name", nullable=false) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Column(name = "description", nullable=false) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + +} 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..567c65fb --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseUserEntity.java @@ -0,0 +1,33 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@Entity +@Table(name="course_users") +public class CourseUserEntity { + private long course_id; + private long user_id; + + @Id + @Column(name="course_id", nullable=false) + public long getCourse_id() { + return course_id; + } + + public void setCourse_id(long course_id) { + this.course_id = course_id; + } + + @Id + @Column(name="user_id", nullable=false) + public long getUser_id() { + return user_id; + } + + public void setUser_id(long user_id) { + this.user_id = user_id; + } +} 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 index a4a77a28..d97e0603 100644 --- 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 @@ -3,6 +3,10 @@ import jakarta.persistence.*; +import java.util.HashSet; +import java.util.Set; +import com.ugent.pidgeon.postgre.models.CourseEntity; + @Entity @Table(name = "users") public class UserEntity { @@ -11,6 +15,14 @@ public class UserEntity { private String surname; private String email; + @ManyToMany + @JoinTable( + name = "course_users", + joinColumns = @JoinColumn(name = "user_id"), + inverseJoinColumns = @JoinColumn(name = "course_id") + ) + private Set courses = new HashSet<>(); + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id", nullable = false) @@ -48,5 +60,7 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } + + } 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 index 70e545fc..ee6e003a 100644 --- 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 @@ -1,8 +1,11 @@ package com.ugent.pidgeon.postgre.repository; import com.ugent.pidgeon.model.User; +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 org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -10,4 +13,6 @@ @Repository public interface UserRepository extends JpaRepository { List findById(long id); + + } From a8810ed058dd5019cc0a8336507a02cf48ea0ebd Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:20:33 +0100 Subject: [PATCH 17/33] Added @Query for findCoursesByUserId --- .../ugent/pidgeon/controllers/JpaUserController.java | 9 ++++----- .../ugent/pidgeon/postgre/models/CourseEntity.java | 10 +++++++--- .../pidgeon/postgre/models/CourseUserEntity.java | 7 +++---- .../com/ugent/pidgeon/postgre/models/UserEntity.java | 11 +---------- .../pidgeon/postgre/repository/UserRepository.java | 3 ++- 5 files changed, 17 insertions(+), 23 deletions(-) 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 index b48ad523..3a498cb0 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -1,7 +1,6 @@ package com.ugent.pidgeon.controllers; - import org.apache.commons.logging.LogFactory; - import org.apache.commons.logging.Log; + import com.ugent.pidgeon.postgre.models.UserEntity; import com.ugent.pidgeon.postgre.repository.UserRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +16,8 @@ public class JpaUserController { Logger logger = LoggerFactory.getLogger(JpaUserController.class); @GetMapping("/api/users2") public String getUsers() { - logger.info("coursessize: " + userRepository.findById(2).get(0).get); - userRepository.findAll().forEach(user -> user.courses.forEach(course -> logger.info(course.getName()))); - return "kaas+: " + userRepository.findById(2).get(0).getName(); + UserEntity user = userRepository.findById(2).get(0); + userRepository.findCoursesByUserId(user.getId()).forEach(course -> logger.info(course.getName())); + return "kaas+: " + user.getName(); } } 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 index 85f30dd2..a00ac49b 100644 --- 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 @@ -13,9 +13,13 @@ public class CourseEntity { private String name; private String description; - @ManyToMany(mappedBy = "users") - private Set users = new HashSet<>(); - + @OneToMany + @JoinTable( + name = "course_users", + joinColumns = @JoinColumn(name = "course_id"), + inverseJoinColumns = @JoinColumn(name = "user_id") + ) + private Set courseusers = new HashSet<>(); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) 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 index 567c65fb..37d11740 100644 --- 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 @@ -1,9 +1,6 @@ package com.ugent.pidgeon.postgre.models; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; @Entity @Table(name="course_users") @@ -17,6 +14,7 @@ public long getCourse_id() { return course_id; } + public void setCourse_id(long course_id) { this.course_id = course_id; } @@ -30,4 +28,5 @@ public long getUser_id() { public void setUser_id(long user_id) { this.user_id = user_id; } + } 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 index d97e0603..745aa217 100644 --- 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 @@ -5,7 +5,6 @@ import java.util.HashSet; import java.util.Set; -import com.ugent.pidgeon.postgre.models.CourseEntity; @Entity @Table(name = "users") @@ -15,13 +14,7 @@ public class UserEntity { private String surname; private String email; - @ManyToMany - @JoinTable( - name = "course_users", - joinColumns = @JoinColumn(name = "user_id"), - inverseJoinColumns = @JoinColumn(name = "course_id") - ) - private Set courses = new HashSet<>(); + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -60,7 +53,5 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } - - } 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 index ee6e003a..22079ef7 100644 --- 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 @@ -14,5 +14,6 @@ public interface UserRepository extends JpaRepository { List findById(long id); - + @Query(value = "SELECT c FROM CourseEntity c JOIN CourseUserEntity cu ON c.id = cu.course_id WHERE cu.user_id = ?1") + List findCoursesByUserId(long id); } From db621cea0c66672afccd6aba3364509f8733afe7 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:47:33 +0100 Subject: [PATCH 18/33] Added course: controller+repo --- .../controllers/AuthTestController.java | 4 --- .../controllers/JpaCourseController.java | 31 +++++++++++++++++++ .../controllers/JpaUserController.java | 16 +++++++--- .../postgre/repository/CourseRepository.java | 15 +++++++++ .../postgre/repository/UserRepository.java | 2 +- 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/CourseRepository.java diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java index f02cd135..95536323 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/AuthTestController.java @@ -17,10 +17,6 @@ public User testApi(HttpServletRequest request, Auth auth) { return auth.getUser(); } - @GetMapping("/api/users") - public String getUsers() { - return "kaas+: " /*+ userRepository.findAll().get(0).getName()*/; - } @GetMapping("/ping") public String ping() { 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..d7688d66 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -0,0 +1,31 @@ +package com.ugent.pidgeon.controllers; + +import com.ugent.pidgeon.postgre.models.CourseEntity; +import com.ugent.pidgeon.postgre.models.UserEntity; +import com.ugent.pidgeon.postgre.repository.CourseRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class JpaCourseController { + @Autowired + private CourseRepository courseRepository; + + @GetMapping("/api/courses") + public String getCourses() { + StringBuilder res = new StringBuilder(); + for (CourseEntity course : courseRepository.findAll()) { + res.append(course.getName()).append(" with users: "); + for (UserEntity user : courseRepository.findUsersByCourseId(course.getId())) { + res.append(user.getName()).append(", "); + } + res.append("\n"); + } + + return res.toString(); + } + + +} 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 index 3a498cb0..721f09e6 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -1,5 +1,6 @@ package com.ugent.pidgeon.controllers; + import com.ugent.pidgeon.postgre.models.CourseEntity; import com.ugent.pidgeon.postgre.models.UserEntity; import com.ugent.pidgeon.postgre.repository.UserRepository; import org.slf4j.Logger; @@ -14,10 +15,17 @@ public class JpaUserController { private UserRepository userRepository; Logger logger = LoggerFactory.getLogger(JpaUserController.class); - @GetMapping("/api/users2") + @GetMapping("/api/users") public String getUsers() { - UserEntity user = userRepository.findById(2).get(0); - userRepository.findCoursesByUserId(user.getId()).forEach(course -> logger.info(course.getName())); - return "kaas+: " + user.getName(); + StringBuilder res = new StringBuilder(); + for (UserEntity user : userRepository.findAll()) { + res.append(user.getName()).append(" in courses: "); + for (CourseEntity course : userRepository.findCoursesByUserId(user.getId())) { + res.append(course.getName()).append(", "); + } + res.append("\n"); + } + + return res.toString(); } } 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..9cd2d0b5 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/CourseRepository.java @@ -0,0 +1,15 @@ +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 { + CourseEntity findById(long id); + + @Query(value = "SELECT u FROM UserEntity u JOIN CourseUserEntity cu ON u.id = cu.user_id WHERE cu.course_id = ?1") + List findUsersByCourseId(long id); +} 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 index 22079ef7..77278fe9 100644 --- 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 @@ -12,7 +12,7 @@ @Repository public interface UserRepository extends JpaRepository { - List findById(long id); + UserEntity findById(long id); @Query(value = "SELECT c FROM CourseEntity c JOIN CourseUserEntity cu ON c.id = cu.course_id WHERE cu.user_id = ?1") List findCoursesByUserId(long id); From 02892f41ca5f1efa257ca7f30f9925ad5bf77fbf Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:09:05 +0100 Subject: [PATCH 19/33] Added create/update for course uses GET mapping because there are some crsf issues with POST --- .../pidgeon/controllers/JpaCourseController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 index d7688d66..85798359 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -4,9 +4,7 @@ import com.ugent.pidgeon.postgre.models.UserEntity; import com.ugent.pidgeon.postgre.repository.CourseRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController public class JpaCourseController { @@ -27,5 +25,13 @@ public String getCourses() { return res.toString(); } - + @GetMapping("/api/course") + public String addCourse(String name, String description) { + CourseEntity course = new CourseEntity(); + course.setId(1); + course.setName("Test"); + course.setDescription("Added for testing update purposes"); + courseRepository.save(course); + return "Course added"; + } } From a377eb3ef946f3f391d0540e71fa3e849dac1a0b Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 13:02:06 +0100 Subject: [PATCH 20/33] Added role to UserEntity --- .../controllers/JpaUserController.java | 2 +- .../pidgeon/postgre/models/CourseEntity.java | 21 +++++++-------- .../pidgeon/postgre/models/UserEntity.java | 26 ++++++++++++++----- .../pidgeon/postgre/models/UserRole.java | 7 +++++ 4 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java 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 index 721f09e6..fdc33819 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -19,7 +19,7 @@ public class JpaUserController { public String getUsers() { StringBuilder res = new StringBuilder(); for (UserEntity user : userRepository.findAll()) { - res.append(user.getName()).append(" in courses: "); + res.append(user.getName()).append("(").append(user.getRole().toString()).append(") in courses: "); for (CourseEntity course : userRepository.findCoursesByUserId(user.getId())) { res.append(course.getName()).append(", "); } 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 index a00ac49b..008060e4 100644 --- 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 @@ -9,21 +9,18 @@ @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; - @OneToMany - @JoinTable( - name = "course_users", - joinColumns = @JoinColumn(name = "course_id"), - inverseJoinColumns = @JoinColumn(name = "user_id") - ) - private Set courseusers = new HashSet<>(); - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "course_id", nullable = false) + public long getId() { return id; } @@ -32,7 +29,7 @@ public void setId(long id) { this.id = id; } - @Column(name = "course_name", nullable=false) + public String getName() { return name; } @@ -41,7 +38,7 @@ public void setName(String name) { this.name = name; } - @Column(name = "description", nullable=false) + public String getDescription() { return description; } 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 index 745aa217..b7c46f7a 100644 --- 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 @@ -9,16 +9,26 @@ @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; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "user_id", nullable = false) public long getId() { return id; } @@ -27,7 +37,7 @@ public void setId(long id) { this.id = id; } - @Column(name = "name", nullable=false) + public String getName() { return name; } @@ -36,7 +46,7 @@ public void setName(String name) { this.name = name; } - @Column(name = "surname", nullable=false) + public String getSurname() { return surname; } @@ -45,7 +55,7 @@ public void setSurname(String surname) { this.surname = surname; } - @Column(name = "email", nullable=false) + public String getEmail() { return email; } @@ -53,5 +63,9 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } + + public UserRole getRole() { + return role; + } } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java new file mode 100644 index 00000000..a27cfd40 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java @@ -0,0 +1,7 @@ +package com.ugent.pidgeon.postgre.models; + +public enum UserRole { + student, + admin, + teacher +} From d1ae49990b97dcd02f0e35bb1796424c21a73ad0 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 14:48:28 +0100 Subject: [PATCH 21/33] Added courserelation --- .../pidgeon/controllers/JpaCourseController.java | 6 ++++-- .../pidgeon/controllers/JpaUserController.java | 8 ++++++-- .../pidgeon/postgre/models/CourseRelation.java | 7 +++++++ .../pidgeon/postgre/models/CourseUserEntity.java | 16 ++++++++++++---- .../postgre/repository/CourseRepository.java | 12 ++++++++++-- .../postgre/repository/UserRepository.java | 15 +++++++++++++-- 6 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseRelation.java 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 index 85798359..4b97c3a0 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -16,8 +16,10 @@ public String getCourses() { StringBuilder res = new StringBuilder(); for (CourseEntity course : courseRepository.findAll()) { res.append(course.getName()).append(" with users: "); - for (UserEntity user : courseRepository.findUsersByCourseId(course.getId())) { - res.append(user.getName()).append(", "); + 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("\n"); } 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 index fdc33819..97c494c8 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -1,11 +1,13 @@ package com.ugent.pidgeon.controllers; import com.ugent.pidgeon.postgre.models.CourseEntity; + import com.ugent.pidgeon.postgre.models.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.data.util.Pair; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -20,8 +22,10 @@ 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 (CourseEntity course : userRepository.findCoursesByUserId(user.getId())) { - res.append(course.getName()).append(", "); + 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"); } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseRelation.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseRelation.java new file mode 100644 index 00000000..fd58b851 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseRelation.java @@ -0,0 +1,7 @@ +package com.ugent.pidgeon.postgre.models; + +public enum CourseRelation { + creator, + course_admin, + enrolled +} 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 index 37d11740..fcdfcb2e 100644 --- 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 @@ -5,11 +5,20 @@ @Entity @Table(name="course_users") public class CourseUserEntity { - private long course_id; - private long user_id; @Id @Column(name="course_id", nullable=false) + private long course_id; + + @Id + @Column(name="user_id", nullable=false) + private long user_id; + + @Column(name = "course_relation") + @Enumerated(EnumType.STRING) + private CourseRelation relation; + + public long getCourse_id() { return course_id; } @@ -19,8 +28,7 @@ public void setCourse_id(long course_id) { this.course_id = course_id; } - @Id - @Column(name="user_id", nullable=false) + public long getUser_id() { return user_id; } 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 index 9cd2d0b5..0dd5b89c 100644 --- 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 @@ -8,8 +8,16 @@ import java.util.List; public interface CourseRepository extends JpaRepository { + CourseEntity findById(long id); - @Query(value = "SELECT u FROM UserEntity u JOIN CourseUserEntity cu ON u.id = cu.user_id WHERE cu.course_id = ?1") - List findUsersByCourseId(long id); + + 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.user_id WHERE cu.course_id = ?1") + List findUsersByCourseId(long id); } 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 index 77278fe9..0e0b9b11 100644 --- 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 @@ -2,18 +2,29 @@ import com.ugent.pidgeon.model.User; import com.ugent.pidgeon.postgre.models.CourseEntity; +import com.ugent.pidgeon.postgre.models.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.data.repository.query.Param; +import org.springframework.data.util.Pair; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface UserRepository extends JpaRepository { + + UserEntity findById(long id); - @Query(value = "SELECT c FROM CourseEntity c JOIN CourseUserEntity cu ON c.id = cu.course_id WHERE cu.user_id = ?1") - List findCoursesByUserId(long id); + + 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.course_id WHERE cu.user_id = ?1") + List findCoursesByUserId(long id); } From 3d12e86d92d2478d85b38af2b2ab04d02ea27e26 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:20:43 +0100 Subject: [PATCH 22/33] Added group-related entities --- .../postgre/models/GroupClusterEntity.java | 66 +++++++++++++++++++ .../pidgeon/postgre/models/GroupEntity.java | 43 ++++++++++++ .../postgre/models/GroupUserEntity.java | 34 ++++++++++ 3 files changed, 143 insertions(+) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupClusterEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupUserEntity.java 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..7c94f7c2 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupClusterEntity.java @@ -0,0 +1,66 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +@Entity +@Table(name="group_clusters") +public class GroupClusterEntity { + + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="group_cluster_id", nullable=false) + private int id; + + @Column(name="course_id", nullable=false) + private int course_id; + + @Column(name="max_size", nullable=false) + private int max_size; + + @Column(name="cluster_name", nullable=false) + private String cluster_name; + + @Column(name="group_amount", nullable=false) + private int group_amount; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getCourse_id() { + return course_id; + } + + public void setCourse_id(int course_id) { + this.course_id = course_id; + } + + public int getMax_size() { + return max_size; + } + + public void setMax_size(int max_size) { + this.max_size = max_size; + } + + public String getCluster_name() { + return cluster_name; + } + + public void setCluster_name(String cluster_name) { + this.cluster_name = cluster_name; + } + + public int getGroup_amount() { + return group_amount; + } + + public void setGroup_amount(int group_amount) { + this.group_amount = group_amount; + } +} 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..65e6c2d0 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupEntity.java @@ -0,0 +1,43 @@ +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 int cluster; + + 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 int getCluster() { + return cluster; + } + + public void setCluster(int cluster) { + this.cluster = cluster; + } +} 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..f48358c4 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupUserEntity.java @@ -0,0 +1,34 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@Entity +@Table(name="group_users") +public class GroupUserEntity { + @Id + @Column(name="group_id", nullable=false) + private long group_id; + + @Id + @Column(name="user_id", nullable=false) + private long user_id; + + public long getGroup_id() { + return group_id; + } + + public void setGroup_id(long group_id) { + this.group_id = group_id; + } + + public long getUser_id() { + return user_id; + } + + public void setUser_id(long user_id) { + this.user_id = user_id; + } +} From 08caa4eb7138be087072b25405fd2879d888b5c9 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:08:19 +0100 Subject: [PATCH 23/33] refactering names + group/groupcluster repo --- .../controllers/JpaCourseController.java | 9 +++++ .../controllers/JpaGroupController.java | 31 ++++++++++++++ .../postgre/models/CourseUserEntity.java | 23 +++++------ .../postgre/models/GroupClusterEntity.java | 40 +++++++++---------- .../postgre/models/GroupUserEntity.java | 20 +++++----- .../postgre/repository/CourseRepository.java | 2 +- .../repository/GroupClusterRepository.java | 10 +++++ .../postgre/repository/GroupRepository.java | 15 +++++++ .../postgre/repository/UserRepository.java | 2 +- 9 files changed, 107 insertions(+), 45 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupClusterRepository.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupRepository.java 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 index 4b97c3a0..519c5c28 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -1,8 +1,10 @@ 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.UserEntity; import com.ugent.pidgeon.postgre.repository.CourseRepository; +import com.ugent.pidgeon.postgre.repository.GroupClusterRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -11,6 +13,9 @@ public class JpaCourseController { @Autowired private CourseRepository courseRepository; + @Autowired + private GroupClusterRepository groupClusterRepository; + @GetMapping("/api/courses") public String getCourses() { StringBuilder res = new StringBuilder(); @@ -21,6 +26,10 @@ public String getCourses() { String relation = user.getRelation(); res.append(userEntity.getName()).append("(").append(relation).append("), "); } + res.append(" with group cluster"); + for (GroupClusterEntity groupcluster: groupClusterRepository.findByCourseId((int) course.getId())) { + res.append(groupcluster.getName()).append(" (").append(groupcluster.getGroupAmount()).append("), "); + } res.append("\n"); } 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..6952a53b --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java @@ -0,0 +1,31 @@ +package com.ugent.pidgeon.controllers; + +import com.ugent.pidgeon.postgre.models.GroupEntity; +import com.ugent.pidgeon.postgre.models.UserEntity; +import com.ugent.pidgeon.postgre.repository.GroupRepository; +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; + + @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(", "); + } + res.add(groupString.toString()); + } + return res; + } +} 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 index fcdfcb2e..79566b0c 100644 --- 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 @@ -8,33 +8,30 @@ public class CourseUserEntity { @Id @Column(name="course_id", nullable=false) - private long course_id; + private long courseId; @Id @Column(name="user_id", nullable=false) - private long user_id; + private long userId; @Column(name = "course_relation") @Enumerated(EnumType.STRING) private CourseRelation relation; - public long getCourse_id() { - return course_id; + public long getCourseId() { + return courseId; } - - public void setCourse_id(long course_id) { - this.course_id = course_id; + public void setCourseId(long courseId) { + this.courseId = courseId; } - - public long getUser_id() { - return user_id; + public long getUserId() { + return userId; } - public void setUser_id(long user_id) { - this.user_id = user_id; + public void setUserId(long userId) { + this.userId = userId; } - } 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 index 7c94f7c2..342668e7 100644 --- 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 @@ -13,16 +13,16 @@ public class GroupClusterEntity { private int id; @Column(name="course_id", nullable=false) - private int course_id; + private int courseId; @Column(name="max_size", nullable=false) - private int max_size; + private int maxSize; @Column(name="cluster_name", nullable=false) - private String cluster_name; + private String name; @Column(name="group_amount", nullable=false) - private int group_amount; + private int groupAmount; public int getId() { return id; @@ -32,35 +32,35 @@ public void setId(int id) { this.id = id; } - public int getCourse_id() { - return course_id; + public int getCourseId() { + return courseId; } - public void setCourse_id(int course_id) { - this.course_id = course_id; + public void setCourseId(int course_id) { + this.courseId = course_id; } - public int getMax_size() { - return max_size; + public int getMaxSize() { + return maxSize; } - public void setMax_size(int max_size) { - this.max_size = max_size; + public void setMaxSize(int max_size) { + this.maxSize = max_size; } - public String getCluster_name() { - return cluster_name; + public String getName() { + return name; } - public void setCluster_name(String cluster_name) { - this.cluster_name = cluster_name; + public void setName(String cluster_name) { + this.name = cluster_name; } - public int getGroup_amount() { - return group_amount; + public int getGroupAmount() { + return groupAmount; } - public void setGroup_amount(int group_amount) { - this.group_amount = group_amount; + public void setGroupAmount(int group_amount) { + this.groupAmount = group_amount; } } 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 index f48358c4..1b4d8b6d 100644 --- 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 @@ -10,25 +10,25 @@ public class GroupUserEntity { @Id @Column(name="group_id", nullable=false) - private long group_id; + private long groupId; @Id @Column(name="user_id", nullable=false) - private long user_id; + private long userId; - public long getGroup_id() { - return group_id; + public long getGroupId() { + return groupId; } - public void setGroup_id(long group_id) { - this.group_id = group_id; + public void setGroupId(long group_id) { + this.groupId = group_id; } - public long getUser_id() { - return user_id; + public long getUserId() { + return userId; } - public void setUser_id(long user_id) { - this.user_id = user_id; + public void setUserId(long user_id) { + this.userId = user_id; } } 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 index 0dd5b89c..fdf7ffac 100644 --- 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 @@ -18,6 +18,6 @@ public interface UserWithRelation { } /* 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.user_id WHERE cu.course_id = ?1") + @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/GroupClusterRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupClusterRepository.java new file mode 100644 index 00000000..bb82247b --- /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(int courseId); +} 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..0712162e --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupRepository.java @@ -0,0 +1,15 @@ +package com.ugent.pidgeon.postgre.repository; + +import com.ugent.pidgeon.postgre.models.GroupEntity; +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{ + GroupEntity findById(long id); + + @Query(value= "SELECT u FROM UserEntity u JOIN GroupUserEntity gu ON u.id = gu.userId WHERE gu.groupId = ?1") + List findCourseUsersByGroupId(long id); +} 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 index 0e0b9b11..615a7b1e 100644 --- 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 @@ -25,6 +25,6 @@ public interface CourseWithRelation { } /* 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.course_id WHERE cu.user_id = ?1") + @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); } From f72c4aa42d64dacd67673b76a556904a53ab910f Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 10:35:34 +0100 Subject: [PATCH 24/33] Added projectEntity --- .../controllers/JpaCourseController.java | 15 +++- .../postgre/models/GroupClusterEntity.java | 12 +-- .../pidgeon/postgre/models/GroupEntity.java | 10 +-- .../pidgeon/postgre/models/ProjectEntity.java | 88 +++++++++++++++++++ .../repository/GroupClusterRepository.java | 2 +- .../postgre/repository/ProjectRepository.java | 10 +++ 6 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/ProjectRepository.java 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 index 519c5c28..276040d8 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -2,9 +2,11 @@ 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.*; @@ -16,6 +18,9 @@ public class JpaCourseController { @Autowired private GroupClusterRepository groupClusterRepository; + @Autowired + private ProjectRepository projectRepository; + @GetMapping("/api/courses") public String getCourses() { StringBuilder res = new StringBuilder(); @@ -26,11 +31,15 @@ public String getCourses() { String relation = user.getRelation(); res.append(userEntity.getName()).append("(").append(relation).append("), "); } - res.append(" with group cluster"); - for (GroupClusterEntity groupcluster: groupClusterRepository.findByCourseId((int) course.getId())) { + res.append("- with group clusters:"); + for (GroupClusterEntity groupcluster: groupClusterRepository.findByCourseId(course.getId())) { res.append(groupcluster.getName()).append(" (").append(groupcluster.getGroupAmount()).append("), "); } - res.append("\n"); + res.append("- with projects:"); + for (ProjectEntity project: projectRepository.findByCourseId(course.getId())) { + res.append(project.getName()).append(", "); + } + res.append("|\n"); } return res.toString(); 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 index 342668e7..0027d96a 100644 --- 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 @@ -10,10 +10,10 @@ public class GroupClusterEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="group_cluster_id", nullable=false) - private int id; + private long id; @Column(name="course_id", nullable=false) - private int courseId; + private long courseId; @Column(name="max_size", nullable=false) private int maxSize; @@ -24,19 +24,19 @@ public class GroupClusterEntity { @Column(name="group_amount", nullable=false) private int groupAmount; - public int getId() { + public long getId() { return id; } - public void setId(int id) { + public void setId(long id) { this.id = id; } - public int getCourseId() { + public long getCourseId() { return courseId; } - public void setCourseId(int course_id) { + public void setCourseId(long course_id) { this.courseId = course_id; } 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 index 65e6c2d0..ac15bf7f 100644 --- 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 @@ -15,7 +15,7 @@ public class GroupEntity { private String name; @Column(name="group_cluster", nullable = false) - private int cluster; + private long clusterId; public long getId() { return id; @@ -33,11 +33,11 @@ public void setName(String name) { this.name = name; } - public int getCluster() { - return cluster; + public long getClusterId() { + return clusterId; } - public void setCluster(int cluster) { - this.cluster = cluster; + public void setClusterId(int cluster) { + this.clusterId = cluster; } } 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..a87e2642 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java @@ -0,0 +1,88 @@ +package com.ugent.pidgeon.postgre.models; + +import jakarta.persistence.*; + +@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; + + + 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; + } +} 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 index bb82247b..45d3b320 100644 --- 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 @@ -6,5 +6,5 @@ import java.util.List; public interface GroupClusterRepository extends JpaRepository { - List findByCourseId(int courseId); + List findByCourseId(long courseId); } 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); +} From 06b053cc142a01acb411af9907e53b00b51bcdca Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:00:58 +0100 Subject: [PATCH 25/33] Added GroupFeedbackEntity + missing project fields --- .../controllers/JpaGroupController.java | 13 +++- .../pidgeon/postgre/models/FileEntity.java | 4 ++ .../postgre/models/GroupFeedbackEntity.java | 62 +++++++++++++++++++ .../pidgeon/postgre/models/ProjectEntity.java | 16 +++++ .../repository/GroupFeedbackRepository.java | 8 +++ .../postgre/repository/GroupRepository.java | 9 +++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/FileEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupFeedbackEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupFeedbackRepository.java 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 index 6952a53b..7a908d5b 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java @@ -1,7 +1,9 @@ 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.UserEntity; +import com.ugent.pidgeon.postgre.repository.GroupFeedbackRepository; import com.ugent.pidgeon.postgre.repository.GroupRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -12,18 +14,27 @@ @RestController public class JpaGroupController { + @Autowired private GroupRepository groupRepository; + @Autowired + private GroupFeedbackRepository groupFeedbackRepository; + @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: "); + groupString.append(group.getName()).append("-with users: "); for (UserEntity user : groupRepository.findCourseUsersByGroupId(group.getId())) { groupString.append(user.getName()).append(", "); } + groupString.append("-with grades: "); + for (long projectId: groupRepository.findProjectsByGroupId(group.getId())) { + GroupFeedbackEntity feedback = groupFeedbackRepository.findByGroupIdAndProjectId(group.getId(), projectId); + groupString.append(feedback.getGrade()).append(", "); + } res.add(groupString.toString()); } return res; 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..65597385 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/FileEntity.java @@ -0,0 +1,4 @@ +package com.ugent.pidgeon.postgre.models; + +public class FileEntity { +} 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..bf10ecaa --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupFeedbackEntity.java @@ -0,0 +1,62 @@ +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 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/ProjectEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java index a87e2642..fd14afbe 100644 --- 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 @@ -1,6 +1,8 @@ package com.ugent.pidgeon.postgre.models; import jakarta.persistence.*; +import java.sql.Timestamp; + @Entity @Table(name = "projects") @@ -29,6 +31,12 @@ public class ProjectEntity { @Column(name="visible", nullable = false) private Boolean projectType; + @Column(name="deadline", nullable = false) + private Timestamp deadline; + + @Column(name="max_score") + private Integer maxScore; + public long getId() { return id; @@ -85,4 +93,12 @@ public Boolean getProjectType() { public void setProjectType(Boolean projectType) { this.projectType = projectType; } + + 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/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 index 0712162e..a2fb8e4e 100644 --- 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 @@ -1,6 +1,7 @@ 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; @@ -12,4 +13,12 @@ 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); } From 108c2e266b17de602eba5c534eff94cdcd21a5ea Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:12:58 +0100 Subject: [PATCH 26/33] fixed pk for [Course|Group]UserEntity (pk = primary key) --- .../pidgeon/postgre/models/CourseUserEntity.java | 8 ++++++++ .../pidgeon/postgre/models/GroupUserEntity.java | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) 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 index 79566b0c..84fe5e6c 100644 --- 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 @@ -2,7 +2,10 @@ import jakarta.persistence.*; +import java.io.Serializable; + @Entity +@IdClass(CourseUserId.class) @Table(name="course_users") public class CourseUserEntity { @@ -35,3 +38,8 @@ public void setUserId(long userId) { this.userId = userId; } } + +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/GroupUserEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/GroupUserEntity.java index 1b4d8b6d..bff40866 100644 --- 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 @@ -1,11 +1,11 @@ package com.ugent.pidgeon.postgre.models; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; + +import java.io.Serializable; @Entity +@IdClass(GroupUserId.class) @Table(name="group_users") public class GroupUserEntity { @Id @@ -32,3 +32,8 @@ 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 From 4801bf35587554a43382da3c7f939e0bd797b004 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Sun, 3 Mar 2024 12:26:00 +0100 Subject: [PATCH 27/33] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 80c68613..eb843e8c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ # UGent-6 - -WIP (ik ga korte uitleg schrijven hoe je dit lokaal kan opzetten) -# dependencies -docker compose +https://github.com/SELab-2/UGent-6/wiki From d09d743f8aae80e5fd595616a838e79b6cf11c03 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:28:35 +0100 Subject: [PATCH 28/33] Added submissionEntity --- .../controllers/JpaGroupController.java | 15 ++++- .../postgre/models/SubmissionEntity.java | 58 +++++++++++++++++++ .../repository/SubmissionRepository.java | 10 ++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/SubmissionEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/SubmissionRepository.java 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 index 7a908d5b..b3845a87 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaGroupController.java @@ -2,9 +2,11 @@ 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; @@ -21,6 +23,9 @@ public class JpaGroupController { @Autowired private GroupFeedbackRepository groupFeedbackRepository; + @Autowired + SubmissionRepository submissionRepository; + @GetMapping("/api/groups") public List getGroups() { List res = new ArrayList<>(); @@ -30,11 +35,19 @@ public List getGroups() { 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: groupRepository.findProjectsByGroupId(group.getId())) { + 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/postgre/models/SubmissionEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/SubmissionEntity.java new file mode 100644 index 00000000..b6a0abce --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/SubmissionEntity.java @@ -0,0 +1,58 @@ +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 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; + } +} 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); +} From 4bf162dfc4150e4281415f83b988b9da99d09240 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 13:18:57 +0100 Subject: [PATCH 29/33] Added testEntity --- .../controllers/JpaProjectController.java | 34 +++++++++++++++++ .../pidgeon/postgre/models/TestEntity.java | 37 +++++++++++++++++++ .../postgre/repository/TestRepository.java | 8 ++++ 3 files changed, 79 insertions(+) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/TestEntity.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/TestRepository.java 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..84835345 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java @@ -0,0 +1,34 @@ +package com.ugent.pidgeon.controllers; + +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; + +@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()); + TestEntity test = testRepository.findById(project.getId()); + projectString.append(" with test: ").append(test.getId()); + + res.add(projectString.toString()); + } + return res; + } +} 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..394903a2 --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/TestEntity.java @@ -0,0 +1,37 @@ +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 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; + } +} 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..b32403ef --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/TestRepository.java @@ -0,0 +1,8 @@ +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 { + TestEntity findById(long id); +} From 18eb5d5f4e0d4bbb98447db17b3a706dc151d084 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 13:30:07 +0100 Subject: [PATCH 30/33] Removed non-optionale findBy's + create FileEntity --- .../controllers/JpaProjectController.java | 5 +- .../controllers/JpaSubmissionController.java | 38 ++++++++++++++ .../pidgeon/postgre/models/FileEntity.java | 50 +++++++++++++++++++ .../postgre/repository/CourseRepository.java | 1 - .../postgre/repository/FileRepository.java | 7 +++ .../postgre/repository/GroupRepository.java | 1 - .../postgre/repository/TestRepository.java | 1 - .../postgre/repository/UserRepository.java | 3 -- 8 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaSubmissionController.java create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/FileRepository.java 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 index 84835345..bcee992b 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; @RestController public class JpaProjectController { @@ -24,8 +25,8 @@ public List getProjects() { List res = new ArrayList<>(); for (ProjectEntity project : projectRepository.findAll()) { StringBuilder projectString = new StringBuilder(project.getName()); - TestEntity test = testRepository.findById(project.getId()); - projectString.append(" with test: ").append(test.getId()); + Optional test = testRepository.findById(project.getId()); + test.ifPresent(testEntity -> projectString.append(" with test: ").append(testEntity.getId())); res.add(projectString.toString()); } 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/postgre/models/FileEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/FileEntity.java index 65597385..3b16d1e2 100644 --- 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 @@ -1,4 +1,54 @@ 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 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/repository/CourseRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/CourseRepository.java index fdf7ffac..cf5fdeae 100644 --- 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 @@ -9,7 +9,6 @@ public interface CourseRepository extends JpaRepository { - CourseEntity findById(long id); public interface UserWithRelation { 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/GroupRepository.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/repository/GroupRepository.java index a2fb8e4e..95c3cfb2 100644 --- 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 @@ -9,7 +9,6 @@ import java.util.List; public interface GroupRepository extends JpaRepository{ - GroupEntity findById(long id); @Query(value= "SELECT u FROM UserEntity u JOIN GroupUserEntity gu ON u.id = gu.userId WHERE gu.groupId = ?1") List findCourseUsersByGroupId(long id); 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 index b32403ef..cfa9cd32 100644 --- 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 @@ -4,5 +4,4 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface TestRepository extends JpaRepository { - TestEntity findById(long id); } 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 index 615a7b1e..aa1f14d6 100644 --- 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 @@ -16,9 +16,6 @@ public interface UserRepository extends JpaRepository { - UserEntity findById(long id); - - public interface CourseWithRelation { CourseEntity getCourse(); CourseRelation getRelation(); From 23e3e2e723a4ce80083f1a712af116c066b18dbb Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 13:50:04 +0100 Subject: [PATCH 31/33] Added missing getters/setters/fields --- .../controllers/JpaUserController.java | 3 +-- .../pidgeon/postgre/models/CourseEntity.java | 11 ++++++++ .../postgre/models/CourseUserEntity.java | 9 +++++++ .../postgre/models/GroupClusterEntity.java | 13 ++++++++++ .../pidgeon/postgre/models/ProjectEntity.java | 8 ++++++ .../postgre/models/SubmissionEntity.java | 16 ++++++++++++ .../pidgeon/postgre/models/TestEntity.java | 8 ++++++ .../pidgeon/postgre/models/UserEntity.java | 26 +++++++++++++++++-- .../models/{ => types}/CourseRelation.java | 2 +- .../postgre/models/{ => types}/UserRole.java | 2 +- .../postgre/repository/UserRepository.java | 5 +--- 11 files changed, 93 insertions(+), 10 deletions(-) rename backend/app/src/main/java/com/ugent/pidgeon/postgre/models/{ => types}/CourseRelation.java (61%) rename backend/app/src/main/java/com/ugent/pidgeon/postgre/models/{ => types}/UserRole.java (56%) 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 index 97c494c8..7619473c 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaUserController.java @@ -1,13 +1,12 @@ package com.ugent.pidgeon.controllers; import com.ugent.pidgeon.postgre.models.CourseEntity; - import com.ugent.pidgeon.postgre.models.CourseRelation; + 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.data.util.Pair; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; 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 index 008060e4..b5f0edf7 100644 --- 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 @@ -2,6 +2,7 @@ import jakarta.persistence.*; +import java.sql.Timestamp; import java.util.HashSet; import java.util.Set; @@ -19,6 +20,9 @@ public class CourseEntity { @Column(name = "description", nullable=false) private String description; + @Column(name = "created_at") + private Timestamp createdAt; + public long getId() { @@ -48,4 +52,11 @@ public void setDescription(String 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 index 84fe5e6c..37f5e5dc 100644 --- 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 @@ -1,5 +1,6 @@ package com.ugent.pidgeon.postgre.models; +import com.ugent.pidgeon.postgre.models.types.CourseRelation; import jakarta.persistence.*; import java.io.Serializable; @@ -37,6 +38,14 @@ public long getUserId() { 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 { 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 index 0027d96a..2fc49171 100644 --- 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 @@ -2,6 +2,8 @@ import jakarta.persistence.*; +import java.sql.Timestamp; + @Entity @Table(name="group_clusters") public class GroupClusterEntity { @@ -24,6 +26,9 @@ public class GroupClusterEntity { @Column(name="group_amount", nullable=false) private int groupAmount; + @Column(name = "created_at") + private Timestamp createdAt; + public long getId() { return id; } @@ -63,4 +68,12 @@ public int getGroupAmount() { 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/ProjectEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java index fd14afbe..74310bd6 100644 --- 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 @@ -101,4 +101,12 @@ public Timestamp getDeadline() { public void setDeadline(Timestamp deadline) { this.deadline = deadline; } + + 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 index b6a0abce..3e794f2c 100644 --- 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 @@ -55,4 +55,20 @@ public Boolean getAccepted() { 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 index 394903a2..ed4bfe15 100644 --- 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 @@ -34,4 +34,12 @@ public String getDockerImage() { 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 index b7c46f7a..281789cc 100644 --- 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 @@ -1,10 +1,10 @@ package com.ugent.pidgeon.postgre.models; +import com.ugent.pidgeon.postgre.models.types.UserRole; import jakarta.persistence.*; -import java.util.HashSet; -import java.util.Set; +import java.sql.Timestamp; @Entity @Table(name = "users") @@ -28,6 +28,12 @@ public class UserEntity { @Enumerated(EnumType.STRING) private UserRole role; + @Column(name = "microsoft_token") + private String microsoftToken; + + @Column(name = "created_at") + private Timestamp createdAt; + public long getId() { return id; @@ -67,5 +73,21 @@ public void setEmail(String 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/CourseRelation.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/CourseRelation.java similarity index 61% rename from backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseRelation.java rename to backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/CourseRelation.java index fd58b851..8c0b254e 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseRelation.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/CourseRelation.java @@ -1,4 +1,4 @@ -package com.ugent.pidgeon.postgre.models; +package com.ugent.pidgeon.postgre.models.types; public enum CourseRelation { creator, diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/UserRole.java similarity index 56% rename from backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java rename to backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/UserRole.java index a27cfd40..53997f1a 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/UserRole.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/types/UserRole.java @@ -1,4 +1,4 @@ -package com.ugent.pidgeon.postgre.models; +package com.ugent.pidgeon.postgre.models.types; public enum UserRole { student, 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 index aa1f14d6..bc1b5d86 100644 --- 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 @@ -1,13 +1,10 @@ package com.ugent.pidgeon.postgre.repository; -import com.ugent.pidgeon.model.User; import com.ugent.pidgeon.postgre.models.CourseEntity; -import com.ugent.pidgeon.postgre.models.CourseRelation; +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.data.repository.query.Param; -import org.springframework.data.util.Pair; import org.springframework.stereotype.Repository; import java.util.List; From 5fe72ed4a6b2ebdcad2580a6df6290d1ef634c61 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:04:15 +0100 Subject: [PATCH 32/33] Added multiple deadline support (Incase this isn't necessary we can always just go back to a single deadline field) --- .../controllers/JpaProjectController.java | 6 ++- .../postgre/models/DeadlineEntity.java | 45 +++++++++++++++++++ .../pidgeon/postgre/models/ProjectEntity.java | 14 +++--- 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 backend/app/src/main/java/com/ugent/pidgeon/postgre/models/DeadlineEntity.java 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 index bcee992b..eb245d3d 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaProjectController.java @@ -1,5 +1,6 @@ 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; @@ -27,7 +28,10 @@ public List getProjects() { 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/postgre/models/DeadlineEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/DeadlineEntity.java new file mode 100644 index 00000000..f1d78f9d --- /dev/null +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/DeadlineEntity.java @@ -0,0 +1,45 @@ +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 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/ProjectEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/ProjectEntity.java index 74310bd6..6cb8f3d2 100644 --- 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 @@ -2,6 +2,7 @@ import jakarta.persistence.*; import java.sql.Timestamp; +import java.util.List; @Entity @@ -31,8 +32,8 @@ public class ProjectEntity { @Column(name="visible", nullable = false) private Boolean projectType; - @Column(name="deadline", nullable = false) - private Timestamp deadline; + @OneToMany(mappedBy = "project") + private List deadlines; @Column(name="max_score") private Integer maxScore; @@ -94,14 +95,9 @@ public void setProjectType(Boolean projectType) { this.projectType = projectType; } - public Timestamp getDeadline() { - return deadline; + public List getDeadlines() { + return deadlines; } - - public void setDeadline(Timestamp deadline) { - this.deadline = deadline; - } - public Integer getMaxScore() { return maxScore; } From 51efb10292a2c78d336d756dc5a1e5115f3131af Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:18:57 +0100 Subject: [PATCH 33/33] Added constructors --- .../pidgeon/controllers/JpaCourseController.java | 16 +++++++--------- .../pidgeon/postgre/models/CourseEntity.java | 7 +++++++ .../pidgeon/postgre/models/CourseUserEntity.java | 11 +++++++++++ .../pidgeon/postgre/models/DeadlineEntity.java | 8 ++++++++ .../ugent/pidgeon/postgre/models/FileEntity.java | 9 +++++++++ .../postgre/models/GroupClusterEntity.java | 11 +++++++++++ .../pidgeon/postgre/models/GroupEntity.java | 9 +++++++++ .../postgre/models/GroupFeedbackEntity.java | 10 ++++++++++ .../pidgeon/postgre/models/GroupUserEntity.java | 8 ++++++++ .../pidgeon/postgre/models/ProjectEntity.java | 13 +++++++++++++ .../pidgeon/postgre/models/SubmissionEntity.java | 12 ++++++++++++ .../ugent/pidgeon/postgre/models/TestEntity.java | 8 ++++++++ .../ugent/pidgeon/postgre/models/UserEntity.java | 11 +++++++++++ 13 files changed, 124 insertions(+), 9 deletions(-) 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 index 276040d8..7991cf6f 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/JpaCourseController.java @@ -45,13 +45,11 @@ public String getCourses() { return res.toString(); } - @GetMapping("/api/course") - public String addCourse(String name, String description) { - CourseEntity course = new CourseEntity(); - course.setId(1); - course.setName("Test"); - course.setDescription("Added for testing update purposes"); - courseRepository.save(course); - return "Course added"; - } +// @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/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java index b5f0edf7..f5f6ebb5 100644 --- 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 @@ -23,7 +23,14 @@ public class CourseEntity { @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; 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 index 37f5e5dc..e29a5f56 100644 --- 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 @@ -22,6 +22,15 @@ public class CourseUserEntity { @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; @@ -46,6 +55,8 @@ public CourseRelation getRelation() { public void setRelation(CourseRelation relation) { this.relation = relation; } + + } class CourseUserId implements Serializable { 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 index f1d78f9d..b1db7050 100644 --- 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 @@ -19,6 +19,14 @@ public class DeadlineEntity { @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; } 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 index 3b16d1e2..f7e0acef 100644 --- 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 @@ -20,6 +20,15 @@ public class FileEntity { @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; } 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 index 2fc49171..bc69f043 100644 --- 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 @@ -29,6 +29,17 @@ public class GroupClusterEntity { @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; } 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 index ac15bf7f..725aeea3 100644 --- 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 @@ -17,6 +17,15 @@ public class GroupEntity { @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; } 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 index bf10ecaa..3bea7ca8 100644 --- 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 @@ -23,6 +23,16 @@ public class GroupFeedbackEntity { @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; } 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 index bff40866..4b23d528 100644 --- 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 @@ -16,6 +16,14 @@ public class GroupUserEntity { @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; } 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 index 6cb8f3d2..98a4de30 100644 --- 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 @@ -38,6 +38,19 @@ public class ProjectEntity { @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; 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 index 3e794f2c..c43ba695 100644 --- 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 @@ -28,6 +28,17 @@ public class SubmissionEntity { @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; } @@ -56,6 +67,7 @@ public void setAccepted(Boolean accepted) { this.accepted = accepted; } + public long getProjectId() { return projectId; } 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 index ed4bfe15..a39cfb67 100644 --- 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 @@ -18,6 +18,14 @@ public class TestEntity { @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; 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 index 281789cc..76d629ab 100644 --- 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 @@ -34,6 +34,17 @@ public class UserEntity { @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;