From 85c16cc0331643c0f7f9fb4fa459697393adfe38 Mon Sep 17 00:00:00 2001 From: "julian.lxs" Date: Thu, 10 Oct 2024 12:15:31 +0200 Subject: [PATCH] add gradings in schema and entities --- .../entity/ExerciseGradingEntity.java | 42 ++++++++++++ .../persistence/entity/GradingEntity.java | 46 +++++++++++++ .../entity/SubexerciseGradingEntity.java | 36 ++++++++++ .../graphql/service/grading.graphqls | 68 +++++++++++++++++++ .../resources/graphql/service/query.graphqls | 8 +++ 5 files changed, 200 insertions(+) create mode 100644 src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/ExerciseGradingEntity.java create mode 100644 src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/GradingEntity.java create mode 100644 src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/SubexerciseGradingEntity.java create mode 100644 src/main/resources/graphql/service/grading.graphqls diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/ExerciseGradingEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/ExerciseGradingEntity.java new file mode 100644 index 0000000..6025850 --- /dev/null +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/ExerciseGradingEntity.java @@ -0,0 +1,42 @@ +package de.unistuttgart.iste.meitrex.assignment_service.persistence.entity; + +import jakarta.persistence.*; +import lombok.*; + +import java.io.Serializable; +import java.util.List; +import java.util.UUID; + +@Entity(name = "ExerciseGrading") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExerciseGradingEntity { + + @EmbeddedId + private PrimaryKey primaryKey; + + @Column(nullable = false) + private double achievedCredits; + + @Column(nullable = false) + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "parentExerciseGrading") + private List subexerciseGradings; + + @ManyToOne + @EqualsAndHashCode.Exclude + @ToString.Exclude + private GradingEntity parentGrading; + + @Data + @Embeddable + @NoArgsConstructor + @AllArgsConstructor + public static class PrimaryKey implements Serializable { + private UUID assessmentId; + private UUID userId; + + } + +} \ No newline at end of file diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/GradingEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/GradingEntity.java new file mode 100644 index 0000000..0adf80c --- /dev/null +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/GradingEntity.java @@ -0,0 +1,46 @@ +package de.unistuttgart.iste.meitrex.assignment_service.persistence.entity; + + +import de.unistuttgart.iste.meitrex.generated.dto.ExerciseGrading; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.OffsetDateTime; +import java.util.List; +import java.util.UUID; + +@Entity(name = "Grading") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class GradingEntity { + + @EmbeddedId + private PrimaryKey primaryKey; + + @Column(nullable = false) + private OffsetDateTime date; + + @Column(nullable = false) + private double achievedCredits; + + @Column(nullable = false) + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "parentGrading") + private List exerciseGradings; + + @Data + @Embeddable + @NoArgsConstructor + @AllArgsConstructor + public static class PrimaryKey implements Serializable { + private UUID assessmentId; + private UUID userId; + + } + +} diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/SubexerciseGradingEntity.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/SubexerciseGradingEntity.java new file mode 100644 index 0000000..e5cb5b7 --- /dev/null +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/persistence/entity/SubexerciseGradingEntity.java @@ -0,0 +1,36 @@ +package de.unistuttgart.iste.meitrex.assignment_service.persistence.entity; + +import jakarta.persistence.*; +import lombok.*; + +import java.io.Serializable; +import java.util.UUID; + +@Entity(name = "SubexerciseGrading") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SubexerciseGradingEntity { + + @EmbeddedId + private PrimaryKey primaryKey; + + @Column(nullable = false) + private double achievedCredits; + + @ManyToOne + @EqualsAndHashCode.Exclude + @ToString.Exclude + private GradingEntity parentExerciseGrading; + + @Data + @Embeddable + @NoArgsConstructor + @AllArgsConstructor + public static class PrimaryKey implements Serializable { + private UUID assessmentId; + private UUID userId; + + } +} diff --git a/src/main/resources/graphql/service/grading.graphqls b/src/main/resources/graphql/service/grading.graphqls new file mode 100644 index 0000000..10ec30c --- /dev/null +++ b/src/main/resources/graphql/service/grading.graphqls @@ -0,0 +1,68 @@ +""" +A grading contains a user's achieved credits on an assignment and its exercises and subexercises. +""" +type Grading { + """ + ID of the assignment. + """ + assessmentId: UUID! + + """ + ID of the user the grading belongs to. + """ + userId: UUID! + + """ + The date and time of when the tutor corrected the assignment. + """ + date: DateTime! + + """ + The absolute number of achieved credits on the assignment. + """ + achievedCredits: Float! + + """ + List of exercise-gradings for each exercise in the assignment. Can be empty, if there are no exercises within the assignment. + """ + exerciseGradings: [ExerciseGrading]! +} + +type ExerciseGrading { + """ + ID of the exercise. + """ + itemId: UUID! + + """ + ID of the user the exercise-grading belongs to. + """ + userId: UUID! + + """ + The absolute number of achieved credits on the exercise. + """ + achievedCredits: Float! + + """ + List of subexercise-gradings for each subexercise in the exercise. Can be empty, if there are no subexercises within the exercise. + """ + subexerciseGradings: [SubexerciseGrading]! +} + +type SubexerciseGrading { + """ + ID of the subexercise. + """ + itemId: UUID! + + """ + ID of the user the subexercise-grading belongs to. + """ + userId: UUID! + + """ + The absolute number of achieved credits on the subexercise. + """ + achievedCredits: Float! +} \ No newline at end of file diff --git a/src/main/resources/graphql/service/query.graphqls b/src/main/resources/graphql/service/query.graphqls index 57fa0a9..726be3e 100644 --- a/src/main/resources/graphql/service/query.graphqls +++ b/src/main/resources/graphql/service/query.graphqls @@ -6,4 +6,12 @@ type Query { an assignment if the user has no access to it. """ findAssignmentsByAssessmentIds(assessmentIds: [UUID!]!): [Assignment]! + + + """ + Get a grading for one assignment for one student + 🔒 The user must be enrolled in the course the assignment belong to to access them. Otherwise null is returned for + an assignment if the user has no access to it. + """ + getGradingForAssignmentForStudent(assessmentId: UUID!, userId: UUID!): Grading! }