Skip to content

Commit b95f714

Browse files
authored
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
1 parent 9b1b5d4 commit b95f714

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

src/main/java/com/unityTest/courseManagement/entity/AssignmentEnrollment.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import io.swagger.annotations.ApiModel;
55
import io.swagger.annotations.ApiModelProperty;
6+
import lombok.AllArgsConstructor;
67
import lombok.Data;
8+
import lombok.RequiredArgsConstructor;
79
import org.hibernate.annotations.GenericGenerator;
810

911
import javax.persistence.*;
@@ -12,13 +14,16 @@
1214
* Models the enrollment of a user in a course
1315
*/
1416
@Data
17+
@RequiredArgsConstructor
18+
@AllArgsConstructor
1519
@ApiModel(value = "AssignmentEnrollment", description = "Enrollment of a user in a assignment")
1620
@Entity
1721
@Table(name = "ASSIGNMENT_ENROLLMENT")
1822
public class AssignmentEnrollment {
1923

2024
@Id
2125
@Column(name = "ID")
26+
@JsonIgnore
2227
@GeneratedValue(generator = "sequence-generator")
2328
@GenericGenerator(
2429
name = "sequence-generator",
@@ -30,10 +35,10 @@ public class AssignmentEnrollment {
3035
private int id;
3136

3237
// Assignment user is enrolled in
33-
// @ApiModelProperty(value = "Enrolled assignment")
34-
// @ManyToOne(fetch = FetchType.LAZY)
35-
// @JoinColumn(name = "ASSIGNMENT_ID", referencedColumnName = "ID")
36-
// private Assignment course;
38+
@ApiModelProperty(value = "Enrolled assignment")
39+
@ManyToOne(fetch = FetchType.LAZY)
40+
@JoinColumn(name = "ASSIGNMENT_ID", referencedColumnName = "ID")
41+
private Assignment assignment;
3742

3843
// User id
3944
@JsonIgnore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.unityTest.courseManagement.models.api.response.page;
2+
3+
import com.unityTest.courseManagement.entity.AssignmentEnrollment;
4+
import io.swagger.annotations.ApiModel;
5+
import org.springframework.data.domain.Page;
6+
7+
@ApiModel(value = "AssignmentEnrollmentPage", description = "Page request for enrollment of assignments")
8+
public class AssignmentEnrollmentPage extends BasePage<AssignmentEnrollment> {
9+
public AssignmentEnrollmentPage(Page<AssignmentEnrollment> page) {
10+
super(page);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.unityTest.courseManagement.repository;
2+
3+
import com.unityTest.courseManagement.entity.AssignmentEnrollment;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
6+
import org.springframework.stereotype.Repository;
7+
8+
@Repository
9+
public interface AssignmentEnrollmentRepository
10+
extends JpaRepository<AssignmentEnrollment, Integer>, JpaSpecificationExecutor<AssignmentEnrollment> {
11+
}

src/main/resources/db/h2/bootstrap_data.sql

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
SET @USER_ID = 'TEST_ID';
3+
14
INSERT INTO COURSE (ID, CODE, LEVEL, TERM, ACADEMIC_YEAR)
25
VALUES
36
(1, 'COMPSCI 1JC3', 1, 'FALL', 2019),
@@ -63,3 +66,13 @@ VALUES
6366
(2, 'CASE', 1000, 'X02', 'How about being positive? :smile:', 0),
6467

6568
(3, 'CASE', 1001, 'X03', 'Should we have done this instead? `x = 3`?', 1);
69+
70+
INSERT INTO ASSIGNMENT_ENROLLMENT (ID, ASSIGNMENT_ID, USER_ID, PINNED)
71+
VALUES
72+
(1, 1, 'X01', false),
73+
(2, 2, 'X02', false),
74+
(3, 1, 'X02', true),
75+
(4, 2, 'X01', true),
76+
(5, 1, 'X03', false),
77+
(6, 1, @USER_ID, false),
78+
(7, 2, @USER_ID, true);

0 commit comments

Comments
 (0)