From 064030f02a67be8d6c2a446833d32f862c164783 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Sat, 6 Apr 2024 12:05:43 +0200 Subject: [PATCH 01/12] Adapted to M-Elo --- .github/workflows/test.yaml | 10 ++-- Dockerfile | 4 +- build.gradle | 34 +++++------ gradle/wrapper/gradle-wrapper.properties | 2 +- jacoco.gradle | 6 +- settings.gradle | 8 +-- .../FlashcardServiceApplication.java | 2 +- .../DevTopicPublisherConfiguration.java | 6 +- ...phQlScalarsAndValidationConfiguration.java | 2 +- .../config/ModelMapperConfiguration.java | 2 +- .../config/RequestHeaderUserInterceptor.java | 4 +- .../config/TopicPublisherConfiguration.java | 4 +- .../controller/FlashcardController.java | 30 +++++----- .../controller/SubscriptionController.java | 6 +- .../exception/ExceptionResolver.java | 4 +- .../persistence/entity/FlashcardEntity.java | 5 +- .../entity/FlashcardProgressDataEntity.java | 2 +- .../FlashcardProgressDataLogEntity.java | 9 ++- .../entity/FlashcardSetEntity.java | 4 +- .../entity/FlashcardSideEntity.java | 2 +- .../persistence/mapper/FlashcardMapper.java | 6 +- .../FlashcardProgressDataLogRepository.java | 4 +- .../FlashcardProgressDataRepository.java | 4 +- .../repository/FlashcardRepository.java | 6 +- .../repository/FlashcardSetRepository.java | 8 +-- .../repository/FlashcardSideRepository.java | 4 +- .../service/FlashcardService.java | 59 +++++++++++++------ .../FlashcardUserProgressDataService.java | 46 +++++++++------ .../validation/FlashcardValidator.java | 4 +- .../graphql/service/flashcards.graphqls | 8 +-- .../graphql/service/mutation.graphqls | 8 ++- .../resources/graphql/service/query.graphqls | 2 +- .../api/MutationCreateFlashcardSetTest.java | 17 ++++-- .../api/MutationCreateFlashcardTest.java | 59 ++++++++++--------- .../api/MutationDeleteFlashcardSetTest.java | 20 +++---- .../api/MutationDeleteFlashcardTest.java | 26 ++++---- .../api/MutationLogFlashcardProgressTest.java | 26 ++++---- .../api/MutationUpdateFlashcardTest.java | 36 +++++------ .../api/QueryDueFlashcardsByCourseIdTest.java | 30 +++++----- .../api/QueryFlashcardSetTest.java | 24 ++++---- .../api/QueryFlashcardTest.java | 28 ++++----- .../api/TestAuthorization.java | 28 ++++----- .../service/FlashcardServiceTest.java | 24 ++++---- .../test_utils/TestUtils.java | 14 ++--- 44 files changed, 352 insertions(+), 285 deletions(-) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/FlashcardServiceApplication.java (86%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/config/DevTopicPublisherConfiguration.java (79%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java (95%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/config/ModelMapperConfiguration.java (86%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/config/RequestHeaderUserInterceptor.java (84%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/config/TopicPublisherConfiguration.java (80%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/controller/FlashcardController.java (79%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/controller/SubscriptionController.java (81%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/exception/ExceptionResolver.java (82%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/entity/FlashcardEntity.java (76%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java (92%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java (83%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/entity/FlashcardSetEntity.java (86%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/entity/FlashcardSideEntity.java (89%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/mapper/FlashcardMapper.java (92%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java (83%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java (59%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/repository/FlashcardRepository.java (65%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/repository/FlashcardSetRepository.java (56%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/persistence/repository/FlashcardSideRepository.java (68%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/service/FlashcardService.java (73%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/service/FlashcardUserProgressDataService.java (87%) rename src/main/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/validation/FlashcardValidator.java (94%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/MutationCreateFlashcardSetTest.java (87%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/MutationCreateFlashcardTest.java (77%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/MutationDeleteFlashcardSetTest.java (79%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/MutationDeleteFlashcardTest.java (80%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/MutationLogFlashcardProgressTest.java (85%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/MutationUpdateFlashcardTest.java (70%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java (71%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/QueryFlashcardSetTest.java (76%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/QueryFlashcardTest.java (66%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/api/TestAuthorization.java (74%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/service/FlashcardServiceTest.java (82%) rename src/test/java/de/unistuttgart/iste/{gits => meitrex}/flashcard_service/test_utils/TestUtils.java (89%) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d07452f..69be015 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,13 +6,13 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up JDK 17 - uses: actions/setup-java@v3 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Validate Gradle wrapper uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 @@ -22,7 +22,7 @@ jobs: - name: Execute tests env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + uses: gradle/gradle-build-action@v3 with: arguments: cleanTest test jacocoTestReport sonar diff --git a/Dockerfile b/Dockerfile index 56d6014..f3529c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,10 @@ COPY . /workspace/app RUN gradle clean build -x test RUN mkdir -p build/dependency && (cd build/dependency; jar -xf ../libs/*-SNAPSHOT.jar) -FROM eclipse-temurin:17-jdk +FROM eclipse-temurin:21-jdk VOLUME /tmp ARG DEPENDENCY=/workspace/app/build/dependency COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app -ENTRYPOINT ["java","-cp","app:app/lib/*","de.unistuttgart.iste.gits.flashcard_service.FlashcardServiceApplication"] \ No newline at end of file +ENTRYPOINT ["java","-cp","app:app/lib/*","de.unistuttgart.iste.meitrex.flashcard_service.FlashcardServiceApplication"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8670b65..607bf2e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,16 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.0.6' - id 'io.spring.dependency-management' version '1.1.0' - id "io.github.kobylynskyi.graphql.codegen" version "5.7.2" - id "org.sonarqube" version "4.0.0.2929" + id 'org.springframework.boot' version '3.+' + id 'io.spring.dependency-management' version '1.+' + id "io.github.kobylynskyi.graphql.codegen" version "5.+" + id "org.sonarqube" version "4.+" id "jacoco" } -group = 'de.unistuttgart.iste.gits' +group = 'de.unistuttgart.iste.meitrex' version = '0.0.1-SNAPSHOT' -sourceCompatibility = '17' +sourceCompatibility = '21' def jacocoEnabled = System.properties.getProperty("jacocoEnabled") ?: "true" @@ -21,11 +21,11 @@ if (jacocoEnabled.toBoolean()) { } sonarqube { - properties { - property("sonar.projectKey", "IT-REX-Platform_flashcard_service") - property("sonar.organization", "it-rex-platform") - property("sonar.host.url", "https://sonarcloud.io") - } + properties { + property("sonar.projectKey", "MEITREX_flashcard_service") + property("sonar.organization", "meitrex-platform") + property("sonar.host.url", "https://sonarcloud.io") + } } @@ -34,7 +34,7 @@ graphqlCodegen { // all config options: // https://github.com/kobylynskyi/graphql-java-codegen/blob/main/docs/codegen-options.md outputDir = new File("$buildDir/generated") - packageName = "de.unistuttgart.iste.gits.generated.dto" + packageName = "de.unistuttgart.iste.meitrex.generated.dto" generatedAnnotation = "jakarta.annotation.Generated" modelValidationAnnotation = "jakarta.validation.constraints.NotNull" generateApis = false // set to false as the generator does not support spring boot graphQL @@ -67,7 +67,7 @@ repositories { } dependencies { - implementation 'de.unistuttgart.iste.gits:gits-common:0.6.4' + implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.1.1' implementation 'com.google.code.findbugs:jsr305:3.0.2' // removes a gradle warning about an unknown annotation implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-graphql' @@ -84,18 +84,18 @@ dependencies { runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'de.unistuttgart.iste.gits:gits-common-test:0.3.2' + testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.0.1' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework:spring-webflux' testImplementation 'org.springframework.graphql:spring-graphql-test' testImplementation "org.mockito:mockito-core:3.+" testImplementation 'org.hamcrest:hamcrest:2.+' - testImplementation "org.testcontainers:postgresql:1.18.3" - testImplementation "org.testcontainers:junit-jupiter:1.18.3" + testImplementation "org.testcontainers:postgresql:1.+" + testImplementation "org.testcontainers:junit-jupiter:1.+" } tasks.named('test') { useJUnitPlatform() } -tasks.withType(Test).configureEach { testLogging.showStandardStreams = true } +tasks.withType(Test).configureEach { testLogging.showStandardStreams = true } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5083229..509c4a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jacoco.gradle b/jacoco.gradle index c7852e4..79af5a1 100644 --- a/jacoco.gradle +++ b/jacoco.gradle @@ -1,5 +1,5 @@ jacoco { - toolVersion = "0.8.8" + toolVersion = "0.8.11" } test { @@ -9,8 +9,8 @@ test { jacocoTestReport { reports { - xml.enabled true - html.enabled true + xml.required.set(true) + html.required.set(true) html.outputLocation = layout.buildDirectory.dir('jacocoHtml') } } diff --git a/settings.gradle b/settings.gradle index 356b8c6..aa4f16f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,10 @@ rootProject.name = 'flashcard_service' sourceControl { - gitRepository(uri('https://github.com/IT-REX-Platform/gits-common')) { - producesModule('de.unistuttgart.iste.gits:gits-common') + gitRepository(uri('https://github.com/MEITREX/common')) { + producesModule('de.unistuttgart.iste.meitrex:meitrex-common') } - gitRepository(uri('https://github.com/IT-REX-Platform/gits-common-test')) { - producesModule('de.unistuttgart.iste.gits:gits-common-test') + gitRepository(uri('https://github.com/MEITREX/common_test')) { + producesModule('de.unistuttgart.iste.meitrex:meitrex-common-test') } } \ No newline at end of file diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/FlashcardServiceApplication.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java similarity index 86% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/FlashcardServiceApplication.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java index 53b1398..3b894e1 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/FlashcardServiceApplication.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service; +package de.unistuttgart.iste.meitrex.flashcard_service; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/DevTopicPublisherConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/DevTopicPublisherConfiguration.java similarity index 79% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/DevTopicPublisherConfiguration.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/DevTopicPublisherConfiguration.java index 091ab7e..04dae1d 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/DevTopicPublisherConfiguration.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/DevTopicPublisherConfiguration.java @@ -1,8 +1,8 @@ -package de.unistuttgart.iste.gits.flashcard_service.config; +package de.unistuttgart.iste.meitrex.flashcard_service.config; -import de.unistuttgart.iste.gits.common.dapr.MockTopicPublisher; -import de.unistuttgart.iste.gits.common.dapr.TopicPublisher; +import de.unistuttgart.iste.meitrex.common.dapr.MockTopicPublisher; +import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.*; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java similarity index 95% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java index 8b248f3..a73ced1 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/GraphQlScalarsAndValidationConfiguration.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service.config; +package de.unistuttgart.iste.meitrex.flashcard_service.config; import graphql.scalars.ExtendedScalars; import graphql.validation.rules.OnValidationErrorStrategy; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/ModelMapperConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/ModelMapperConfiguration.java similarity index 86% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/ModelMapperConfiguration.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/ModelMapperConfiguration.java index 5ac199d..0d9892a 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/ModelMapperConfiguration.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/ModelMapperConfiguration.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service.config; +package de.unistuttgart.iste.meitrex.flashcard_service.config; import org.modelmapper.ModelMapper; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/RequestHeaderUserInterceptor.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/RequestHeaderUserInterceptor.java similarity index 84% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/RequestHeaderUserInterceptor.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/RequestHeaderUserInterceptor.java index 0843e81..3590a00 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/RequestHeaderUserInterceptor.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/RequestHeaderUserInterceptor.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.config; +package de.unistuttgart.iste.meitrex.flashcard_service.config; -import de.unistuttgart.iste.gits.common.user_handling.RequestHeaderUserProcessor; +import de.unistuttgart.iste.meitrex.common.user_handling.RequestHeaderUserProcessor; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/TopicPublisherConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/TopicPublisherConfiguration.java similarity index 80% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/TopicPublisherConfiguration.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/TopicPublisherConfiguration.java index 285b472..e5ad301 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/config/TopicPublisherConfiguration.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/config/TopicPublisherConfiguration.java @@ -1,7 +1,7 @@ -package de.unistuttgart.iste.gits.flashcard_service.config; +package de.unistuttgart.iste.meitrex.flashcard_service.config; -import de.unistuttgart.iste.gits.common.dapr.TopicPublisher; +import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; import io.dapr.client.DaprClientBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/controller/FlashcardController.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java similarity index 79% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/controller/FlashcardController.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java index cef909f..4b7a893 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/controller/FlashcardController.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java @@ -1,12 +1,14 @@ -package de.unistuttgart.iste.gits.flashcard_service.controller; - -import de.unistuttgart.iste.gits.common.exception.NoAccessToCourseException; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser.UserRoleInCourse; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.service.FlashcardService; -import de.unistuttgart.iste.gits.flashcard_service.service.FlashcardUserProgressDataService; -import de.unistuttgart.iste.gits.generated.dto.*; +package de.unistuttgart.iste.meitrex.flashcard_service.controller; + +import de.unistuttgart.iste.meitrex.generated.dto.Flashcard; +import de.unistuttgart.iste.meitrex.generated.dto.FlashcardSet; +import de.unistuttgart.iste.meitrex.common.exception.NoAccessToCourseException; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.service.FlashcardService; +import de.unistuttgart.iste.meitrex.flashcard_service.service.FlashcardUserProgressDataService; +import de.unistuttgart.iste.meitrex.generated.dto.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.graphql.data.method.annotation.*; @@ -15,8 +17,8 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse; -import static de.unistuttgart.iste.gits.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourses; +import static de.unistuttgart.iste.meitrex.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse; +import static de.unistuttgart.iste.meitrex.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourses; @Slf4j @@ -67,7 +69,7 @@ public List dueFlashcardsByCourseId(@Argument final UUID courseId, @SchemaMapping(typeName = "Flashcard", field = "userProgressData") public FlashcardProgressData flashcardUserProgressData(final Flashcard flashcard, @ContextValue final LoggedInUser currentUser) { - return progressDataService.getProgressData(flashcard.getId(), currentUser.getId()); + return progressDataService.getProgressData(flashcard.getItemId(), currentUser.getId()); } @MutationMapping @@ -82,13 +84,13 @@ public FlashcardSetMutation mutateFlashcardSet(@Argument final UUID assessmentId } @SchemaMapping(typeName = "FlashcardSetMutation") - public Flashcard createFlashcard(@Argument(name = "input") final CreateFlashcardInput input, + public Flashcard _internal_noauth_createFlashcard(@Argument(name = "input") final CreateFlashcardInput input, final FlashcardSetMutation mutation) { return flashcardService.createFlashcard(mutation.getAssessmentId(), input); } @SchemaMapping(typeName = "FlashcardSetMutation") - public Flashcard updateFlashcard(@Argument(name = "input") final UpdateFlashcardInput input) { + public Flashcard _internal_noauth_updateFlashcard(@Argument(name = "input") final UpdateFlashcardInput input) { return flashcardService.updateFlashcard(input); } diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/controller/SubscriptionController.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java similarity index 81% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/controller/SubscriptionController.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java index a537278..219ccc2 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/controller/SubscriptionController.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java @@ -1,7 +1,7 @@ -package de.unistuttgart.iste.gits.flashcard_service.controller; +package de.unistuttgart.iste.meitrex.flashcard_service.controller; -import de.unistuttgart.iste.gits.common.event.ContentChangeEvent; -import de.unistuttgart.iste.gits.flashcard_service.service.FlashcardService; +import de.unistuttgart.iste.meitrex.common.event.ContentChangeEvent; +import de.unistuttgart.iste.meitrex.flashcard_service.service.FlashcardService; import io.dapr.Topic; import io.dapr.client.domain.CloudEvent; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/exception/ExceptionResolver.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/exception/ExceptionResolver.java similarity index 82% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/exception/ExceptionResolver.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/exception/ExceptionResolver.java index fddded6..9adf6d2 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/exception/ExceptionResolver.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/exception/ExceptionResolver.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.exception; +package de.unistuttgart.iste.meitrex.flashcard_service.exception; -import de.unistuttgart.iste.gits.common.exception.ExceptionToGraphQlErrorConverter; +import de.unistuttgart.iste.meitrex.common.exception.ExceptionToGraphQlErrorConverter; import graphql.GraphQLError; import graphql.schema.DataFetchingEnvironment; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardEntity.java similarity index 76% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardEntity.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardEntity.java index c05d51e..202537e 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardEntity.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.entity; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity; import jakarta.persistence.*; import lombok.*; @@ -14,8 +14,7 @@ public class FlashcardEntity { @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private UUID id; + private UUID itemId; @OneToMany(mappedBy = "flashcard", cascade = CascadeType.ALL, orphanRemoval = true) private List sides; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java similarity index 92% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java index b02097d..42a366c 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.entity; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity; import jakarta.persistence.*; import lombok.*; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java similarity index 83% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java index 3f11e07..16a92eb 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataLogEntity.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.entity; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity; import jakarta.persistence.*; import lombok.*; @@ -8,6 +8,9 @@ @Entity(name = "FlashcardProgressDataLog") @Data +@Builder +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class FlashcardProgressDataLogEntity { @@ -30,4 +33,8 @@ public class FlashcardProgressDataLogEntity { @EqualsAndHashCode.Exclude @ToString.Exclude private FlashcardProgressDataEntity flashcardProgressData; + + public boolean getSuccess() { + return success; + } } diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardSetEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardSetEntity.java similarity index 86% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardSetEntity.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardSetEntity.java index 0b28176..671c46c 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardSetEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardSetEntity.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.entity; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity; -import de.unistuttgart.iste.gits.common.persistence.IWithId; +import de.unistuttgart.iste.meitrex.common.persistence.IWithId; import jakarta.persistence.*; import lombok.*; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardSideEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardSideEntity.java similarity index 89% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardSideEntity.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardSideEntity.java index 92ddc66..9497728 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/entity/FlashcardSideEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardSideEntity.java @@ -1,4 +1,4 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.entity; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity; import jakarta.persistence.*; import lombok.*; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/mapper/FlashcardMapper.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/mapper/FlashcardMapper.java similarity index 92% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/mapper/FlashcardMapper.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/mapper/FlashcardMapper.java index 4db623f..7f13018 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/mapper/FlashcardMapper.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/mapper/FlashcardMapper.java @@ -1,7 +1,7 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.mapper; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.mapper; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.*; -import de.unistuttgart.iste.gits.generated.dto.*; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.*; +import de.unistuttgart.iste.meitrex.generated.dto.*; import org.modelmapper.ModelMapper; import org.springframework.stereotype.Component; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java similarity index 83% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java index f96a069..7ac46c4 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardProgressDataLogRepository.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.repository; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardProgressDataLogEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardProgressDataLogEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java similarity index 59% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java index ee00100..d38c14a 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardProgressDataRepository.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.repository; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardProgressDataEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardProgressDataEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java similarity index 65% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardRepository.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java index 77fef71..93e343f 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.repository; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; @@ -14,7 +14,7 @@ */ @Repository public interface FlashcardRepository extends JpaRepository, JpaSpecificationExecutor { - List findByIdIn(List ids); + List findByItemIdIn(List ids); } diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardSetRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java similarity index 56% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardSetRepository.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java index c043502..1580426 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardSetRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java @@ -1,7 +1,7 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.repository; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository; -import de.unistuttgart.iste.gits.common.persistence.GitsRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.common.persistence.MeitrexRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; @@ -9,7 +9,7 @@ import java.util.UUID; @Repository -public interface FlashcardSetRepository extends GitsRepository, +public interface FlashcardSetRepository extends MeitrexRepository, JpaSpecificationExecutor { /** diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardSideRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSideRepository.java similarity index 68% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardSideRepository.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSideRepository.java index bcec133..d20f601 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/persistence/repository/FlashcardSideRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSideRepository.java @@ -1,7 +1,7 @@ -package de.unistuttgart.iste.gits.flashcard_service.persistence.repository; +package de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSideEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSideEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java similarity index 73% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardService.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java index be4c27e..6ad47e3 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java @@ -1,15 +1,16 @@ -package de.unistuttgart.iste.gits.flashcard_service.service; - -import de.unistuttgart.iste.gits.common.event.ContentChangeEvent; -import de.unistuttgart.iste.gits.common.event.CrudOperation; -import de.unistuttgart.iste.gits.common.exception.IncompleteEventMessageException; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.mapper.FlashcardMapper; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.validation.FlashcardValidator; -import de.unistuttgart.iste.gits.generated.dto.*; +package de.unistuttgart.iste.meitrex.flashcard_service.service; + +import de.unistuttgart.iste.meitrex.common.event.ContentChangeEvent; +import de.unistuttgart.iste.meitrex.common.event.CrudOperation; +import de.unistuttgart.iste.meitrex.common.exception.IncompleteEventMessageException; +import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.mapper.FlashcardMapper; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.validation.FlashcardValidator; +import de.unistuttgart.iste.meitrex.generated.dto.*; import jakarta.persistence.EntityNotFoundException; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; @@ -31,6 +32,8 @@ public class FlashcardService { private final FlashcardMapper flashcardMapper; private final FlashcardValidator flashcardValidator; + private final TopicPublisher topicPublisher; + public Flashcard createFlashcard(final UUID assessmentId, final CreateFlashcardInput flashcardInput) { flashcardValidator.validateCreateFlashcardInput(flashcardInput); @@ -50,8 +53,8 @@ public Flashcard createFlashcard(final UUID assessmentId, final CreateFlashcardI public Flashcard updateFlashcard(final UpdateFlashcardInput input) { flashcardValidator.validateUpdateFlashcardInput(input); - final FlashcardEntity oldFlashcard = flashcardRepository.findById(input.getId()) - .orElseThrow(() -> new EntityNotFoundException("Flashcard with id %s not found.".formatted(input.getId()))); + final FlashcardEntity oldFlashcard = flashcardRepository.findById(input.getItemId()) + .orElseThrow(() -> new EntityNotFoundException("Flashcard with id %s not found.".formatted(input.getItemId()))); FlashcardEntity updatedFlashcard = flashcardMapper.dtoToEntity(input); updatedFlashcard.setParentSet(oldFlashcard.getParentSet()); @@ -63,10 +66,11 @@ public Flashcard updateFlashcard(final UpdateFlashcardInput input) { public UUID deleteFlashcard(final UUID assessmentId, final UUID flashcardId) { final FlashcardSetEntity set = requireFlashcardSetExisting(assessmentId); - if (!set.getFlashcards().removeIf(x -> x.getId().equals(flashcardId))) { + if (!set.getFlashcards().removeIf(x -> x.getItemId().equals(flashcardId))) { throw new EntityNotFoundException("Flashcard with id %s not found.".formatted(flashcardId)); } flashcardSetRepository.save(set); + publishItemChangeEvent(flashcardId); return flashcardId; } @@ -82,6 +86,7 @@ public FlashcardSet createFlashcardSet(final UUID courseId, final UUID assessmen public UUID deleteFlashcardSet(final UUID uuid) { requireFlashcardSetExisting(uuid); + publishDeletedFlashcardSet(uuid); flashcardSetRepository.deleteById(uuid); return uuid; } @@ -92,9 +97,9 @@ public FlashcardSetEntity requireFlashcardSetExisting(final UUID uuid) { } public List getFlashcardsByIds(final List ids) { - final List entities = flashcardRepository.findByIdIn(ids); + final List entities = flashcardRepository.findByItemIdIn(ids); - ids.removeAll(entities.stream().map(FlashcardEntity::getId).toList()); + ids.removeAll(entities.stream().map(FlashcardEntity::getItemId).toList()); if(!ids.isEmpty()) { throw new EntityNotFoundException("Flashcards with ids " + ids.stream().map(UUID::toString).collect(Collectors.joining(", ")) @@ -159,4 +164,24 @@ private void checkCompletenessOfDto(final ContentChangeEvent dto) throws Incompl throw new IncompleteEventMessageException(IncompleteEventMessageException.ERROR_INCOMPLETE_MESSAGE); } } + + /*** + * helper function, that creates a ItemChange Event and publish it, when a flashcard was deleted + * @param itemId the id of the item + */ + private void publishItemChangeEvent(final UUID itemId) { + topicPublisher.notifyItemChanges(itemId,CrudOperation.DELETE); + + } + + /** + * for each flashcard of the deleted flashcard set publish a itemchanged event + * @param flashcardSetId the id of the flashcardset to delete + */ + private void publishDeletedFlashcardSet(UUID flashcardSetId){ + FlashcardSetEntity flashcardSet=flashcardSetRepository.findById(flashcardSetId).get(); + for(FlashcardEntity flashcard:flashcardSet.getFlashcards()){ + publishItemChangeEvent(flashcard.getItemId()); + } + } } diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java similarity index 87% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardUserProgressDataService.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index d1bf73e..f87a78a 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -1,11 +1,12 @@ -package de.unistuttgart.iste.gits.flashcard_service.service; - -import de.unistuttgart.iste.gits.common.dapr.TopicPublisher; -import de.unistuttgart.iste.gits.common.event.ContentProgressedEvent; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.*; -import de.unistuttgart.iste.gits.flashcard_service.persistence.mapper.FlashcardMapper; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.*; -import de.unistuttgart.iste.gits.generated.dto.*; +package de.unistuttgart.iste.meitrex.flashcard_service.service; + +import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; +import de.unistuttgart.iste.meitrex.common.event.ContentProgressedEvent; +import de.unistuttgart.iste.meitrex.common.event.Response; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.*; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.mapper.FlashcardMapper; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.*; +import de.unistuttgart.iste.meitrex.generated.dto.*; import lombok.RequiredArgsConstructor; import org.modelmapper.ModelMapper; import org.springframework.stereotype.Service; @@ -115,7 +116,7 @@ private Stream getDueFlashcardsOfFlashcardSet(final FlashcardSe final OffsetDateTime now = OffsetDateTime.now(); return flashcards.stream() .filter(flashcardEntity -> { - final var progressData = getProgressDataEntity(flashcardEntity.getId(), userId); + final var progressData = getProgressDataEntity(flashcardEntity.getItemId(), userId); if (progressData.getNextLearn() == null) { // if the flashcard has never been learned, it's not due for review return false; @@ -139,7 +140,7 @@ private FlashcardLearnedFeedback createFeedback( int correctlyLearnedFlashcards = 0; for (final FlashcardEntity flashcardEntity : flashcards) { - final FlashcardProgressDataEntity progressDataOfCurrentCard = getProgressDataEntity(flashcardEntity.getId(), userId); + final FlashcardProgressDataEntity progressDataOfCurrentCard = getProgressDataEntity(flashcardEntity.getItemId(), userId); if (wasNotLearnedInCurrentIteration(flashcardSetEntity, progressDataOfCurrentCard)) { numberOfFlashcardsNotLearnedInSet++; } else if (wasLearnedSuccessful(progressDataOfCurrentCard)) { @@ -158,10 +159,9 @@ private FlashcardLearnedFeedback createFeedback( } private static boolean wasLearnedSuccessful(final FlashcardProgressDataEntity progressData) { - return progressData.getFlashcardProgressDataLogs().stream() - .findFirst() - .map(FlashcardProgressDataLogEntity::isSuccess) - .orElse(false); + List progress= progressData.getFlashcardProgressDataLogs(); + boolean success=progress.get(0).getSuccess(); + return success; } private static boolean wasNotLearnedInCurrentIteration(final FlashcardSetEntity flashcardSetEntity, final FlashcardProgressDataEntity progressData) { @@ -226,14 +226,25 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS final int correct = dataLogs.stream().mapToInt(log -> log.getSuccess() ? 1 : 0).sum(); final float correctness = (float) correct / total; - + List responses= new ArrayList(); + for(FlashcardProgressDataLogEntity log:dataLogEntities){ + float correctnes=0; + if(log.getSuccess()){ + correctnes=1; + } + Response response =Response.builder() + .itemId(log.getFlashcardProgressData().getPrimaryKey().getFlashcardID()) + .response(correctnes) + .build(); + responses.add(response); + } flashcardSetEntity.setLastLearned(OffsetDateTime.now()); flashcardSetRepository.save(flashcardSetEntity); - publishUserProgressEvent(userId, flashcardSetId, correctness); + publishUserProgressEvent(userId, flashcardSetId, correctness,responses); } - private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness) { + private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness, final List responses) { topicPublisher.notifyUserWorkedOnContent( ContentProgressedEvent.builder() .contentId(assessmentId) @@ -242,6 +253,7 @@ private void publishUserProgressEvent(final UUID userId, final UUID assessmentId .success(true) .timeToComplete(null) .correctness(correctness) + .responses(responses) .build() ); } diff --git a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/validation/FlashcardValidator.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java similarity index 94% rename from src/main/java/de/unistuttgart/iste/gits/flashcard_service/validation/FlashcardValidator.java rename to src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java index 599bd64..045430e 100644 --- a/src/main/java/de/unistuttgart/iste/gits/flashcard_service/validation/FlashcardValidator.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java @@ -1,6 +1,6 @@ -package de.unistuttgart.iste.gits.flashcard_service.validation; +package de.unistuttgart.iste.meitrex.flashcard_service.validation; -import de.unistuttgart.iste.gits.generated.dto.*; +import de.unistuttgart.iste.meitrex.generated.dto.*; import jakarta.validation.ValidationException; import org.springframework.stereotype.Component; diff --git a/src/main/resources/graphql/service/flashcards.graphqls b/src/main/resources/graphql/service/flashcards.graphqls index 82cf46f..82006e2 100644 --- a/src/main/resources/graphql/service/flashcards.graphqls +++ b/src/main/resources/graphql/service/flashcards.graphqls @@ -5,9 +5,9 @@ and which sides he has to guess. """ type Flashcard { """ - Unique identifier of this flashcard. + Unique identifier of this flashcard, which is the id of the corresponding item """ - id: UUID! + itemId: UUID! """ List of sides of this flashcard. """ @@ -104,9 +104,9 @@ input FlashcardSideInput { input UpdateFlashcardInput { """ - Id of the flashcard to update. + Id of the flashcard to update, which is the id of the corresponding item. """ - id: UUID! + itemId: UUID! """ List of sides of this flashcard. Must be at least two sides. """ diff --git a/src/main/resources/graphql/service/mutation.graphqls b/src/main/resources/graphql/service/mutation.graphqls index 97b1dcf..3432ce9 100644 --- a/src/main/resources/graphql/service/mutation.graphqls +++ b/src/main/resources/graphql/service/mutation.graphqls @@ -39,13 +39,17 @@ type FlashcardSetMutation { """ Creates a new flashcard. Throws an error if the flashcard set does not exist. + ⚠️ This mutation is only accessible internally in the system and allows the caller to create Flashcards without + any permissions check and should not be called without any validation of the caller's permissions. ⚠️ """ - createFlashcard(input: CreateFlashcardInput!): Flashcard! + _internal_noauth_createFlashcard(input: CreateFlashcardInput!): Flashcard! """ Updates a flashcard. Throws an error if the flashcard does not exist. + ⚠️ This mutation is only accessible internally in the system and allows the caller to update Flashcards without + any permissions check and should not be called without any validation of the caller's permissions. ⚠️ """ - updateFlashcard(input: UpdateFlashcardInput!): Flashcard! + _internal_noauth_updateFlashcard(input: UpdateFlashcardInput!): Flashcard! """ Deletes the flashcard with the specified ID. Throws an error if the flashcard does not exist. diff --git a/src/main/resources/graphql/service/query.graphqls b/src/main/resources/graphql/service/query.graphqls index 807b7ac..7938aa2 100644 --- a/src/main/resources/graphql/service/query.graphqls +++ b/src/main/resources/graphql/service/query.graphqls @@ -3,7 +3,7 @@ type Query { Get flashcards by their ids. 🔒 The user must be enrolled in the course the flashcards belong to. Otherwise an error is thrown. """ - flashcardsByIds(ids: [UUID!]!): [Flashcard!]! + flashcardsByIds(itemIds: [UUID!]!): [Flashcard!]! """ Get flashcard sets by their assessment ids. Returns a list of flashcard sets in the same order as the provided ids. diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationCreateFlashcardSetTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java similarity index 87% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationCreateFlashcardSetTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java index b45a72f..514aeb7 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationCreateFlashcardSetTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java @@ -1,8 +1,8 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; +package de.unistuttgart.iste.meitrex.flashcard_service.api; -import de.unistuttgart.iste.gits.common.testutil.GraphQlApiTest; -import de.unistuttgart.iste.gits.common.testutil.TablesToDelete; -import de.unistuttgart.iste.gits.generated.dto.*; +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; +import de.unistuttgart.iste.meitrex.generated.dto.*; import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.graphql.test.tester.GraphQlTester; @@ -25,12 +25,15 @@ class MutationCreateFlashcardSetTest { void testCreateFlashcardSet(final GraphQlTester tester) { final UUID assessmentId = UUID.randomUUID(); final UUID courseId = UUID.randomUUID(); + final UUID itemId1= UUID.randomUUID(); + final UUID itemId2=UUID.randomUUID(); final String query = """ mutation ($courseId: UUID!, $assessmentId: UUID!){ _internal_noauth_createFlashcardSet(courseId: $courseId, assessmentId: $assessmentId, input: { flashcards: [ { + itemId:$itemId1, sides: [ { label: "Side 1", @@ -47,6 +50,7 @@ void testCreateFlashcardSet(final GraphQlTester tester) { ] }, { + itemId:$itemId2, sides: [ { label: "Side 1", @@ -69,6 +73,7 @@ void testCreateFlashcardSet(final GraphQlTester tester) { assessmentId courseId flashcards { + itemId sides { label isQuestion @@ -83,6 +88,8 @@ void testCreateFlashcardSet(final GraphQlTester tester) { final FlashcardSet createdFlashcardSet = tester.document(query) .variable("assessmentId", assessmentId) .variable("courseId", courseId) + .variable("itemId1", itemId1) + .variable("itemId2", itemId2) .execute() .path("_internal_noauth_createFlashcardSet").entity(FlashcardSet.class).get(); @@ -96,6 +103,7 @@ void testCreateFlashcardSet(final GraphQlTester tester) { final Flashcard flashcard1 = flashcards.get(0); assertThat(flashcard1.getSides(), hasSize(2)); + assertThat(flashcard1.getItemId(), is(itemId1)); final FlashcardSide flashcard1Side1 = flashcard1.getSides().get(0); assertThat(flashcard1Side1.getLabel(), is("Side 1")); @@ -111,6 +119,7 @@ void testCreateFlashcardSet(final GraphQlTester tester) { final Flashcard flashcard2 = flashcards.get(1); assertThat(flashcard2.getSides(), hasSize(2)); + assertThat(flashcard2.getItemId(), is(itemId2)); final FlashcardSide flashcard2Side1 = flashcard2.getSides().get(0); assertThat(flashcard2Side1.getLabel(), is("Side 1")); diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationCreateFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java similarity index 77% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationCreateFlashcardTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java index ff8a587..cc19559 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationCreateFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java @@ -1,15 +1,15 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; - -import de.unistuttgart.iste.gits.common.testutil.GraphQlApiTest; -import de.unistuttgart.iste.gits.common.testutil.InjectCurrentUserHeader; -import de.unistuttgart.iste.gits.common.testutil.TablesToDelete; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.*; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; -import de.unistuttgart.iste.gits.generated.dto.Flashcard; -import de.unistuttgart.iste.gits.generated.dto.FlashcardSide; +package de.unistuttgart.iste.meitrex.flashcard_service.api; + +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; +import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.*; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; +import de.unistuttgart.iste.meitrex.generated.dto.Flashcard; +import de.unistuttgart.iste.meitrex.generated.dto.FlashcardSide; import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +20,7 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; @GraphQlApiTest @TablesToDelete({"flashcard_side", "flashcard", "flashcard_set"}) @@ -44,11 +44,12 @@ class MutationCreateFlashcardTest { @Commit void testCreateFlashcard(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - + final UUID itemId=UUID.randomUUID(); final String query = """ mutation ($setId: UUID!) { mutateFlashcardSet(assessmentId: $setId) { - createFlashcard(input: { + _internal_noauth_createFlashcard(input: { + itemId:$itemId, sides: [ { label: "Side 11", @@ -64,7 +65,7 @@ void testCreateFlashcard(final GraphQlTester graphQlTester) { } ] }) { - id + itemId sides { label isQuestion @@ -81,13 +82,14 @@ void testCreateFlashcard(final GraphQlTester graphQlTester) { // Execute the mutation and extract the created flashcard final Flashcard createdFlashcard = graphQlTester.document(query) .variable("setId", setId) + .variable("itemId", itemId) .execute() - .path("mutateFlashcardSet.createFlashcard") + .path("mutateFlashcardSet._internal_noauth_createFlashcard") .entity(Flashcard.class) .get(); // Assert the values of the data returned by the createFlashcard mutation - assertThat(createdFlashcard.getId()).isNotNull(); + assertThat(createdFlashcard.getItemId()).isNotNull(); assertThat(createdFlashcard.getSides()).containsExactlyInAnyOrder( new FlashcardSide("Question 1", "Side 11", true, false), new FlashcardSide("Answer 1", "Side 21", false, true) @@ -98,10 +100,10 @@ void testCreateFlashcard(final GraphQlTester graphQlTester) { .getReferenceById(setId) .getFlashcards() .stream() - .map(FlashcardEntity::getId)) - .contains(createdFlashcard.getId()); + .map(FlashcardEntity::getItemId)) + .contains(createdFlashcard.getItemId()); - final FlashcardEntity flashcardFromRepo = flashcardRepository.getReferenceById(createdFlashcard.getId()); + final FlashcardEntity flashcardFromRepo = flashcardRepository.getReferenceById(createdFlashcard.getItemId()); assertThat(flashcardFromRepo.getParentSet().getAssessmentId()).isEqualTo(setId); assertThat(flashcardFromRepo.getSides().get(0)) @@ -117,11 +119,12 @@ void testCreateFlashcard(final GraphQlTester graphQlTester) { @Test void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - + final UUID itemId=UUID.randomUUID(); final String query = """ mutation ($setId: UUID!) { mutateFlashcardSet(assessmentId: $setId) { - createFlashcard(input: { + _internal_noauth_createFlashcard(input: { + itemId:$itemId, sides: [ { label: "Side 11", @@ -137,7 +140,7 @@ void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { } ] }) { - id + itemId sides { label isQuestion @@ -154,6 +157,7 @@ void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { // Execute the mutation and check for expected errors graphQlTester.document(query) .variable("setId", setId) + .variable("itemId", itemId) .execute() .errors() .expect(responseError -> responseError.getMessage() != null && responseError.getMessage().toLowerCase().contains("flashcards must have at least one question side and one answer side")); @@ -164,11 +168,11 @@ void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { @Test void testCreateInvalidFlashcardSide(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - + final UUID itemId=UUID.randomUUID(); final String query = """ mutation ($setId: UUID!) { mutateFlashcardSet(assessmentId: $setId) { - createFlashcard(input: { + _internal_noauth_createFlashcard(input: { sides: [ { label: "Side 11", @@ -184,7 +188,7 @@ void testCreateInvalidFlashcardSide(final GraphQlTester graphQlTester) { } ] }) { - id + itemId sides { label isQuestion @@ -201,6 +205,7 @@ void testCreateInvalidFlashcardSide(final GraphQlTester graphQlTester) { // Execute the mutation and check for expected errors graphQlTester.document(query) .variable("setId", setId) + .variable("itemId", itemId) .execute() .errors() .expect(responseError -> responseError.getMessage() != null && responseError.getMessage().toLowerCase().contains("flashcard side must must be at least a question or an answer")); diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationDeleteFlashcardSetTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationDeleteFlashcardSetTest.java similarity index 79% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationDeleteFlashcardSetTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationDeleteFlashcardSetTest.java index ca52cc9..682c6ac 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationDeleteFlashcardSetTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationDeleteFlashcardSetTest.java @@ -1,12 +1,12 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; - -import de.unistuttgart.iste.gits.common.testutil.GraphQlApiTest; -import de.unistuttgart.iste.gits.common.testutil.InjectCurrentUserHeader; -import de.unistuttgart.iste.gits.common.testutil.TablesToDelete; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.*; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; +package de.unistuttgart.iste.meitrex.flashcard_service.api; + +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; +import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.*; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.graphql.test.tester.GraphQlTester; @@ -16,7 +16,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; import static org.assertj.core.api.Assertions.assertThat; @GraphQlApiTest diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationDeleteFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationDeleteFlashcardTest.java similarity index 80% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationDeleteFlashcardTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationDeleteFlashcardTest.java index e07c093..25af1c2 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationDeleteFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationDeleteFlashcardTest.java @@ -1,13 +1,13 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; - -import de.unistuttgart.iste.gits.common.testutil.GraphQlApiTest; -import de.unistuttgart.iste.gits.common.testutil.InjectCurrentUserHeader; -import de.unistuttgart.iste.gits.common.testutil.TablesToDelete; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; +package de.unistuttgart.iste.meitrex.flashcard_service.api; + +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; +import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,7 +17,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; import static org.assertj.core.api.Assertions.assertThat; @@ -55,7 +55,7 @@ void testDeleteFlashcard(final GraphQlTester tester) { """; final UUID setToDeleteFrom = expectedSets.get(0).getAssessmentId(); - final UUID flashcardToDelete = expectedSets.get(0).getFlashcards().stream().findAny().orElseThrow().getId(); + final UUID flashcardToDelete = expectedSets.get(0).getFlashcards().stream().findAny().orElseThrow().getItemId(); tester.document(query) .variable("assessmentId", setToDeleteFrom) @@ -73,7 +73,7 @@ void testDeleteFlashcard(final GraphQlTester tester) { .orElseThrow() .getFlashcards() .stream() - .filter(x -> x.getId() == flashcardToDelete)) + .filter(x -> x.getItemId() == flashcardToDelete)) .isEmpty(); // assert that the flashcard is missing from the flashcard repository diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationLogFlashcardProgressTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java similarity index 85% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationLogFlashcardProgressTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java index a46b4d5..d160601 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationLogFlashcardProgressTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java @@ -1,12 +1,13 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; - -import de.unistuttgart.iste.gits.common.dapr.TopicPublisher; -import de.unistuttgart.iste.gits.common.event.ContentProgressedEvent; -import de.unistuttgart.iste.gits.common.testutil.*; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; +package de.unistuttgart.iste.meitrex.flashcard_service.api; + +import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; +import de.unistuttgart.iste.meitrex.common.event.ContentProgressedEvent; +import de.unistuttgart.iste.meitrex.common.testutil.*; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.common.event.Response; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; import jakarta.transaction.Transactional; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; @@ -19,7 +20,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; @@ -70,8 +71,8 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { FlashcardSetEntity flashcardSetEntity = flashcardSet.get(0); final UUID flashcardSetId = flashcardSetEntity.getAssessmentId(); - final UUID flashcardId1 = flashcardSetEntity.getFlashcards().get(0).getId(); - final UUID flashcardId2 = flashcardSetEntity.getFlashcards().get(1).getId(); + final UUID flashcardId1 = flashcardSetEntity.getFlashcards().get(0).getItemId(); + final UUID flashcardId2 = flashcardSetEntity.getFlashcards().get(1).getItemId(); runMutationLogFlashcardLearned(graphQlTester, flashcardId1, true) .path("logFlashcardLearned.success").entity(Boolean.class).isEqualTo(true) @@ -95,6 +96,7 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { .success(true) .timeToComplete(null) .hintsUsed(0) + .responses(List.of(Response.builder().itemId(flashcardId2).response(1).build())) .build(); verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent); diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationUpdateFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java similarity index 70% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationUpdateFlashcardTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java index 13a7ddf..5e82d85 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/MutationUpdateFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java @@ -1,15 +1,15 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; +package de.unistuttgart.iste.meitrex.flashcard_service.api; -import de.unistuttgart.iste.gits.common.testutil.GraphQlApiTest; -import de.unistuttgart.iste.gits.common.testutil.InjectCurrentUserHeader; -import de.unistuttgart.iste.gits.common.testutil.TablesToDelete; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; -import de.unistuttgart.iste.gits.generated.dto.Flashcard; -import de.unistuttgart.iste.gits.generated.dto.FlashcardSide; +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; +import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; +import de.unistuttgart.iste.meitrex.generated.dto.Flashcard; +import de.unistuttgart.iste.meitrex.generated.dto.FlashcardSide; import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -19,7 +19,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; import static org.assertj.core.api.Assertions.assertThat; @GraphQlApiTest @@ -47,13 +47,13 @@ void testUpdateFlashcard(final GraphQlTester tester) { final UUID setOfFlashcard = set.get(0).getAssessmentId(); // Perform the update operation - final UUID flashcardToUpdate = set.get(0).getFlashcards().stream().findAny().orElseThrow().getId(); + final UUID flashcardToUpdate = set.get(0).getFlashcards().stream().findAny().orElseThrow().getItemId(); final String query = """ mutation ($assessmentId: UUID!, $flashcardId: UUID!) { mutateFlashcardSet(assessmentId: $assessmentId) { - updateFlashcard(input: { - id: $flashcardId, + _internal_noauth_updateFlashcard(input: { + itemId: $flashcardId, sides: [ { label: "New_Side 1", @@ -69,7 +69,7 @@ void testUpdateFlashcard(final GraphQlTester tester) { } ] }) { - id + itemId sides { label isQuestion @@ -86,12 +86,12 @@ void testUpdateFlashcard(final GraphQlTester tester) { .variable("assessmentId", setOfFlashcard) .variable("flashcardId", flashcardToUpdate) .execute() - .path("mutateFlashcardSet.updateFlashcard") + .path("mutateFlashcardSet._internal_noauth_updateFlashcard") .entity(Flashcard.class) .get(); // Assert the values of the data returned by the updateFlashcard mutation - assertThat(updatedFlashcard.getId()).isEqualTo(flashcardToUpdate); + assertThat(updatedFlashcard.getItemId()).isEqualTo(flashcardToUpdate); assertThat(updatedFlashcard.getSides()).containsExactlyInAnyOrder( new FlashcardSide("{text: \"New_Question 1\"}", "New_Side 1", diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java similarity index 71% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java index de21d39..a580bb8 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java @@ -1,13 +1,13 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; +package de.unistuttgart.iste.meitrex.flashcard_service.api; -import de.unistuttgart.iste.gits.common.testutil.*; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser.UserRoleInCourse; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.*; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardProgressDataEntity.PrimaryKey; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardProgressDataRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; +import de.unistuttgart.iste.meitrex.common.testutil.*; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.*; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardProgressDataEntity.PrimaryKey; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardProgressDataRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.graphql.test.tester.GraphQlTester; @@ -16,7 +16,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; @GraphQlApiTest @TablesToDelete({"flashcard_side", "flashcard", "flashcard_set"}) @@ -50,22 +50,22 @@ void testDueFlashcardsByCourseId(final GraphQlTester tester) { flashcardProgressDataRepository.saveAll(List.of( // due FlashcardProgressDataEntity.builder() - .primaryKey(new PrimaryKey(flashCardsSet1.get(0).getId(), loggedInUser.getId())) + .primaryKey(new PrimaryKey(flashCardsSet1.get(0).getItemId(), loggedInUser.getId())) .nextLearn(OffsetDateTime.now().minusDays(2)) .build(), // not due FlashcardProgressDataEntity.builder() - .primaryKey(new PrimaryKey(flashCardsSet1.get(1).getId(), loggedInUser.getId())) + .primaryKey(new PrimaryKey(flashCardsSet1.get(1).getItemId(), loggedInUser.getId())) .nextLearn(null) .build(), // due FlashcardProgressDataEntity.builder() - .primaryKey(new PrimaryKey(flashCardsSet2.get(0).getId(), loggedInUser.getId())) + .primaryKey(new PrimaryKey(flashCardsSet2.get(0).getItemId(), loggedInUser.getId())) .nextLearn(OffsetDateTime.now().minusDays(1)) .build(), // not due FlashcardProgressDataEntity.builder() - .primaryKey(new PrimaryKey(flashCardsSet2.get(1).getId(), loggedInUser.getId())) + .primaryKey(new PrimaryKey(flashCardsSet2.get(1).getItemId(), loggedInUser.getId())) .nextLearn(OffsetDateTime.now().plusDays(1)) .build() )); @@ -84,6 +84,6 @@ void testDueFlashcardsByCourseId(final GraphQlTester tester) { .path("dueFlashcardsByCourseId[*].id") .entityList(UUID.class) .hasSize(2) - .contains(flashCardsSet1.get(0).getId(), flashCardsSet2.get(0).getId()); + .contains(flashCardsSet1.get(0).getItemId(), flashCardsSet2.get(0).getItemId()); } } diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryFlashcardSetTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardSetTest.java similarity index 76% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryFlashcardSetTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardSetTest.java index 1566484..86a59e7 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryFlashcardSetTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardSetTest.java @@ -1,13 +1,13 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; - -import de.unistuttgart.iste.gits.common.testutil.*; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser.UserRoleInCourse; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.mapper.FlashcardMapper; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; -import de.unistuttgart.iste.gits.generated.dto.FlashcardSet; +package de.unistuttgart.iste.meitrex.flashcard_service.api; + +import de.unistuttgart.iste.meitrex.common.testutil.*; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.mapper.FlashcardMapper; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; +import de.unistuttgart.iste.meitrex.generated.dto.FlashcardSet; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.graphql.test.tester.GraphQlTester; @@ -15,7 +15,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; import static org.assertj.core.api.Assertions.assertThat; @GraphQlApiTest @@ -47,7 +47,7 @@ void testFlashcardSetsByAssessmentIds(final GraphQlTester tester) { assessmentId, courseId, flashcards { - id, + itemId, sides { label, isQuestion, diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java similarity index 66% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryFlashcardTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java index 4fb6f71..a3f8fe2 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/QueryFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java @@ -1,14 +1,14 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; +package de.unistuttgart.iste.meitrex.flashcard_service.api; -import de.unistuttgart.iste.gits.common.testutil.*; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser.UserRoleInCourse; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.mapper.FlashcardMapper; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; -import de.unistuttgart.iste.gits.generated.dto.Flashcard; +import de.unistuttgart.iste.meitrex.common.testutil.*; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.mapper.FlashcardMapper; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; +import de.unistuttgart.iste.meitrex.generated.dto.Flashcard; import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,7 +17,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; import static org.assertj.core.api.Assertions.assertThat; @GraphQlApiTest @@ -49,8 +49,8 @@ void testQueryFlashcardsByIds(final GraphQlTester tester) { final String query = """ query($ids: [UUID!]!) { - flashcardsByIds(ids: $ids) { - id + flashcardsByIds(itemIds: $ids) { + itemId sides { label isQuestion @@ -62,7 +62,7 @@ void testQueryFlashcardsByIds(final GraphQlTester tester) { """; final List actualFlashcards = tester.document(query) - .variable("ids", flashcardsToQuery.stream().map(FlashcardEntity::getId)) + .variable("ids", flashcardsToQuery.stream().map(FlashcardEntity::getItemId)) .execute() .path("flashcardsByIds") .entityList(Flashcard.class) diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/TestAuthorization.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java similarity index 74% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/TestAuthorization.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java index 4f10305..4179eae 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/api/TestAuthorization.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java @@ -1,13 +1,13 @@ -package de.unistuttgart.iste.gits.flashcard_service.api; - -import de.unistuttgart.iste.gits.common.testutil.AuthorizationAsserts; -import de.unistuttgart.iste.gits.common.testutil.GraphQlApiTest; -import de.unistuttgart.iste.gits.common.testutil.InjectCurrentUserHeader; -import de.unistuttgart.iste.gits.common.testutil.TablesToDelete; -import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.test_utils.TestUtils; +package de.unistuttgart.iste.meitrex.flashcard_service.api; + +import de.unistuttgart.iste.meitrex.common.testutil.AuthorizationAsserts; +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; +import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; +import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,7 +17,7 @@ import java.util.List; import java.util.UUID; -import static de.unistuttgart.iste.gits.common.testutil.TestUsers.userWithMembershipInCourseWithId; +import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; @GraphQlApiTest @TablesToDelete({"flashcard_side", "flashcard", "flashcard_set"}) @@ -42,13 +42,13 @@ void testUpdateFlashcardOnlyForAdmins(final GraphQlTester tester) { final UUID setOfFlashcard = set.get(0).getAssessmentId(); // Perform the update operation - final UUID flashcardToUpdate = set.get(0).getFlashcards().stream().findAny().orElseThrow().getId(); + final UUID flashcardToUpdate = set.get(0).getFlashcards().stream().findAny().orElseThrow().getItemId(); final String query = """ mutation ($assessmentId: UUID!, $flashcardId: UUID!) { mutateFlashcardSet(assessmentId: $assessmentId) { updateFlashcard(input: { - id: $flashcardId, + itemId: $flashcardId, sides: [ { label: "New_Side 1", @@ -64,7 +64,7 @@ void testUpdateFlashcardOnlyForAdmins(final GraphQlTester tester) { } ] }) { - id + itemId sides { label isQuestion diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardServiceTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java similarity index 82% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardServiceTest.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java index d339549..15fa080 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/service/FlashcardServiceTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java @@ -1,13 +1,13 @@ -package de.unistuttgart.iste.gits.flashcard_service.service; - -import de.unistuttgart.iste.gits.common.event.ContentChangeEvent; -import de.unistuttgart.iste.gits.common.event.CrudOperation; -import de.unistuttgart.iste.gits.common.exception.IncompleteEventMessageException; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity; -import de.unistuttgart.iste.gits.flashcard_service.persistence.mapper.FlashcardMapper; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardRepository; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.gits.flashcard_service.validation.FlashcardValidator; +package de.unistuttgart.iste.meitrex.flashcard_service.service; +import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; +import de.unistuttgart.iste.meitrex.common.event.ContentChangeEvent; +import de.unistuttgart.iste.meitrex.common.event.CrudOperation; +import de.unistuttgart.iste.meitrex.common.exception.IncompleteEventMessageException; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.mapper.FlashcardMapper; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.validation.FlashcardValidator; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.modelmapper.ModelMapper; @@ -25,7 +25,9 @@ class FlashcardServiceTest { private final FlashcardSetRepository flashcardSetRepository = Mockito.mock(FlashcardSetRepository.class); private final FlashcardMapper flashcardMapper = new FlashcardMapper(new ModelMapper()); private final FlashcardValidator flashcardValidator = new FlashcardValidator(); - private final FlashcardService flashcardService = new FlashcardService(flashcardRepository, flashcardSetRepository, flashcardMapper, flashcardValidator); + + private final TopicPublisher topicPublisher = Mockito.mock(TopicPublisher.class); + private final FlashcardService flashcardService = new FlashcardService(flashcardRepository, flashcardSetRepository, flashcardMapper, flashcardValidator,topicPublisher); @Test void removeContentIds() { //init diff --git a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/test_utils/TestUtils.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java similarity index 89% rename from src/test/java/de/unistuttgart/iste/gits/flashcard_service/test_utils/TestUtils.java rename to src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java index db92a67..651ed6a 100644 --- a/src/test/java/de/unistuttgart/iste/gits/flashcard_service/test_utils/TestUtils.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java @@ -1,7 +1,7 @@ -package de.unistuttgart.iste.gits.flashcard_service.test_utils; +package de.unistuttgart.iste.meitrex.flashcard_service.test_utils; -import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.*; -import de.unistuttgart.iste.gits.flashcard_service.persistence.repository.FlashcardSetRepository; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.*; +import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; import jakarta.transaction.Transactional; import org.springframework.stereotype.Component; @@ -24,7 +24,7 @@ public List populateFlashcardSetRepository(FlashcardSetRepos set1.setCourseId(courseId); FlashcardEntity flashcard1 = new FlashcardEntity(); - flashcard1.setId(UUID.randomUUID()); + flashcard1.setItemId(UUID.randomUUID()); flashcard1.setParentSet(set1); flashcard1.setSides(List.of( new FlashcardSideEntity(UUID.randomUUID(), @@ -42,7 +42,7 @@ public List populateFlashcardSetRepository(FlashcardSetRepos )); FlashcardEntity flashcard2 = new FlashcardEntity(); - flashcard2.setId(UUID.randomUUID()); + flashcard2.setItemId(UUID.randomUUID()); flashcard2.setParentSet(set1); flashcard2.setSides(List.of( new FlashcardSideEntity(UUID.randomUUID(), @@ -66,7 +66,7 @@ public List populateFlashcardSetRepository(FlashcardSetRepos set2.setCourseId(courseId); FlashcardEntity flashcard3 = new FlashcardEntity(); - flashcard3.setId(UUID.randomUUID()); + flashcard3.setItemId(UUID.randomUUID()); flashcard3.setParentSet(set2); flashcard3.setSides(List.of( new FlashcardSideEntity(UUID.randomUUID(), @@ -84,7 +84,7 @@ public List populateFlashcardSetRepository(FlashcardSetRepos )); FlashcardEntity flashcard4 = new FlashcardEntity(); - flashcard4.setId(UUID.randomUUID()); + flashcard4.setItemId(UUID.randomUUID()); flashcard4.setParentSet(set2); flashcard4.setSides(List.of( new FlashcardSideEntity(UUID.randomUUID(), From e5cd3a063d680501128a00b42d226f3e3fd40f62 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:37:46 +0200 Subject: [PATCH 02/12] Adapted and fixed tests --- .../controller/FlashcardController.java | 7 ++++- .../repository/FlashcardRepository.java | 2 ++ .../service/FlashcardService.java | 1 + .../FlashcardUserProgressDataService.java | 31 +++++++++---------- .../graphql/service/flashcards.graphqls | 4 +++ .../graphql/service/mutation.graphqls | 7 +++++ .../api/MutationCreateFlashcardSetTest.java | 2 +- .../api/MutationCreateFlashcardTest.java | 6 ++-- .../api/MutationLogFlashcardProgressTest.java | 13 ++++++-- .../api/QueryDueFlashcardsByCourseIdTest.java | 4 +-- .../api/QueryFlashcardTest.java | 6 ++-- 11 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java index 4b7a893..63b817c 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java @@ -30,7 +30,7 @@ public class FlashcardController { private final FlashcardUserProgressDataService progressDataService; @QueryMapping - public List flashcardsByIds(@Argument(name = "ids") final List ids, + public List flashcardsByIds(@Argument(name = "itemIds") final List ids, @ContextValue final LoggedInUser currentUser) { final List courseIds = flashcardService.getCourseIdsForFlashcardIds(ids); @@ -94,6 +94,11 @@ public Flashcard _internal_noauth_updateFlashcard(@Argument(name = "input") fina return flashcardService.updateFlashcard(input); } + @SchemaMapping(typeName = "FlashcardSetMutation") + public Flashcard updateFlashcard(@Argument(name = "input") final UpdateFlashcardInput input) { + return flashcardService.updateFlashcard(input); + } + @SchemaMapping(typeName = "FlashcardSetMutation") public UUID deleteFlashcard(@Argument final UUID id, final FlashcardSetMutation mutation) { return flashcardService.deleteFlashcard(mutation.getAssessmentId(), id); diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java index 93e343f..37a7727 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardRepository.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; import java.util.UUID; @@ -17,4 +18,5 @@ public interface FlashcardRepository extends JpaRepository findByItemIdIn(List ids); + Optional findByItemId(UUID itemId); } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java index 6ad47e3..9abb0c8 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java @@ -118,6 +118,7 @@ public List getFlashcardsByIds(final List ids) { * @return list of course ids, in the same order as the flashcard ids. */ public List getCourseIdsForFlashcardIds(final List flashcardIds) { + System.out.println("Recieved"+flashcardIds); return flashcardRepository.findAllById(flashcardIds).stream() .map(FlashcardEntity::getParentSet) .map(FlashcardSetEntity::getCourseId) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index f87a78a..1095782 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -89,7 +89,7 @@ public FlashcardLearnedFeedback logFlashcardLearned(final UUID flashcardId, fina flashcardProgressDataRepository.save(progressData); final FlashcardSetEntity flashcardSetEntity = getFlashcardSetForFlashcard(flashcardId); - publishFlashcardSetLearned(userId, flashcardSetEntity.getAssessmentId()); + publishFlashcardSetLearned(userId, flashcardSetEntity.getAssessmentId(),flashcardId,successful); return createFeedback(progressData, successful, flashcardSetEntity, userId); } @@ -202,7 +202,7 @@ private FlashcardSetEntity getFlashcardSetForFlashcard(final UUID flashcardId) { return this.flashcardSetRepository.getReferenceById(flashcardEntity.getParentSet().getAssessmentId()); } - private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardSetId) { + private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardSetId, final UUID itemId,final boolean successful) { final FlashcardSetEntity flashcardSetEntity = flashcardSetRepository.getReferenceById(flashcardSetId); final List dataLogEntities = flashCardProgressDataLogRepository .findLatestLogsPerFlashcardProgressData(userId); @@ -226,25 +226,22 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS final int correct = dataLogs.stream().mapToInt(log -> log.getSuccess() ? 1 : 0).sum(); final float correctness = (float) correct / total; - List responses= new ArrayList(); - for(FlashcardProgressDataLogEntity log:dataLogEntities){ - float correctnes=0; - if(log.getSuccess()){ - correctnes=1; - } - Response response =Response.builder() - .itemId(log.getFlashcardProgressData().getPrimaryKey().getFlashcardID()) - .response(correctnes) - .build(); - responses.add(response); - } + flashcardSetEntity.setLastLearned(OffsetDateTime.now()); flashcardSetRepository.save(flashcardSetEntity); + float answer=0; + if(successful){ + answer=1F; + } + Response response=Response.builder() + .response(answer) + .itemId(itemId) + .build(); - publishUserProgressEvent(userId, flashcardSetId, correctness,responses); + publishUserProgressEvent(userId, flashcardSetId, correctness,response); } - private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness, final List responses) { + private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness, Response response) { topicPublisher.notifyUserWorkedOnContent( ContentProgressedEvent.builder() .contentId(assessmentId) @@ -253,7 +250,7 @@ private void publishUserProgressEvent(final UUID userId, final UUID assessmentId .success(true) .timeToComplete(null) .correctness(correctness) - .responses(responses) + .responses(List.of(response)) .build() ); } diff --git a/src/main/resources/graphql/service/flashcards.graphqls b/src/main/resources/graphql/service/flashcards.graphqls index 82006e2..bcc9967 100644 --- a/src/main/resources/graphql/service/flashcards.graphqls +++ b/src/main/resources/graphql/service/flashcards.graphqls @@ -77,6 +77,10 @@ type FlashcardSide { input CreateFlashcardInput { + """ + id of the item the flashcard belongs to + """ + itemId:UUID """ List of sides of this flashcard. Must be at least two sides. """ diff --git a/src/main/resources/graphql/service/mutation.graphqls b/src/main/resources/graphql/service/mutation.graphqls index 3432ce9..52941e3 100644 --- a/src/main/resources/graphql/service/mutation.graphqls +++ b/src/main/resources/graphql/service/mutation.graphqls @@ -51,6 +51,13 @@ type FlashcardSetMutation { """ _internal_noauth_updateFlashcard(input: UpdateFlashcardInput!): Flashcard! + """ + Updates a flashcard. Throws an error if the flashcard does not exist. + ⚠️ This mutation is only accessible internally in the system and allows the caller to update Flashcards without + any permissions check and should not be called without any validation of the caller's permissions. ⚠️ + """ + updateFlashcard(input: UpdateFlashcardInput!): Flashcard! + """ Deletes the flashcard with the specified ID. Throws an error if the flashcard does not exist. """ diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java index 514aeb7..9268477 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java @@ -29,7 +29,7 @@ void testCreateFlashcardSet(final GraphQlTester tester) { final UUID itemId2=UUID.randomUUID(); final String query = """ - mutation ($courseId: UUID!, $assessmentId: UUID!){ + mutation ($courseId: UUID!, $assessmentId: UUID!,$itemId1:UUID!,$itemId2:UUID!){ _internal_noauth_createFlashcardSet(courseId: $courseId, assessmentId: $assessmentId, input: { flashcards: [ { diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java index cc19559..401bcb7 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java @@ -46,7 +46,7 @@ void testCreateFlashcard(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); final UUID itemId=UUID.randomUUID(); final String query = """ - mutation ($setId: UUID!) { + mutation ($setId: UUID!,$itemId:UUID!) { mutateFlashcardSet(assessmentId: $setId) { _internal_noauth_createFlashcard(input: { itemId:$itemId, @@ -121,10 +121,10 @@ void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); final UUID itemId=UUID.randomUUID(); final String query = """ - mutation ($setId: UUID!) { + mutation ($setId: UUID!,$itemId:UUID!) { mutateFlashcardSet(assessmentId: $setId) { _internal_noauth_createFlashcard(input: { - itemId:$itemId, + itemId:$itemId sides: [ { label: "Side 11", diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java index d160601..af0ad7a 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java @@ -96,7 +96,7 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { .success(true) .timeToComplete(null) .hintsUsed(0) - .responses(List.of(Response.builder().itemId(flashcardId2).response(1).build())) + .responses(List.of(Response.builder().itemId(flashcardId2).response(0).build())) .build(); verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent); @@ -114,8 +114,17 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { runMutationLogFlashcardLearned(graphQlTester, flashcardId2, true) .errors().verify(); + final ContentProgressedEvent expectedEvent2 = ContentProgressedEvent.builder() + .userId(loggedInUser.getId()) + .contentId(flashcardSetId) + .correctness(1.0) + .success(true) + .timeToComplete(null) + .hintsUsed(0) + .responses(List.of(Response.builder().itemId(flashcardId2).response(1).build())) + .build(); - verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent); + verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent2); } @NotNull diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java index a580bb8..b2feb00 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryDueFlashcardsByCourseIdTest.java @@ -73,7 +73,7 @@ void testDueFlashcardsByCourseId(final GraphQlTester tester) { final String query = """ query($courseId: UUID!) { dueFlashcardsByCourseId(courseId: $courseId) { - id + itemId } } """; @@ -81,7 +81,7 @@ void testDueFlashcardsByCourseId(final GraphQlTester tester) { tester.document(query) .variable("courseId", courseId) .execute() - .path("dueFlashcardsByCourseId[*].id") + .path("dueFlashcardsByCourseId[*].itemId") .entityList(UUID.class) .hasSize(2) .contains(flashCardsSet1.get(0).getItemId(), flashCardsSet2.get(0).getItemId()); diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java index a3f8fe2..0920963 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java @@ -41,12 +41,14 @@ class QueryFlashcardTest { @Transactional void testQueryFlashcardsByIds(final GraphQlTester tester) { final List expectedSets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - + System.out.println( ("testId"+expectedSets.get(0).getFlashcards().get(0).getItemId())); + System.out.println( ("testId"+expectedSets.get(1).getFlashcards().get(1).getItemId())); final List flashcardsToQuery = List.of( expectedSets.get(0).getFlashcards().get(0), expectedSets.get(1).getFlashcards().get(1) ); - + Listids=List.of(expectedSets.get(0).getFlashcards().get(0).getItemId(),expectedSets.get(1).getFlashcards().get(1).getItemId()); + System.out.println(ids); final String query = """ query($ids: [UUID!]!) { flashcardsByIds(itemIds: $ids) { From b9bcaab07b7ca44bec5280af852ee9c1349ff18b Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Tue, 28 May 2024 14:31:02 +0200 Subject: [PATCH 03/12] Adapted FlashcardService --- Dockerfile | 2 +- build.gradle | 2 +- components/pubsub.yaml | 2 +- .../controller/SubscriptionController.java | 2 +- .../entity/FlashcardProgressDataEntity.java | 1 + .../service/FlashcardService.java | 1 - .../FlashcardUserProgressDataService.java | 25 +++++----- .../graphql/service/mutation.graphqls | 7 --- .../api/MutationLogFlashcardProgressTest.java | 4 +- .../api/QueryFlashcardTest.java | 3 -- .../api/TestAuthorization.java | 46 ++++--------------- 11 files changed, 28 insertions(+), 67 deletions(-) diff --git a/Dockerfile b/Dockerfile index f3529c4..555b7bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:experimental -FROM gradle:7.6.2-jdk17 AS build +FROM gradle:8-jdk21 AS build WORKDIR /workspace/app COPY . /workspace/app diff --git a/build.gradle b/build.gradle index 49f0d08..d5909c1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.+' + id 'org.springframework.boot' version '3.2.+' id 'io.spring.dependency-management' version '1.+' id "io.github.kobylynskyi.graphql.codegen" version "5.+" id "org.sonarqube" version "4.+" diff --git a/components/pubsub.yaml b/components/pubsub.yaml index 3b231c3..25b4fe0 100644 --- a/components/pubsub.yaml +++ b/components/pubsub.yaml @@ -1,7 +1,7 @@ apiVersion: dapr.io/v1alpha1 kind: Component metadata: - name: gits + name: meitrex spec: type: pubsub.redis version: v1 diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java index 219ccc2..32bec01 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/SubscriptionController.java @@ -19,7 +19,7 @@ public class SubscriptionController { private final FlashcardService flashcardService; - @Topic(name = "content-changed", pubsubName = "gits") + @Topic(name = "content-changed", pubsubName = "meitrex") @PostMapping(path = "/flashcard-service/content-changed-pubsub") public Mono updateAssociation(@RequestBody CloudEvent cloudEvent) { diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java index 42a366c..da8ba0f 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java @@ -11,6 +11,7 @@ @Entity(name = "FlashcardProgressData") @Data @Builder +@Getter @NoArgsConstructor @AllArgsConstructor public class FlashcardProgressDataEntity { diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java index 9abb0c8..6ad47e3 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java @@ -118,7 +118,6 @@ public List getFlashcardsByIds(final List ids) { * @return list of course ids, in the same order as the flashcard ids. */ public List getCourseIdsForFlashcardIds(final List flashcardIds) { - System.out.println("Recieved"+flashcardIds); return flashcardRepository.findAllById(flashcardIds).stream() .map(FlashcardEntity::getParentSet) .map(FlashcardSetEntity::getCourseId) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index 1095782..b8baeae 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -214,14 +214,20 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS if (dataLogEntities.size() < flashcardSetEntity.getFlashcards().size()) { // not all flashcards have been learned yet + return; } - + Listresponses=new ArrayList<>(); + for(FlashcardProgressDataLogEntity log:dataLogEntities){ + FlashcardProgressDataEntity progressDataEntity = log.getFlashcardProgressData(); + UUID flashcardID = progressDataEntity.getPrimaryKey().getFlashcardID(); + Response response=new Response(flashcardID,log.getSuccess()?1:0); + responses.add(response); + } final List dataLogs = dataLogEntities .stream() .map(this::mapLogEntityToDto) .toList(); - final int total = dataLogs.size(); final int correct = dataLogs.stream().mapToInt(log -> log.getSuccess() ? 1 : 0).sum(); @@ -229,19 +235,10 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS flashcardSetEntity.setLastLearned(OffsetDateTime.now()); flashcardSetRepository.save(flashcardSetEntity); - float answer=0; - if(successful){ - answer=1F; - } - Response response=Response.builder() - .response(answer) - .itemId(itemId) - .build(); - - publishUserProgressEvent(userId, flashcardSetId, correctness,response); + publishUserProgressEvent(userId, flashcardSetId, correctness,responses); } - private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness, Response response) { + private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness, List responses) { topicPublisher.notifyUserWorkedOnContent( ContentProgressedEvent.builder() .contentId(assessmentId) @@ -250,7 +247,7 @@ private void publishUserProgressEvent(final UUID userId, final UUID assessmentId .success(true) .timeToComplete(null) .correctness(correctness) - .responses(List.of(response)) + .responses(responses) .build() ); } diff --git a/src/main/resources/graphql/service/mutation.graphqls b/src/main/resources/graphql/service/mutation.graphqls index 52941e3..3432ce9 100644 --- a/src/main/resources/graphql/service/mutation.graphqls +++ b/src/main/resources/graphql/service/mutation.graphqls @@ -51,13 +51,6 @@ type FlashcardSetMutation { """ _internal_noauth_updateFlashcard(input: UpdateFlashcardInput!): Flashcard! - """ - Updates a flashcard. Throws an error if the flashcard does not exist. - ⚠️ This mutation is only accessible internally in the system and allows the caller to update Flashcards without - any permissions check and should not be called without any validation of the caller's permissions. ⚠️ - """ - updateFlashcard(input: UpdateFlashcardInput!): Flashcard! - """ Deletes the flashcard with the specified ID. Throws an error if the flashcard does not exist. """ diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java index af0ad7a..86a26cc 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java @@ -96,7 +96,7 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { .success(true) .timeToComplete(null) .hintsUsed(0) - .responses(List.of(Response.builder().itemId(flashcardId2).response(0).build())) + .responses(List.of(Response.builder().itemId(flashcardId1).response(1).build(),Response.builder().itemId(flashcardId2).response(0).build())) .build(); verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent); @@ -121,7 +121,7 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { .success(true) .timeToComplete(null) .hintsUsed(0) - .responses(List.of(Response.builder().itemId(flashcardId2).response(1).build())) + .responses(List.of(Response.builder().itemId(flashcardId1).response(1).build(),Response.builder().itemId(flashcardId2).response(1).build())) .build(); verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent2); diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java index 0920963..17135a7 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java @@ -41,14 +41,11 @@ class QueryFlashcardTest { @Transactional void testQueryFlashcardsByIds(final GraphQlTester tester) { final List expectedSets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - System.out.println( ("testId"+expectedSets.get(0).getFlashcards().get(0).getItemId())); - System.out.println( ("testId"+expectedSets.get(1).getFlashcards().get(1).getItemId())); final List flashcardsToQuery = List.of( expectedSets.get(0).getFlashcards().get(0), expectedSets.get(1).getFlashcards().get(1) ); Listids=List.of(expectedSets.get(0).getFlashcards().get(0).getItemId(),expectedSets.get(1).getFlashcards().get(1).getItemId()); - System.out.println(ids); final String query = """ query($ids: [UUID!]!) { flashcardsByIds(itemIds: $ids) { diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java index 4179eae..d3d642b 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java @@ -37,49 +37,23 @@ public class TestAuthorization { @Test @Transactional @Commit - void testUpdateFlashcardOnlyForAdmins(final GraphQlTester tester) { - final List set = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - - final UUID setOfFlashcard = set.get(0).getAssessmentId(); - // Perform the update operation - final UUID flashcardToUpdate = set.get(0).getFlashcards().stream().findAny().orElseThrow().getItemId(); + void testDeleteFlashcardOnlyForAdmins(final GraphQlTester tester) { + final List expectedSets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); final String query = """ - mutation ($assessmentId: UUID!, $flashcardId: UUID!) { + mutation($assessmentId: UUID!, $flashcardId: UUID!) { mutateFlashcardSet(assessmentId: $assessmentId) { - updateFlashcard(input: { - itemId: $flashcardId, - sides: [ - { - label: "New_Side 1", - isQuestion: true, - isAnswer: false, - text: "{text: \\"New_Question 1\\"}" - }, - { - label: "New_Side 2", - isQuestion: false, - isAnswer: true, - text: "{text: \\"New_Answer 1\\"}" - } - ] - }) { - itemId - sides { - label - isQuestion - isAnswer - text - } - } + deleteFlashcard(id: $flashcardId) } - } + } """; - // Execute the update mutation query + final UUID setToDeleteFrom = expectedSets.get(0).getAssessmentId(); + final UUID flashcardToDelete = expectedSets.get(0).getFlashcards().stream().findAny().orElseThrow().getItemId(); + tester.document(query) - .variable("assessmentId", setOfFlashcard) - .variable("flashcardId", flashcardToUpdate) + .variable("assessmentId", setToDeleteFrom) + .variable("flashcardId", flashcardToDelete) .execute() .errors() .satisfy(AuthorizationAsserts::assertIsMissingUserRoleError); From b149de1245dcc1146e0a0f9eb9d0b3582f561e0d Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:47:14 +0200 Subject: [PATCH 04/12] Reformated --- .../FlashcardServiceApplication.java | 1 - .../controller/FlashcardController.java | 2 +- .../repository/FlashcardSetRepository.java | 1 + .../repository/FlashcardSideRepository.java | 1 + .../service/FlashcardService.java | 12 +- .../FlashcardUserProgressDataService.java | 22 +-- .../validation/FlashcardValidator.java | 14 +- .../api/MutationCreateFlashcardSetTest.java | 112 +++++------ .../api/MutationCreateFlashcardTest.java | 182 +++++++++--------- .../api/MutationLogFlashcardProgressTest.java | 34 ++-- .../api/MutationUpdateFlashcardTest.java | 58 +++--- .../api/QueryFlashcardTest.java | 2 +- .../api/TestAuthorization.java | 2 +- .../service/FlashcardServiceTest.java | 5 +- .../test_utils/TestUtils.java | 1 + 15 files changed, 230 insertions(+), 219 deletions(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java index 3b894e1..e4cd13f 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/FlashcardServiceApplication.java @@ -4,7 +4,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; - /** * This is the entry point of the application. */ diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java index 63b817c..792cef7 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/controller/FlashcardController.java @@ -85,7 +85,7 @@ public FlashcardSetMutation mutateFlashcardSet(@Argument final UUID assessmentId @SchemaMapping(typeName = "FlashcardSetMutation") public Flashcard _internal_noauth_createFlashcard(@Argument(name = "input") final CreateFlashcardInput input, - final FlashcardSetMutation mutation) { + final FlashcardSetMutation mutation) { return flashcardService.createFlashcard(mutation.getAssessmentId(), input); } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java index 1580426..43da1da 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/repository/FlashcardSetRepository.java @@ -14,6 +14,7 @@ public interface FlashcardSetRepository extends MeitrexRepository, JpaSpecificationExecutor { diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java index 6ad47e3..e4900f8 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java @@ -100,7 +100,7 @@ public List getFlashcardsByIds(final List ids) { final List entities = flashcardRepository.findByItemIdIn(ids); ids.removeAll(entities.stream().map(FlashcardEntity::getItemId).toList()); - if(!ids.isEmpty()) { + if (!ids.isEmpty()) { throw new EntityNotFoundException("Flashcards with ids " + ids.stream().map(UUID::toString).collect(Collectors.joining(", ")) + " not found."); @@ -153,6 +153,7 @@ public void deleteFlashcardSetIfContentIsDeleted(final ContentChangeEvent dto) t flashcardSetRepository.deleteAllById(dto.getContentIds()); } + /** * helper function to make sure received event message is complete * @@ -170,17 +171,18 @@ private void checkCompletenessOfDto(final ContentChangeEvent dto) throws Incompl * @param itemId the id of the item */ private void publishItemChangeEvent(final UUID itemId) { - topicPublisher.notifyItemChanges(itemId,CrudOperation.DELETE); + topicPublisher.notifyItemChanges(itemId, CrudOperation.DELETE); } /** * for each flashcard of the deleted flashcard set publish a itemchanged event + * * @param flashcardSetId the id of the flashcardset to delete */ - private void publishDeletedFlashcardSet(UUID flashcardSetId){ - FlashcardSetEntity flashcardSet=flashcardSetRepository.findById(flashcardSetId).get(); - for(FlashcardEntity flashcard:flashcardSet.getFlashcards()){ + private void publishDeletedFlashcardSet(UUID flashcardSetId) { + FlashcardSetEntity flashcardSet = flashcardSetRepository.findById(flashcardSetId).get(); + for (FlashcardEntity flashcard : flashcardSet.getFlashcards()) { publishItemChangeEvent(flashcard.getItemId()); } } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index b8baeae..a7117ca 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -89,7 +89,7 @@ public FlashcardLearnedFeedback logFlashcardLearned(final UUID flashcardId, fina flashcardProgressDataRepository.save(progressData); final FlashcardSetEntity flashcardSetEntity = getFlashcardSetForFlashcard(flashcardId); - publishFlashcardSetLearned(userId, flashcardSetEntity.getAssessmentId(),flashcardId,successful); + publishFlashcardSetLearned(userId, flashcardSetEntity.getAssessmentId(), flashcardId, successful); return createFeedback(progressData, successful, flashcardSetEntity, userId); } @@ -159,15 +159,15 @@ private FlashcardLearnedFeedback createFeedback( } private static boolean wasLearnedSuccessful(final FlashcardProgressDataEntity progressData) { - List progress= progressData.getFlashcardProgressDataLogs(); - boolean success=progress.get(0).getSuccess(); - return success; + List progress = progressData.getFlashcardProgressDataLogs(); + boolean success = progress.get(0).getSuccess(); + return success; } private static boolean wasNotLearnedInCurrentIteration(final FlashcardSetEntity flashcardSetEntity, final FlashcardProgressDataEntity progressData) { return progressData.getLastLearned() == null - // if the flashcard was learned before the last time the set was learned, it was not learned in the current iteration - || progressData.getNextLearn().isBefore(flashcardSetEntity.getLastLearned().orElse(OffsetDateTime.MIN)); + // if the flashcard was learned before the last time the set was learned, it was not learned in the current iteration + || progressData.getNextLearn().isBefore(flashcardSetEntity.getLastLearned().orElse(OffsetDateTime.MIN)); } private void updateProgressDataEntity(final FlashcardProgressDataEntity progressData, final boolean success) { @@ -202,7 +202,7 @@ private FlashcardSetEntity getFlashcardSetForFlashcard(final UUID flashcardId) { return this.flashcardSetRepository.getReferenceById(flashcardEntity.getParentSet().getAssessmentId()); } - private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardSetId, final UUID itemId,final boolean successful) { + private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardSetId, final UUID itemId, final boolean successful) { final FlashcardSetEntity flashcardSetEntity = flashcardSetRepository.getReferenceById(flashcardSetId); final List dataLogEntities = flashCardProgressDataLogRepository .findLatestLogsPerFlashcardProgressData(userId); @@ -217,11 +217,11 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS return; } - Listresponses=new ArrayList<>(); - for(FlashcardProgressDataLogEntity log:dataLogEntities){ + List responses = new ArrayList<>(); + for (FlashcardProgressDataLogEntity log : dataLogEntities) { FlashcardProgressDataEntity progressDataEntity = log.getFlashcardProgressData(); UUID flashcardID = progressDataEntity.getPrimaryKey().getFlashcardID(); - Response response=new Response(flashcardID,log.getSuccess()?1:0); + Response response = new Response(flashcardID, log.getSuccess() ? 1 : 0); responses.add(response); } final List dataLogs = dataLogEntities @@ -235,7 +235,7 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS flashcardSetEntity.setLastLearned(OffsetDateTime.now()); flashcardSetRepository.save(flashcardSetEntity); - publishUserProgressEvent(userId, flashcardSetId, correctness,responses); + publishUserProgressEvent(userId, flashcardSetId, correctness, responses); } private void publishUserProgressEvent(final UUID userId, final UUID assessmentId, final float correctness, List responses) { diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java index 045430e..7f2838f 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/validation/FlashcardValidator.java @@ -11,6 +11,7 @@ public class FlashcardValidator { /** * validation function for newly created flashcard inputs + * * @param flashcardInput new flashcard input */ public void validateCreateFlashcardInput(CreateFlashcardInput flashcardInput) { @@ -19,10 +20,11 @@ public void validateCreateFlashcardInput(CreateFlashcardInput flashcardInput) { /** * validation of flashcard set inputs + * * @param flashcardSetInput a Flashcard-Set input */ public void validateCreateFlashcardSetInput(CreateFlashcardSetInput flashcardSetInput) { - for (CreateFlashcardInput flashcardInput: flashcardSetInput.getFlashcards()) { + for (CreateFlashcardInput flashcardInput : flashcardSetInput.getFlashcards()) { validateCreateFlashcardInput(flashcardInput); } } @@ -30,6 +32,7 @@ public void validateCreateFlashcardSetInput(CreateFlashcardSetInput flashcardSet /** * validation function for updated flashcard inputs + * * @param input an updated flashcard input */ public void validateUpdateFlashcardInput(UpdateFlashcardInput input) { @@ -38,23 +41,24 @@ public void validateUpdateFlashcardInput(UpdateFlashcardInput input) { /** * validates if flashcard has at least one side labeled as question and at least one side labeled as answer + * * @param flashcardSideInputs list of flashcard sides * @throws ValidationException if flashcard has no question or no answer or a side that is neither a question nor an answer */ private void validateSides(List flashcardSideInputs) { boolean hasQuestion = false; boolean hasAnswer = false; - for (FlashcardSideInput flashcardInputSide: flashcardSideInputs) { + for (FlashcardSideInput flashcardInputSide : flashcardSideInputs) { - if (flashcardInputSide.getIsQuestion()){ + if (flashcardInputSide.getIsQuestion()) { hasQuestion = true; } - if (flashcardInputSide.getIsAnswer()){ + if (flashcardInputSide.getIsAnswer()) { hasAnswer = true; } // finds invalid flashcard side - if ((!flashcardInputSide.getIsQuestion()) && (!flashcardInputSide.getIsAnswer())){ + if ((!flashcardInputSide.getIsQuestion()) && (!flashcardInputSide.getIsAnswer())) { throw new ValidationException("Flashcard side must must be at least a question or an answer"); } } diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java index 9268477..1b314d2 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardSetTest.java @@ -25,65 +25,65 @@ class MutationCreateFlashcardSetTest { void testCreateFlashcardSet(final GraphQlTester tester) { final UUID assessmentId = UUID.randomUUID(); final UUID courseId = UUID.randomUUID(); - final UUID itemId1= UUID.randomUUID(); - final UUID itemId2=UUID.randomUUID(); + final UUID itemId1 = UUID.randomUUID(); + final UUID itemId2 = UUID.randomUUID(); final String query = - """ - mutation ($courseId: UUID!, $assessmentId: UUID!,$itemId1:UUID!,$itemId2:UUID!){ - _internal_noauth_createFlashcardSet(courseId: $courseId, assessmentId: $assessmentId, input: { - flashcards: [ - { - itemId:$itemId1, - sides: [ - { - label: "Side 1", - isQuestion: true, - isAnswer: false, - text: "Question 1" - }, - { - label: "Side 2", - isQuestion: false, - isAnswer: true, - text: "Answer 1" + """ + mutation ($courseId: UUID!, $assessmentId: UUID!,$itemId1:UUID!,$itemId2:UUID!){ + _internal_noauth_createFlashcardSet(courseId: $courseId, assessmentId: $assessmentId, input: { + flashcards: [ + { + itemId:$itemId1, + sides: [ + { + label: "Side 1", + isQuestion: true, + isAnswer: false, + text: "Question 1" + }, + { + label: "Side 2", + isQuestion: false, + isAnswer: true, + text: "Answer 1" + } + ] + }, + { + itemId:$itemId2, + sides: [ + { + label: "Side 1", + isQuestion: true, + isAnswer: false, + text: "Question 2" + }, + { + label: "Side 2", + isQuestion: false, + isAnswer: true, + text: "Answer 2" + } + ] + } + ] } - ] - }, - { - itemId:$itemId2, - sides: [ - { - label: "Side 1", - isQuestion: true, - isAnswer: false, - text: "Question 2" - }, - { - label: "Side 2", - isQuestion: false, - isAnswer: true, - text: "Answer 2" - } - ] + ) + { + assessmentId + courseId + flashcards { + itemId + sides { + label + isQuestion + isAnswer + text + } + } + } } - ] - } - ) - { - assessmentId - courseId - flashcards { - itemId - sides { - label - isQuestion - isAnswer - text - } - } - } - } - """; + """; final FlashcardSet createdFlashcardSet = tester.document(query) .variable("assessmentId", assessmentId) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java index 401bcb7..9874d0c 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationCreateFlashcardTest.java @@ -44,38 +44,38 @@ class MutationCreateFlashcardTest { @Commit void testCreateFlashcard(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - final UUID itemId=UUID.randomUUID(); + final UUID itemId = UUID.randomUUID(); final String query = """ - mutation ($setId: UUID!,$itemId:UUID!) { - mutateFlashcardSet(assessmentId: $setId) { - _internal_noauth_createFlashcard(input: { - itemId:$itemId, - sides: [ - { - label: "Side 11", - isQuestion: true, - isAnswer: false, - text: "Question 1" - }, - { - label: "Side 21", - isQuestion: false, - isAnswer: true, - text: "Answer 1" + mutation ($setId: UUID!,$itemId:UUID!) { + mutateFlashcardSet(assessmentId: $setId) { + _internal_noauth_createFlashcard(input: { + itemId:$itemId, + sides: [ + { + label: "Side 11", + isQuestion: true, + isAnswer: false, + text: "Question 1" + }, + { + label: "Side 21", + isQuestion: false, + isAnswer: true, + text: "Answer 1" + } + ] + }) { + itemId + sides { + label + isQuestion + isAnswer + text + } + } + } } - ] - }) { - itemId - sides { - label - isQuestion - isAnswer - text - } - } - } - } - """; + """; final UUID setId = sets.get(0).getAssessmentId(); @@ -119,38 +119,38 @@ void testCreateFlashcard(final GraphQlTester graphQlTester) { @Test void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - final UUID itemId=UUID.randomUUID(); + final UUID itemId = UUID.randomUUID(); final String query = """ - mutation ($setId: UUID!,$itemId:UUID!) { - mutateFlashcardSet(assessmentId: $setId) { - _internal_noauth_createFlashcard(input: { - itemId:$itemId - sides: [ - { - label: "Side 11", - isQuestion: false, - isAnswer: true, - text: "Question 1" - }, - { - label: "Side 21", - isQuestion: false, - isAnswer: true, - text: "Answer 1" - } - ] - }) { - itemId - sides { - label - isQuestion - isAnswer - text + mutation ($setId: UUID!,$itemId:UUID!) { + mutateFlashcardSet(assessmentId: $setId) { + _internal_noauth_createFlashcard(input: { + itemId:$itemId + sides: [ + { + label: "Side 11", + isQuestion: false, + isAnswer: true, + text: "Question 1" + }, + { + label: "Side 21", + isQuestion: false, + isAnswer: true, + text: "Answer 1" + } + ] + }) { + itemId + sides { + label + isQuestion + isAnswer + text + } + } + } } - } - } - } - """; + """; final UUID setId = sets.get(0).getAssessmentId(); @@ -160,7 +160,7 @@ void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { .variable("itemId", itemId) .execute() .errors() - .expect(responseError -> responseError.getMessage() != null && responseError.getMessage().toLowerCase().contains("flashcards must have at least one question side and one answer side")); + .expect(responseError -> responseError.getMessage() != null && responseError.getMessage().toLowerCase().contains("flashcards must have at least one question side and one answer side")); } @@ -168,37 +168,37 @@ void testCreateInvalidFlashcard(final GraphQlTester graphQlTester) { @Test void testCreateInvalidFlashcardSide(final GraphQlTester graphQlTester) { final List sets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); - final UUID itemId=UUID.randomUUID(); + final UUID itemId = UUID.randomUUID(); final String query = """ - mutation ($setId: UUID!) { - mutateFlashcardSet(assessmentId: $setId) { - _internal_noauth_createFlashcard(input: { - sides: [ - { - label: "Side 11", - isQuestion: true, - isAnswer: false, - text: "Question 1" - }, - { - label: "Side 21", - isQuestion: false, - isAnswer: false, - text: "Answer 1" - } - ] - }) { - itemId - sides { - label - isQuestion - isAnswer - text + mutation ($setId: UUID!) { + mutateFlashcardSet(assessmentId: $setId) { + _internal_noauth_createFlashcard(input: { + sides: [ + { + label: "Side 11", + isQuestion: true, + isAnswer: false, + text: "Question 1" + }, + { + label: "Side 21", + isQuestion: false, + isAnswer: false, + text: "Answer 1" + } + ] + }) { + itemId + sides { + label + isQuestion + isAnswer + text + } + } + } } - } - } - } - """; + """; final UUID setId = sets.get(0).getAssessmentId(); @@ -208,7 +208,7 @@ void testCreateInvalidFlashcardSide(final GraphQlTester graphQlTester) { .variable("itemId", itemId) .execute() .errors() - .expect(responseError -> responseError.getMessage() != null && responseError.getMessage().toLowerCase().contains("flashcard side must must be at least a question or an answer")); + .expect(responseError -> responseError.getMessage() != null && responseError.getMessage().toLowerCase().contains("flashcard side must must be at least a question or an answer")); } diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java index 86a26cc..95dbd1c 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java @@ -42,23 +42,23 @@ class MutationLogFlashcardProgressTest { private final LoggedInUser loggedInUser = userWithMembershipInCourseWithId(courseId, LoggedInUser.UserRoleInCourse.ADMINISTRATOR); private static final String mutation = """ - mutation logFlashcardProgress($id: UUID!, $successful: Boolean!) { - logFlashcardLearned( - input: { - flashcardId: $id, - successful: $successful - } - ) { - success - nextLearnDate - flashcardSetProgress { - correctness - percentageLearned - } + mutation logFlashcardProgress($id: UUID!, $successful: Boolean!) { + logFlashcardLearned( + input: { + flashcardId: $id, + successful: $successful + } + ) { + success + nextLearnDate + flashcardSetProgress { + correctness + percentageLearned } - } - """; + + } + """; /** * Tests that the mutation "logFlashcardProgress" works as expected @@ -96,7 +96,7 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { .success(true) .timeToComplete(null) .hintsUsed(0) - .responses(List.of(Response.builder().itemId(flashcardId1).response(1).build(),Response.builder().itemId(flashcardId2).response(0).build())) + .responses(List.of(Response.builder().itemId(flashcardId1).response(1).build(), Response.builder().itemId(flashcardId2).response(0).build())) .build(); verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent); @@ -121,7 +121,7 @@ void testLogFlashcardProgress(final HttpGraphQlTester graphQlTester) { .success(true) .timeToComplete(null) .hintsUsed(0) - .responses(List.of(Response.builder().itemId(flashcardId1).response(1).build(),Response.builder().itemId(flashcardId2).response(1).build())) + .responses(List.of(Response.builder().itemId(flashcardId1).response(1).build(), Response.builder().itemId(flashcardId2).response(1).build())) .build(); verify(topicPublisher).notifyUserWorkedOnContent(expectedEvent2); diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java index 5e82d85..d7adc46 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationUpdateFlashcardTest.java @@ -50,36 +50,36 @@ void testUpdateFlashcard(final GraphQlTester tester) { final UUID flashcardToUpdate = set.get(0).getFlashcards().stream().findAny().orElseThrow().getItemId(); final String query = """ - mutation ($assessmentId: UUID!, $flashcardId: UUID!) { - mutateFlashcardSet(assessmentId: $assessmentId) { - _internal_noauth_updateFlashcard(input: { - itemId: $flashcardId, - sides: [ - { - label: "New_Side 1", - isQuestion: true, - isAnswer: false, - text: "{text: \\"New_Question 1\\"}" - }, - { - label: "New_Side 2", - isQuestion: false, - isAnswer: true, - text: "{text: \\"New_Answer 1\\"}" + mutation ($assessmentId: UUID!, $flashcardId: UUID!) { + mutateFlashcardSet(assessmentId: $assessmentId) { + _internal_noauth_updateFlashcard(input: { + itemId: $flashcardId, + sides: [ + { + label: "New_Side 1", + isQuestion: true, + isAnswer: false, + text: "{text: \\"New_Question 1\\"}" + }, + { + label: "New_Side 2", + isQuestion: false, + isAnswer: true, + text: "{text: \\"New_Answer 1\\"}" + } + ] + }) { + itemId + sides { + label + isQuestion + isAnswer + text + } + } + } } - ] - }) { - itemId - sides { - label - isQuestion - isAnswer - text - } - } - } - } - """; + """; // Execute the update mutation query final Flashcard updatedFlashcard = tester.document(query) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java index 17135a7..1a76398 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java @@ -45,7 +45,7 @@ void testQueryFlashcardsByIds(final GraphQlTester tester) { expectedSets.get(0).getFlashcards().get(0), expectedSets.get(1).getFlashcards().get(1) ); - Listids=List.of(expectedSets.get(0).getFlashcards().get(0).getItemId(),expectedSets.get(1).getFlashcards().get(1).getItemId()); + List ids = List.of(expectedSets.get(0).getFlashcards().get(0).getItemId(), expectedSets.get(1).getFlashcards().get(1).getItemId()); final String query = """ query($ids: [UUID!]!) { flashcardsByIds(itemIds: $ids) { diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java index d3d642b..3844aec 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java @@ -38,7 +38,7 @@ public class TestAuthorization { @Transactional @Commit void testDeleteFlashcardOnlyForAdmins(final GraphQlTester tester) { - final List expectedSets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); + final List expectedSets = testUtils.populateFlashcardSetRepository(flashcardSetRepository, courseId); final String query = """ mutation($assessmentId: UUID!, $flashcardId: UUID!) { diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java index 15fa080..202854d 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardServiceTest.java @@ -1,4 +1,5 @@ package de.unistuttgart.iste.meitrex.flashcard_service.service; + import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; import de.unistuttgart.iste.meitrex.common.event.ContentChangeEvent; import de.unistuttgart.iste.meitrex.common.event.CrudOperation; @@ -27,7 +28,8 @@ class FlashcardServiceTest { private final FlashcardValidator flashcardValidator = new FlashcardValidator(); private final TopicPublisher topicPublisher = Mockito.mock(TopicPublisher.class); - private final FlashcardService flashcardService = new FlashcardService(flashcardRepository, flashcardSetRepository, flashcardMapper, flashcardValidator,topicPublisher); + private final FlashcardService flashcardService = new FlashcardService(flashcardRepository, flashcardSetRepository, flashcardMapper, flashcardValidator, topicPublisher); + @Test void removeContentIds() { //init @@ -51,6 +53,7 @@ void removeContentIds() { assertDoesNotThrow(() -> flashcardService.deleteFlashcardSetIfContentIsDeleted(contentChangeEvent)); verify(flashcardSetRepository, times(1)).deleteAllById(any()); } + @Test void removeContentIdsWithNoIdsToBeRemovedTest() { //init diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java index 651ed6a..0c18a70 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/test_utils/TestUtils.java @@ -13,6 +13,7 @@ public class TestUtils { /** * Helper method which creates some flashcard sets and saves them to the repository. + * * @param repo The repository to save the flashcard sets to. * @return Returns the created flashcard sets. */ From 8774c4c33b95ce0d63daf6c6793ae663c79b7288 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:10:56 +0200 Subject: [PATCH 05/12] Fixed SonarCubeComments --- .../flashcard_service/service/FlashcardService.java | 10 +++++++--- .../service/FlashcardUserProgressDataService.java | 7 +++---- .../flashcard_service/api/QueryFlashcardTest.java | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java index e4900f8..d956ec6 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardService.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -181,9 +182,12 @@ private void publishItemChangeEvent(final UUID itemId) { * @param flashcardSetId the id of the flashcardset to delete */ private void publishDeletedFlashcardSet(UUID flashcardSetId) { - FlashcardSetEntity flashcardSet = flashcardSetRepository.findById(flashcardSetId).get(); - for (FlashcardEntity flashcard : flashcardSet.getFlashcards()) { - publishItemChangeEvent(flashcard.getItemId()); + Optional flashcardSetOptional = flashcardSetRepository.findById(flashcardSetId); + if(flashcardSetOptional.isPresent()){ + FlashcardSetEntity flashcardSet=flashcardSetOptional.get(); + for (FlashcardEntity flashcard : flashcardSet.getFlashcards()) { + publishItemChangeEvent(flashcard.getItemId()); + } } } } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index a7117ca..079c8f1 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -89,7 +89,7 @@ public FlashcardLearnedFeedback logFlashcardLearned(final UUID flashcardId, fina flashcardProgressDataRepository.save(progressData); final FlashcardSetEntity flashcardSetEntity = getFlashcardSetForFlashcard(flashcardId); - publishFlashcardSetLearned(userId, flashcardSetEntity.getAssessmentId(), flashcardId, successful); + publishFlashcardSetLearned(userId, flashcardSetEntity.getAssessmentId()); return createFeedback(progressData, successful, flashcardSetEntity, userId); } @@ -160,8 +160,7 @@ private FlashcardLearnedFeedback createFeedback( private static boolean wasLearnedSuccessful(final FlashcardProgressDataEntity progressData) { List progress = progressData.getFlashcardProgressDataLogs(); - boolean success = progress.get(0).getSuccess(); - return success; + return progress.get(0).getSuccess(); } private static boolean wasNotLearnedInCurrentIteration(final FlashcardSetEntity flashcardSetEntity, final FlashcardProgressDataEntity progressData) { @@ -202,7 +201,7 @@ private FlashcardSetEntity getFlashcardSetForFlashcard(final UUID flashcardId) { return this.flashcardSetRepository.getReferenceById(flashcardEntity.getParentSet().getAssessmentId()); } - private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardSetId, final UUID itemId, final boolean successful) { + private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardSetId) { final FlashcardSetEntity flashcardSetEntity = flashcardSetRepository.getReferenceById(flashcardSetId); final List dataLogEntities = flashCardProgressDataLogRepository .findLatestLogsPerFlashcardProgressData(userId); diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java index 1a76398..0001914 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/QueryFlashcardTest.java @@ -45,7 +45,6 @@ void testQueryFlashcardsByIds(final GraphQlTester tester) { expectedSets.get(0).getFlashcards().get(0), expectedSets.get(1).getFlashcards().get(1) ); - List ids = List.of(expectedSets.get(0).getFlashcards().get(0).getItemId(), expectedSets.get(1).getFlashcards().get(1).getItemId()); final String query = """ query($ids: [UUID!]!) { flashcardsByIds(itemIds: $ids) { From debb0022bb68260bf50a140bddb6eb8c39a18ce6 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:45:57 +0200 Subject: [PATCH 06/12] Added getter --- .../persistence/entity/FlashcardProgressDataEntity.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java index e94f1cb..da8ba0f 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/persistence/entity/FlashcardProgressDataEntity.java @@ -1,10 +1,7 @@ package de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.io.Serializable; import java.time.OffsetDateTime; From 72626627b4563dd356b60ce2da7da7b1f02a9cfa Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:49:45 +0200 Subject: [PATCH 07/12] Fixed TestAuthorization --- .../api/TestAuthorization.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java index 1508071..0f006ce 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/TestAuthorization.java @@ -1,24 +1,13 @@ package de.unistuttgart.iste.meitrex.flashcard_service.api; - -import de.unistuttgart.iste.meitrex.common.testutil.AuthorizationAsserts; - import de.unistuttgart.iste.meitrex.common.testutil.AuthorizationAsserts; - import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; import de.unistuttgart.iste.meitrex.common.testutil.TablesToDelete; import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; - import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; -import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardRepository; -import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; -import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; -import de.unistuttgart.iste.meitrex.generated.dto.Flashcard; -import de.unistuttgart.iste.meitrex.generated.dto.FlashcardSide; - import jakarta.transaction.Transactional; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -30,28 +19,18 @@ import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; - @GraphQlApiTest @TablesToDelete({"flashcard_side", "flashcard", "flashcard_set"}) public class TestAuthorization { - - -@GraphQlApiTest -@TablesToDelete({"flashcard_side", "flashcard", "flashcard_set"}) -class MutationUpdateFlashcardTest { - - @Autowired private FlashcardSetRepository flashcardSetRepository; - private final UUID courseId = UUID.randomUUID(); @InjectCurrentUserHeader private final LoggedInUser loggedInUser = userWithMembershipInCourseWithId(courseId, LoggedInUser.UserRoleInCourse.STUDENT); - @Autowired private TestUtils testUtils; From 500fd2d3dd1c54091f8b18f859232dfbe2b72b5f Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:00:53 +0200 Subject: [PATCH 08/12] Fixed error --- .../flashcard_service/api/MutationLogFlashcardProgressTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java index ee88ac3..0258d66 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java @@ -139,4 +139,4 @@ private static GraphQlTester.Response runMutationLogFlashcardLearned(final HttpG .variable("successful", success) .execute(); } -} +} \ No newline at end of file From 8886a195016ba66c863bc1fe8863e8239a786b50 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:11:55 +0200 Subject: [PATCH 09/12] Try to fix test --- .../flashcard_service/api/MutationLogFlashcardProgressTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java index 0258d66..d5ce1b5 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/flashcard_service/api/MutationLogFlashcardProgressTest.java @@ -2,11 +2,9 @@ import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher; import de.unistuttgart.iste.meitrex.common.event.ContentProgressedEvent; - import de.unistuttgart.iste.meitrex.common.testutil.*; import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; import de.unistuttgart.iste.meitrex.common.event.Response; - import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity; import de.unistuttgart.iste.meitrex.flashcard_service.persistence.repository.FlashcardSetRepository; import de.unistuttgart.iste.meitrex.flashcard_service.test_utils.TestUtils; From 5f254c91a75071c437b04afd05f2c2c76c8d925b Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:29:54 +0200 Subject: [PATCH 10/12] added sorting --- .../service/FlashcardUserProgressDataService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index cd6ce6c..2dcba30 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -14,6 +14,7 @@ import java.time.OffsetDateTime; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.UUID; import java.util.stream.Stream; @@ -220,6 +221,7 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS return; } List responses = new ArrayList<>(); + dataLogEntities.sort(Comparator.comparing(FlashcardProgressDataLogEntity::getLastLearned)); for (FlashcardProgressDataLogEntity log : dataLogEntities) { FlashcardProgressDataEntity progressDataEntity = log.getFlashcardProgressData(); UUID flashcardID = progressDataEntity.getPrimaryKey().getFlashcardID(); From c97a8eaddf4447ebb255a92140e89a99eb13fec4 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:34:02 +0200 Subject: [PATCH 11/12] removed sort --- .../service/FlashcardUserProgressDataService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java index 2dcba30..86b90f9 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/flashcard_service/service/FlashcardUserProgressDataService.java @@ -221,7 +221,6 @@ private void publishFlashcardSetLearned(final UUID userId, final UUID flashcardS return; } List responses = new ArrayList<>(); - dataLogEntities.sort(Comparator.comparing(FlashcardProgressDataLogEntity::getLastLearned)); for (FlashcardProgressDataLogEntity log : dataLogEntities) { FlashcardProgressDataEntity progressDataEntity = log.getFlashcardProgressData(); UUID flashcardID = progressDataEntity.getPrimaryKey().getFlashcardID(); From 721dcddc5f45bb08541b21b5bf1a99e8b374dab5 Mon Sep 17 00:00:00 2001 From: Tessa Keller <117365470+TessaKeller@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:36:00 +0200 Subject: [PATCH 12/12] Added new releases --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c2880dd..772e0fb 100644 --- a/build.gradle +++ b/build.gradle @@ -110,7 +110,7 @@ repositories { } dependencies { - implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.1.1' + implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.2' implementation 'com.google.code.findbugs:jsr305:3.0.2' // removes a gradle warning about an unknown annotation implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-graphql' @@ -127,7 +127,7 @@ dependencies { runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.0.1' + testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.2' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework:spring-webflux' testImplementation 'org.springframework.graphql:spring-graphql-test'