These Scrum team members were responsible for contributions to this portion of the Assignment object:
Raymond: Raymond got the process in motion by helping to research how to implement file uploads and got the initial version of file uploads working on the backend. His "/upload" endpoint method was used for crucial testing and implemented in the larger assignment submission methods.
Drew: Drew was largely responsible for applying the file upload methods in the context of Assignment submissions. This included creating the new AssignmentSubmission entities and their relationships, the JPA repository and Details Service methods for the new class (to interact with Assignment and Person), and created the "/submit" endpoint used on the frontend to upload assignment submissions and save them to a given assignment.
AJ: AJ was unable to commit to the branch for a while due to errors in VSCode, AJ played a crucial role in outlining the mechanics (existing and intended) of the Assignment class and was involved in pair programming with Drew on his system.
Submission Code
AssignmentSubmission Object
The object is just a basic POJO stored as an entity. Originally, in this commit, it wasn't an SQL entity, as Drew wasn't originally intending for that. AJ emphasized making it an entity so that it could be related to Assignment and Person, so we reimplemented it in this commit.
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Convert(attributeName ="assignmentSubmission", converter = JsonType.class)
public class AssignmentSubmission {
// automatic unique identifier for Person record
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(fetch = FetchType.EAGER)
private Person submitter;
@NonNull
private String filePath;
@Temporal(TemporalType.TIMESTAMP)
private Date timeSubmitted;
private int submissionNumber;
}
Upload Method
Raymond's upload method was the foundation for the submission endpoint method, implemented in this commit.
Comments throughout the method explain its functional, as below:
File tempDirectory = new File(tempUploadDir);
if (!tempDirectory.exists()) {
tempDirectory.mkdirs();
}
// Save the file to the temporary upload directory
String tempFilePath = tempUploadDir + File.separator + file.getOriginalFilename();
file.transferTo(new File(tempFilePath));
// Move the file to the final destination
String finalFilePath = uploadDir + File.separator + file.getOriginalFilename();
new File(tempFilePath).renameTo(new File(finalFilePath));
return ResponseEntity.ok("File uploaded successfully");
Submit Method
This method utilizes the functionality of the upload method, but implements the AssignmentSubmission object and the JWT for user data. Some unique code is shown below:
@PostMapping("/submit/{id}/{submissionTimeString}")
public ResponseEntity<Object> handleFileUpload(@CookieValue("jwt") String jwtToken,
@RequestPart("file") MultipartFile file,
@PathVariable long id,
@PathVariable String submissionTimeString) {
// jwt processing for user info
if (jwtToken.isEmpty()) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
// getting user data
String userEmail = tokenUtil.getUsernameFromToken(jwtToken);
Person existingPerson = personRepository.findByEmail(userEmail);
if (existingPerson == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
// determining the relevant assignment and its relation to user
boolean userInClasses = false;
Assignment submittedAssignment = assignmentDetailsService.get(id); // getting requested assignment
List<ClassPeriod> classesWithAssignment = classService.getClassPeriodsByAssignment(submittedAssignment); // classes with assignment
for (ClassPeriod classPeriod : classesWithAssignment) {
for (Person student : classPeriod.getStudents()) {
if (student.getEmail().equals(existingPerson.getEmail())) {
userInClasses = true; // user is in a class period with the given assignment
}
}
}
if (!userInClasses) { // if the user is not in the necessary class
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
// checking the submission number
int submissionNumber = 1;
for (AssignmentSubmission submission : submittedAssignment.getSubmissions()) {
if (submission.getSubmitter().getEmail().equals(existingPerson.getEmail())) {
if (submission.getSubmissionNumber() >= submissionNumber) {
submissionNumber = submission.getSubmissionNumber() + 1;
}
}
}
Demo
OBS wasn't working, so we have some screenshot demos.
Initial SQL Table
File Upload
Signed in as "jm1021@gmail.com", the file "python code image.png" will be uploaded to the assignment "Teddy's Big Bready":
SQL Tables After Upload
This is the AssignmentSubmission successfully uploaded:
Involved Scrum Members
These Scrum team members were responsible for contributions to this portion of the Assignment object:
AssignmentSubmission
entities and their relationships, the JPA repository and Details Service methods for the new class (to interact with Assignment and Person), and created the "/submit" endpoint used on the frontend to upload assignment submissions and save them to a given assignment.Submission Code
AssignmentSubmission Object
The object is just a basic POJO stored as an entity. Originally, in this commit, it wasn't an SQL entity, as Drew wasn't originally intending for that. AJ emphasized making it an entity so that it could be related to Assignment and Person, so we reimplemented it in this commit.
Upload Method
Raymond's upload method was the foundation for the submission endpoint method, implemented in this commit.
Comments throughout the method explain its functional, as below:
Submit Method
This method utilizes the functionality of the upload method, but implements the AssignmentSubmission object and the JWT for user data. Some unique code is shown below:
Demo
OBS wasn't working, so we have some screenshot demos.
Initial SQL Table
File Upload
Signed in as "jm1021@gmail.com", the file "python code image.png" will be uploaded to the assignment "Teddy's Big Bready":
SQL Tables After Upload
This is the AssignmentSubmission successfully uploaded: