Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.0 #2

Open
wants to merge 81 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
ca7dd5e
Added selenium dependencies to pom.xml, completed Enrollment class, c…
juanjoseguva Mar 9, 2024
9d2a12c
Uncomment Assignment Repository
kabsten Mar 10, 2024
4b9a801
Resolved merge conflicts
kabsten Mar 10, 2024
6085a75
Commit before revert
kabsten Mar 10, 2024
4b8ea37
Resolved revert conflict
kabsten Mar 10, 2024
b423af0
Reverted files
kabsten Mar 10, 2024
96c6122
New change comment
kabsten Mar 10, 2024
807efda
Only assignment update
kabsten Mar 10, 2024
0e482ca
My change to ass2
juanjoseguva Mar 10, 2024
9f15ef1
Merge branch 'v1.0' of https://github.com/juanjoseguva/CST438-Assignm…
juanjoseguva Mar 10, 2024
af9ffc4
Restored all my other work locally. Uncommented all repositories
kabsten Mar 10, 2024
49004b2
Resetting AssignmentController to default state
kabsten Mar 10, 2024
06a4419
Updated Repository files
kabsten Mar 11, 2024
f1107ad
My change to ass2
kd65541 Mar 11, 2024
edb92f0
updated create assignment
kd65541 Mar 11, 2024
2d865a6
added Class methods to Grade.java
androog3000 Mar 11, 2024
aa712a1
updated updateAssignment()
kd65541 Mar 11, 2024
56f1e47
updated deleteAssignment()
kd65541 Mar 11, 2024
5296158
Update Assignment.java
kd65541 Mar 11, 2024
725ca6e
checkpoint
kd65541 Mar 11, 2024
08fed4b
conflict resolve
kd65541 Mar 11, 2024
dd6c879
finished getAssignmentGrades and updateGrades
kd65541 Mar 11, 2024
30fc5ac
finished getStudentAssignments
kd65541 Mar 11, 2024
f1008ab
Updated enrollment entity to change User to student
kabsten Mar 11, 2024
3c829a5
courserepo error
kd65541 Mar 11, 2024
17d1029
fixed assignmentController
kd65541 Mar 11, 2024
be3be3d
Fixed Enrollment controller using .getUser() instead of .getStudent()
kabsten Mar 11, 2024
f3df813
Uncommented a couple functions in Section
kabsten Mar 11, 2024
9025885
Update StudentController.java
androog3000 Mar 12, 2024
8a77a73
Update SectionRepository.java
androog3000 Mar 12, 2024
b097807
Update EnrollmentRepository.java
androog3000 Mar 12, 2024
7853321
Update StudentController.java
androog3000 Mar 12, 2024
c2db4c9
Update StudentController.java
androog3000 Mar 12, 2024
1abf2c8
Update StudentController.java
androog3000 Mar 12, 2024
9e06e3e
Changed getUser() to getStudent()
kabsten Mar 12, 2024
52be679
Added @Autowired to repository declarations, and fixed getStudentAssi…
kabsten Mar 12, 2024
c17cc47
Update StudentController.java
androog3000 Mar 12, 2024
ec5e118
Added sectionNo error checking to EnrollmentController
kabsten Mar 12, 2024
d3a44bf
Update AssignmentController.java
androog3000 Mar 12, 2024
8917c3f
Merge branch 'v1.0' of github.com:juanjoseguva/CST438-Assignment2-09 …
kabsten Mar 12, 2024
8481400
added throw responses
kd65541 Mar 12, 2024
fb3758b
added another findByEnrollmentIdAndAssignmentId after saving
kd65541 Mar 13, 2024
63ffd34
Updated sectionRepository method in AssigngmentController.java
androog3000 Mar 13, 2024
b69fa61
updating merge conflict
kd65541 Mar 19, 2024
f1bdd3e
resolve merge conflict
kd65541 Mar 19, 2024
dc939ea
commit juan's change from main branch
kd65541 Mar 19, 2024
27a54a3
First commit for ACUT, not passing tests yet.
juanjoseguva Mar 23, 2024
a854968
changed expected response to 404. Still need to find why it's not ret…
juanjoseguva Mar 23, 2024
a99a976
deleted unnecessary comments
juanjoseguva Mar 23, 2024
6980bb3
Passig all tests, fixed database cleanup issue
juanjoseguva Mar 23, 2024
ecdfa2f
Deleted unused imports (BeforeEach, AfterEach)
juanjoseguva Mar 23, 2024
f692052
Edit for consistency in declaring AssignmentDTO instance
juanjoseguva Mar 23, 2024
e72a87a
Finished unit tests for ADD ASSIGNMENT FAILS FOR BAD SECTION NO(had t…
kabsten Mar 24, 2024
27dd024
Fixed pom.xml file so selenium driver works. Started selenium test fo…
kabsten Mar 24, 2024
e4f8f02
Added StudentControllerUnitTest
androog3000 Mar 24, 2024
c1ae009
Update to AssignmentControllerUnitTest.java
androog3000 Mar 25, 2024
65d1049
Update AssignmentControllerUnitTest.java
androog3000 Mar 25, 2024
b843bf2
Test for adding an assignment
juanjoseguva Mar 25, 2024
4b51709
systemTestGradeAssignment is done. May need some further commenting
kabsten Mar 25, 2024
ee94026
Merge branch 'v1.0' of github.com:juanjoseguva/CST438-Assignment2-09 …
kabsten Mar 25, 2024
d6177b8
Add files via upload
androog3000 Mar 25, 2024
470e3b5
Changed the way the driver finds the Show Sections link
juanjoseguva Mar 26, 2024
df15a31
Fixed typo on line 104, had the wrong course id in the xpath
juanjoseguva Mar 26, 2024
8e66d10
Fixed format for keys to send to DatePicker element
juanjoseguva Mar 27, 2024
039c19a
added the 2 student unit tests
kd65541 Mar 27, 2024
1456932
Passing all tests
juanjoseguva Mar 27, 2024
a86663a
added the 2 student unit tests again
kd65541 Mar 27, 2024
f09918a
updating studentcontrollerunittest again
kd65541 Mar 27, 2024
dbe152b
updated without the extra /
kd65541 Mar 27, 2024
499fd3b
Edited null check when adding section
androog3000 Mar 27, 2024
e319f36
student controller unit test completed
kd65541 Mar 27, 2024
71143bc
student controller unit test completed1
kd65541 Mar 27, 2024
72695e5
Added additional checks in StudentControllerSystemTest
androog3000 Mar 27, 2024
7e9574a
update on enrollmentcontroller unit test
kd65541 Mar 27, 2024
e1ca600
changes to enrollmentcontroller unit testing
kd65541 Mar 27, 2024
699aefb
change to enrollmentcontroller unit test
kd65541 Mar 27, 2024
6ead2e4
change to enrollmentcontroller unit test
kd65541 Mar 27, 2024
eaa6625
additions to enrollment system test
kd65541 Mar 29, 2024
94dfc44
small format change
kd65541 Apr 3, 2024
9558efc
Uncommented @AfterEach so driver is correctly destroyed
kabsten Apr 3, 2024
4719689
Fixed AssignmentGrade selenium test. Needed to Thread.sleep(SLEEP_DUR…
kabsten Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is making changes in the pom.xml file necessary for this PR?

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down
152 changes: 131 additions & 21 deletions src/main/java/com/cst438/controller/AssignmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,81 @@

import java.util.ArrayList;
import java.util.List;
import java.sql.Date;

@RestController
@CrossOrigin(origins = "http://localhost:3000")
public class AssignmentController {

@Autowired
AssignmentRepository assignmentRepository;
@Autowired
CourseRepository courseRepository;
@Autowired
SectionRepository sectionRepository;
@Autowired
EnrollmentRepository enrollmentRepository;
@Autowired
GradeRepository gradeRepository;

// instructor lists assignments for a section. Assignments ordered by due date.
// logged in user must be the instructor for the section
@GetMapping("/sections/{secNo}/assignments")
public List<AssignmentDTO> getAssignments(
@PathVariable("secNo") int secNo) {

// TODO remove the following line when done
List<Assignment> assignments = assignmentRepository.findBySectionNoOrderByDueDate(secNo);
if (assignments.isEmpty()) {
throw new ResponseStatusException( HttpStatus.NOT_FOUND, "section not found ");
}
List<AssignmentDTO> dto_list = new ArrayList<>();
for(Assignment a:assignments){
dto_list.add(new AssignmentDTO(
a.getAssignmentId(),
a.getTitle(),
a.getDueDate().toString(),
a.getSection().getCourse().getCourseId(),
a.getSection().getSecId(),
a.getSection().getSectionNo()
));
}

// hint: use the assignment repository method
// findBySectionNoOrderByDueDate to return
// a list of assignments

return null;
return dto_list;
}

// add assignment
// user must be instructor of the section
// return AssignmentDTO with assignmentID generated by database
@PostMapping("/assignments")
public AssignmentDTO createAssignment(
@RequestBody AssignmentDTO dto) {
public AssignmentDTO createAssignment(@RequestBody AssignmentDTO dto) {

// TODO remove the following line when done
Section s = sectionRepository.findById(dto.secId()).orElse(null);
if (s==null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "section not found " + dto.secId());
}

return null;
// TODO remove the following line when done
Assignment a = new Assignment();
a.setAssignmentId(dto.id());
a.setTitle(dto.title());
//convert string -> date
Date date = Date.valueOf(dto.dueDate());
a.setDueDate(date);
a.setSection(s);
assignmentRepository.save(a);

return new AssignmentDTO(
a.getAssignmentId(),
a.getTitle(),
a.getDueDate().toString(),
a.getSection().getCourse().getCourseId(),
a.getSection().getSecId(),
a.getSection().getSectionNo()
);
}

// update assignment for a section. Only title and dueDate may be changed.
Expand All @@ -55,17 +99,36 @@ public AssignmentDTO createAssignment(
@PutMapping("/assignments")
public AssignmentDTO updateAssignment(@RequestBody AssignmentDTO dto) {

// TODO remove the following line when done

return null;
Assignment a = assignmentRepository.findById(dto.id()).orElse(null);
if(a==null){
throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Assignment not found "+dto.id());
}

a.setTitle(dto.title());
//convert string -> date
Date date = Date.valueOf(dto.dueDate());
a.setDueDate(date);
assignmentRepository.save(a);
return new AssignmentDTO(
a.getAssignmentId(),
a.getTitle(),
a.getDueDate().toString(),
a.getSection().getCourse().getCourseId(),
a.getSection().getSecId(),
a.getSection().getSectionNo()
);
}

// delete assignment for a section
// logged in user must be instructor of the section
@DeleteMapping("/assignments/{assignmentId}")
public void deleteAssignment(@PathVariable("assignmentId") int assignmentId) {

// TODO
Assignment a = assignmentRepository.findById(assignmentId).orElse(null);
//if assignment doesn't exist, do nothing
if(a!=null){
assignmentRepository.delete(a);
}
}

// instructor gets grades for assignment ordered by student name
Expand All @@ -74,27 +137,56 @@ public void deleteAssignment(@PathVariable("assignmentId") int assignmentId) {
public List<GradeDTO> getAssignmentGrades(@PathVariable("assignmentId") int assignmentId) {

// TODO remove the following line when done
Assignment a = assignmentRepository.findById(assignmentId).orElse(null);
if (a==null) {
throw new ResponseStatusException( HttpStatus.NOT_FOUND, "assignment not found "+assignmentId);
}

// get the list of enrollments for the section related to this assignment.
// hint: use te enrollment repository method findEnrollmentsBySectionOrderByStudentName.
// hint: use the enrollment repository method findEnrollmentsBySectionOrderByStudentName.
List<Enrollment> enrollments = enrollmentRepository.findEnrollmentsBySectionNoOrderByStudentName(a.getSection().getSectionNo());

// for each enrollment, get the grade related to the assignment and enrollment
// hint: use the gradeRepository findByEnrollmentIdAndAssignmentId method.
// if the grade does not exist, create a grade entity and set the score to NULL
// and then save the new entity

return null;
List<GradeDTO> gradeDTOList = new ArrayList<>();
for(Enrollment e:enrollments){
// if the grade does not exist, create a grade entity and set the score to NULL
Grade g = gradeRepository.findByEnrollmentIdAndAssignmentId(e.getEnrollmentId(), assignmentId);
if(g==null){
g = new Grade();
g.setScore(null);
}
// and then save the new entity
gradeRepository.save(g);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this with postman, and is it working correctly? I think you will need to set a few more properties of the grade entity, and then return the grade with findByEnrollmentIdAndAssignmentId after saving it.

Copy link
Collaborator

@kd65541 kd65541 Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added properties and reran findByEnrollmentIdAndAssignmentId after saving, appears to be working properly on postman

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


gradeDTOList.add(new GradeDTO(
g.getGradeId(),
e.getStudent().getName(),
e.getStudent().getEmail(),
a.getTitle(),
e.getSection().getCourse().getCourseId(),
e.getSection().getSecId(),
g.getScore()
));
}
return gradeDTOList;
}

// instructor uploads grades for assignment
// user must be instructor for the section
@PutMapping("/grades")
public void updateGrades(@RequestBody List<GradeDTO> dlist) {

// TODO

// for each grade in the GradeDTO list, retrieve the grade entity
// update the score and save the entity

for(GradeDTO dto:dlist){
Grade g = gradeRepository.findById(dto.gradeId()).orElse(null);
if(g==null){
throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Grade not found "+dto.gradeId());
}
// update the score and save the entity
g.setScore(dto.score());
gradeRepository.save(g);
}
}


Expand All @@ -108,11 +200,29 @@ public List<AssignmentStudentDTO> getStudentAssignments(
@RequestParam("semester") String semester) {

// TODO remove the following line when done
List<AssignmentStudentDTO> returnDtos = new ArrayList<>();
List<Enrollment> enrollments = enrollmentRepository.findByYearAndSemesterOrderByCourseId(year, semester, studentId);
List<Assignment> assignments = new ArrayList<>();
for (Enrollment e:enrollments){
assignments = assignmentRepository.findBySectionNoOrderByDueDate(e.getSection().getSectionNo());
for(Assignment a:assignments){
Grade grade = gradeRepository.findByEnrollmentIdAndAssignmentId(e.getEnrollmentId(), a.getAssignmentId());
returnDtos.add(new AssignmentStudentDTO(
a.getAssignmentId(),
a.getTitle(),
a.getDueDate(),
e.getSection().getCourse().getCourseId(),
e.getSection().getSecId(),
(grade!=null) ? grade.getScore() : null
));
}
}


// return a list of assignments and (if they exist) the assignment grade
// for all sections that the student is enrolled for the given year and semester
// hint: use the assignment repository method findByStudentIdAndYearAndSemesterOrderByDueDate
// hint: use the assignment repository method findByStudentIdAndYearAndSemesterOrderByDueDate

return null;
return returnDtos;
}
}
58 changes: 39 additions & 19 deletions src/main/java/com/cst438/controller/EnrollmentController.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
package com.cst438.controller;


import com.cst438.domain.Enrollment;
import com.cst438.domain.EnrollmentRepository;
import com.cst438.dto.EnrollmentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@CrossOrigin(origins = "http://localhost:3000")
public class EnrollmentController {

@Autowired
private EnrollmentRepository enrollmentRepository;

// instructor downloads student enrollments for a section, ordered by student name
// user must be instructor for the section
@GetMapping("/sections/{sectionNo}/enrollments")
public List<EnrollmentDTO> getEnrollments(
@PathVariable("sectionNo") int sectionNo ) {

// TODO
// hint: use enrollment repository findEnrollmentsBySectionNoOrderByStudentName method
// remove the following line when done
return null;
public List<EnrollmentDTO> getEnrollments(@PathVariable("sectionNo") int sectionNo) {
List<Enrollment> enrollments = enrollmentRepository.findEnrollmentsBySectionNoOrderByStudentName(sectionNo);
if(enrollments == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Section number is invalid");
}

return enrollments.stream()
.map(enrollment -> new EnrollmentDTO(
enrollment.getEnrollmentId(),
enrollment.getGrade(),
enrollment.getStudent().getId(),
enrollment.getStudent().getName(),
enrollment.getStudent().getEmail(),
enrollment.getSection().getCourse().getCourseId(),
enrollment.getSection().getSecId(),
enrollment.getSection().getSectionNo(),
enrollment.getSection().getBuilding(),
enrollment.getSection().getRoom(),
enrollment.getSection().getTimes(),
enrollment.getSection().getCourse().getCredits(),
enrollment.getSection().getTerm().getYear(),
enrollment.getSection().getTerm().getSemester()))
.collect(Collectors.toList());
}

// instructor uploads enrollments with the final grades for the section
// user must be instructor for the section
@PutMapping("/enrollments")
public void updateEnrollmentGrade(@RequestBody List<EnrollmentDTO> dlist) {

// TODO

// For each EnrollmentDTO in the list
// find the Enrollment entity using enrollmentId
// update the grade and save back to database

public void updateEnrollmentGrade(@RequestBody List<EnrollmentDTO> dtoList) {
for (EnrollmentDTO dto : dtoList) {
Enrollment enrollment = enrollmentRepository.findById(dto.enrollmentId())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Enrollment not found"));

// Update the grade and save back to the database
enrollment.setGrade(dto.grade());
enrollmentRepository.save(enrollment);
}
}

}
}
Loading