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);