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

fixed update service methods and implemented cucumber tests #108

Merged
merged 16 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,9 @@ public static StudentDto convertToDto(Student s) {
notification.getTitle(),
notification.getBody(),
null, // null student since parent
null,// null admin
null, // null admin
notification.getSeen(),
notification.getTimeStamp());
notification.getTimeStamp());

Admin admin = notification.getSender();
AdminDto adminDto =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public List<CoopDto> getAllCoops() {
return ControllerUtils.convertCoopListToDto(coops);
}

@GetMapping("/student/{id}")
public List<CoopDto> getCoopByStudentId(@PathVariable int id) {
Student s = studentService.getStudentById(id);
List<Coop> coops = coopService.getAllCoopsByStudent(s);
return ControllerUtils.convertCoopListToDto(coops);
}

@PostMapping("")
public CoopDto createCoop(@RequestBody CoopDto coopDto) {
Coop coop = new Coop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -110,8 +111,8 @@ public EmployerReportDto updateEmployerReport(
@RequestParam("status") String status,
@RequestParam("title") String title,
@RequestParam("coop_id") int coopId,
@RequestParam("report_sections") Set<ReportSectionDto> rsDtos,
@RequestParam("employer_id") int employerId) {
@RequestParam("employer_id") int employerId,
@RequestBody Set<ReportSectionDto> rsDtos) {
EmployerReport reportToUpdate = employerReportService.getEmployerReport(id);

Coop coop = coopService.getCoopById(coopId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public NotificationDto getNotificationById(@RequestParam int id) {

return ControllerUtils.convertToDto(n);
}


/**
* Sets notification seen by id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package ca.mcgill.cooperator.controller;

import ca.mcgill.cooperator.dto.EmployerReportDto;
import ca.mcgill.cooperator.dto.ReportSectionDto;
import ca.mcgill.cooperator.dto.StudentReportDto;
import ca.mcgill.cooperator.model.EmployerReport;
import ca.mcgill.cooperator.model.ReportSection;
import ca.mcgill.cooperator.model.StudentReport;
import ca.mcgill.cooperator.service.EmployerReportService;
import ca.mcgill.cooperator.service.ReportSectionService;
import ca.mcgill.cooperator.service.StudentReportService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("report-sections")
public class ReportSectionController {

@Autowired ReportSectionService reportSectionService;
@Autowired StudentReportService studentReportService;
@Autowired EmployerReportService employerReportService;

@GetMapping("/{id}")
public ReportSectionDto getReportSectionById(@PathVariable int id) {
ReportSection reportSection = reportSectionService.getReportSection(id);
return ControllerUtils.convertToDto(reportSection);
}

@GetMapping("")
public List<ReportSectionDto> getAllReportSections() {
List<ReportSection> reportSections = reportSectionService.getAllReportSections();
return ControllerUtils.convertReportSectionListToDto(reportSections);
}

@PostMapping("")
public ReportSectionDto createReportSection(@RequestBody ReportSectionDto reportSectionDto) {
ReportSection reportSection =
reportSectionService.createReportSection(
reportSectionDto.getTitle(), reportSectionDto.getContent());
return ControllerUtils.convertToDto(reportSection);
}

@PutMapping("")
public ReportSectionDto updateReportSection(@RequestBody ReportSectionDto reportSectionDto) {
ReportSection reportSection =
reportSectionService.getReportSection(reportSectionDto.getId());
StudentReport studentReport = null;
EmployerReport employerReport = null;

if (reportSectionDto.getStudentReport() != null) {
StudentReportDto studentReportDto = reportSectionDto.getStudentReport();
studentReport = studentReportService.getStudentReport(studentReportDto.getId());
}

if (reportSectionDto.getEmployerReport() != null) {
EmployerReportDto employerReportDto = reportSectionDto.getEmployerReport();
employerReport = employerReportService.getEmployerReport(employerReportDto.getId());
}

reportSection =
reportSectionService.updateReportSection(
reportSection,
reportSectionDto.getTitle(),
reportSectionDto.getContent(),
studentReport,
employerReport);

return ControllerUtils.convertToDto(reportSection);
}

@DeleteMapping("/{id}")
public void deleteReportSection(@PathVariable int id) {
ReportSection reportSection = reportSectionService.getReportSection(id);
reportSectionService.deleteReportSection(reportSection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ca.mcgill.cooperator.model.Student;
import ca.mcgill.cooperator.model.StudentReport;
import ca.mcgill.cooperator.service.CoopService;
import ca.mcgill.cooperator.service.ReportSectionService;
import ca.mcgill.cooperator.service.StudentReportService;
import ca.mcgill.cooperator.service.StudentService;
import java.util.HashSet;
Expand All @@ -24,6 +25,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -37,6 +39,7 @@ public class StudentReportController {
@Autowired StudentReportService studentReportService;
@Autowired StudentService studentService;
@Autowired CoopService coopService;
@Autowired ReportSectionService reportSectionService;

/**
* Gets a StudentReport by ID
Expand Down Expand Up @@ -115,16 +118,18 @@ public StudentReportDto createStudentReport(
* @param coopId
* @return the updated StudentReport
*/
@PutMapping("/{reportId}")
@PutMapping("/{id}")
public StudentReportDto updateStudentReport(
@PathVariable int reportId,
@PathVariable int id,
@ModelAttribute("file") MultipartFile file,
@RequestParam("status") String status,
@RequestParam("title") String title,
@RequestParam("report_sections") Set<ReportSectionDto> rsDtos,
@RequestParam("coop_id") int coopId) {
StudentReport reportToUpdate = studentReportService.getStudentReport(reportId);
Set<ReportSection> sections = ControllerUtils.convertReportSectionSetToDomainObject(rsDtos);
@RequestParam("coop_id") int coopId,
@RequestBody Set<ReportSectionDto> rsDtos) {
StudentReport reportToUpdate = studentReportService.getStudentReport(id);

Set<ReportSection> sections = convertReportSectionSetToDomainObject(rsDtos);

Coop coop = coopService.getCoopById(coopId);
ReportStatus reportStatus = ReportStatus.valueOf(status);

Expand Down Expand Up @@ -154,4 +159,13 @@ public final ResponseEntity<Exception> handleAllExceptions(RuntimeException ex)
ex.printStackTrace();
return new ResponseEntity<Exception>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
}

public Set<ReportSection> convertReportSectionSetToDomainObject(Set<ReportSectionDto> rsDtos) {
Set<ReportSection> reports = new HashSet<ReportSection>();
for (ReportSectionDto rsDto : rsDtos) {
ReportSection rs = reportSectionService.getReportSection(rsDto.getId());
reports.add(rs);
}
return reports;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import ca.mcgill.cooperator.model.Coop;
import ca.mcgill.cooperator.model.CoopStatus;
import ca.mcgill.cooperator.model.Student;
import java.util.List;
import org.springframework.data.repository.CrudRepository;

public interface CoopRepository extends CrudRepository<Coop, Integer> {
List<Coop> findByStatus(CoopStatus coopStatus);

List<Coop> findByStudent(String firstName);
List<Coop> findByStudent(Student s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ public class NotificationDto {
private StudentDto student;
private AdminDto sender;

public NotificationDto(int id, String title, String body, StudentDto student, AdminDto sender, Boolean seen, long timeStamp) {
public NotificationDto(
int id,
String title,
String body,
StudentDto student,
AdminDto sender,
Boolean seen,
long timeStamp) {
this.id = id;
this.title = title;
this.body = body;
Expand Down Expand Up @@ -57,20 +64,20 @@ public AdminDto getSender() {
public void setSender(AdminDto sender) {
this.sender = sender;
}

public Boolean getSeen() {
return this.seen;
return this.seen;
}

public void setSeen(Boolean seen) {
this.seen = seen;
this.seen = seen;
}

public long getTimeStamp() {
return this.timeStamp;
return this.timeStamp;
}

public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
this.timeStamp = timeStamp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class ReportSectionDto {
private StudentReportDto studentReport;
private EmployerReportDto employerReport;

public ReportSectionDto() {}

public ReportSectionDto(
int id,
String title,
Expand Down
6 changes: 3 additions & 3 deletions Backend/src/main/java/ca/mcgill/cooperator/model/Coop.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public Set<StudentReport> getStudentReports() {
return this.studentReports;
}

public void setStudentReports(Set<StudentReport> studentReports) {
public void setStudentReports(Set<StudentReport> srs) {
if (this.studentReports == null) {
this.studentReports = studentReports;
this.studentReports = srs;
} else {
this.studentReports.clear();
this.studentReports.addAll(studentReports);
this.studentReports.addAll(srs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
public class EmployerReport {
Expand All @@ -22,7 +24,12 @@ public class EmployerReport {

@ManyToOne private EmployerContact employerContact;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OneToMany(
mappedBy = "employerReport",
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
private Set<ReportSection> reportSections;

/*--- Getters and Setters ---*/
Expand Down
18 changes: 8 additions & 10 deletions Backend/src/main/java/ca/mcgill/cooperator/model/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,20 @@ public Admin getSender() {
public void setSender(Admin sender) {
this.sender = sender;
}

public Boolean getSeen() {
return this.seen;
return this.seen;
}

public void setSeen(Boolean seen) {
this.seen = seen;
this.seen = seen;
}

public long getTimeStamp() {
return this.timeStamp;
return this.timeStamp;
}

public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
this.timeStamp = timeStamp;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum ReportStatus {
COMPLETED,
INCOMPLETE,
UNDER_REVIEW,
SUBMITTED,
NOT_SUBMITTED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
public class StudentReport {
Expand All @@ -20,7 +22,12 @@ public class StudentReport {

@ManyToOne private Coop coop;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OneToMany(
mappedBy = "studentReport",
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
private Set<ReportSection> reportSections;

/*--- Getters and Setters ---*/
Expand Down
Loading