From b95f714b05285522d03e8b7c9dd1daabc611e542 Mon Sep 17 00:00:00 2001 From: Youcef Boumar <34604972+youcefs21@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:31:46 -0400 Subject: [PATCH] PR#1 of issue #2 (#28) * PR#1 of issue #2 - Fixed up the `AssignmentEnrollment` entity - Created `AssignmentEnrollmentRepository` - Created `AssignmentEnrollmentPage` model - added test data to `bootstrap_data.sql` * Fixed some things for PR#1 of issue #2 - Renamed the assignment associated with AssignmentEnrollment from "course" to "assignment - Added a JsonIgnore tag to the ID in AssignmentEnrollment - Added a USER_ID variable to bootstrap_data.sql for ease of testing - Added a 2 more test cases to Assignment enrolment in bootstrap_data --- .../entity/AssignmentEnrollment.java | 13 +++++++++---- .../api/response/page/AssignmentEnrollmentPage.java | 12 ++++++++++++ .../repository/AssignmentEnrollmentRepository.java | 11 +++++++++++ src/main/resources/db/h2/bootstrap_data.sql | 13 +++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/unityTest/courseManagement/models/api/response/page/AssignmentEnrollmentPage.java create mode 100644 src/main/java/com/unityTest/courseManagement/repository/AssignmentEnrollmentRepository.java diff --git a/src/main/java/com/unityTest/courseManagement/entity/AssignmentEnrollment.java b/src/main/java/com/unityTest/courseManagement/entity/AssignmentEnrollment.java index 389231b..2349d46 100644 --- a/src/main/java/com/unityTest/courseManagement/entity/AssignmentEnrollment.java +++ b/src/main/java/com/unityTest/courseManagement/entity/AssignmentEnrollment.java @@ -3,7 +3,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.RequiredArgsConstructor; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; @@ -12,6 +14,8 @@ * Models the enrollment of a user in a course */ @Data +@RequiredArgsConstructor +@AllArgsConstructor @ApiModel(value = "AssignmentEnrollment", description = "Enrollment of a user in a assignment") @Entity @Table(name = "ASSIGNMENT_ENROLLMENT") @@ -19,6 +23,7 @@ public class AssignmentEnrollment { @Id @Column(name = "ID") + @JsonIgnore @GeneratedValue(generator = "sequence-generator") @GenericGenerator( name = "sequence-generator", @@ -30,10 +35,10 @@ public class AssignmentEnrollment { private int id; // Assignment user is enrolled in - // @ApiModelProperty(value = "Enrolled assignment") - // @ManyToOne(fetch = FetchType.LAZY) - // @JoinColumn(name = "ASSIGNMENT_ID", referencedColumnName = "ID") - // private Assignment course; + @ApiModelProperty(value = "Enrolled assignment") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "ASSIGNMENT_ID", referencedColumnName = "ID") + private Assignment assignment; // User id @JsonIgnore diff --git a/src/main/java/com/unityTest/courseManagement/models/api/response/page/AssignmentEnrollmentPage.java b/src/main/java/com/unityTest/courseManagement/models/api/response/page/AssignmentEnrollmentPage.java new file mode 100644 index 0000000..42866be --- /dev/null +++ b/src/main/java/com/unityTest/courseManagement/models/api/response/page/AssignmentEnrollmentPage.java @@ -0,0 +1,12 @@ +package com.unityTest.courseManagement.models.api.response.page; + +import com.unityTest.courseManagement.entity.AssignmentEnrollment; +import io.swagger.annotations.ApiModel; +import org.springframework.data.domain.Page; + +@ApiModel(value = "AssignmentEnrollmentPage", description = "Page request for enrollment of assignments") +public class AssignmentEnrollmentPage extends BasePage { + public AssignmentEnrollmentPage(Page page) { + super(page); + } +} diff --git a/src/main/java/com/unityTest/courseManagement/repository/AssignmentEnrollmentRepository.java b/src/main/java/com/unityTest/courseManagement/repository/AssignmentEnrollmentRepository.java new file mode 100644 index 0000000..df5cd8e --- /dev/null +++ b/src/main/java/com/unityTest/courseManagement/repository/AssignmentEnrollmentRepository.java @@ -0,0 +1,11 @@ +package com.unityTest.courseManagement.repository; + +import com.unityTest.courseManagement.entity.AssignmentEnrollment; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; + +@Repository +public interface AssignmentEnrollmentRepository + extends JpaRepository, JpaSpecificationExecutor { +} diff --git a/src/main/resources/db/h2/bootstrap_data.sql b/src/main/resources/db/h2/bootstrap_data.sql index 7d35924..feb2167 100644 --- a/src/main/resources/db/h2/bootstrap_data.sql +++ b/src/main/resources/db/h2/bootstrap_data.sql @@ -1,3 +1,6 @@ + +SET @USER_ID = 'TEST_ID'; + INSERT INTO COURSE (ID, CODE, LEVEL, TERM, ACADEMIC_YEAR) VALUES (1, 'COMPSCI 1JC3', 1, 'FALL', 2019), @@ -63,3 +66,13 @@ VALUES (2, 'CASE', 1000, 'X02', 'How about being positive? :smile:', 0), (3, 'CASE', 1001, 'X03', 'Should we have done this instead? `x = 3`?', 1); + +INSERT INTO ASSIGNMENT_ENROLLMENT (ID, ASSIGNMENT_ID, USER_ID, PINNED) +VALUES +(1, 1, 'X01', false), +(2, 2, 'X02', false), +(3, 1, 'X02', true), +(4, 2, 'X01', true), +(5, 1, 'X03', false), +(6, 1, @USER_ID, false), +(7, 2, @USER_ID, true);