| 1 | package edu.ucsb.cs156.happiercows.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.happiercows.helpers.ParticipationGradeCSVHelper; | |
| 4 | import edu.ucsb.cs156.happiercows.models.ParticipationGrade; | |
| 5 | import edu.ucsb.cs156.happiercows.models.ParticipationGradeParams; | |
| 6 | import edu.ucsb.cs156.happiercows.services.ParticipationGradeService; | |
| 7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | ||
| 11 | import org.springframework.format.annotation.DateTimeFormat; | |
| 12 | import org.springframework.http.HttpHeaders; | |
| 13 | import org.springframework.http.MediaType; | |
| 14 | import org.springframework.http.ResponseEntity; | |
| 15 | ||
| 16 | import java.io.ByteArrayInputStream; | |
| 17 | import java.io.IOException; | |
| 18 | import java.time.LocalDate; | |
| 19 | import java.util.List; | |
| 20 | ||
| 21 | import org.springframework.beans.factory.annotation.Autowired; | |
| 22 | import org.springframework.core.io.InputStreamResource; | |
| 23 | import org.springframework.core.io.Resource; | |
| 24 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 25 | import org.springframework.web.bind.annotation.GetMapping; | |
| 26 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 27 | import org.springframework.web.bind.annotation.RequestParam; | |
| 28 | import org.springframework.web.bind.annotation.RestController; | |
| 29 | ||
| 30 | @Tag(name = "ParticipationGrade") | |
| 31 | @RequestMapping("/api/participationgrade") | |
| 32 | @RestController | |
| 33 | public class ParticipationGradeController extends ApiController { | |
| 34 | ||
| 35 | @Autowired | |
| 36 | ParticipationGradeService participationGradeService; | |
| 37 | ||
| 38 | @Operation(summary = "Compute participation grades for a course's roster over a date range") | |
| 39 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 40 | @GetMapping("/compute") | |
| 41 | public List<ParticipationGrade> compute( | |
| 42 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 43 | @Parameter(name = "startDate") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, | |
| 44 | @Parameter(name = "endDate") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, | |
| 45 | @Parameter(name = "criterion1Weight") @RequestParam int criterion1Weight, | |
| 46 | @Parameter(name = "criterion2Weight") @RequestParam int criterion2Weight, | |
| 47 | @Parameter(name = "criterion2MinDays") @RequestParam int criterion2MinDays, | |
| 48 | @Parameter(name = "criterion2PartialCredit") @RequestParam boolean criterion2PartialCredit, | |
| 49 | @Parameter(name = "criterion3Weight") @RequestParam int criterion3Weight, | |
| 50 | @Parameter(name = "totalPoints") @RequestParam double totalPoints) { | |
| 51 | ||
| 52 | ParticipationGradeParams params = toParams(courseId, startDate, endDate, criterion1Weight, | |
| 53 | criterion2Weight, criterion2MinDays, criterion2PartialCredit, criterion3Weight, totalPoints); | |
| 54 | ||
| 55 |
1
1. compute : replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/ParticipationGradeController::compute → KILLED |
return participationGradeService.computeGrades(params); |
| 56 | } | |
| 57 | ||
| 58 | @Operation(summary = "Download computed participation grades for a course's roster as a csv") | |
| 59 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 60 | @GetMapping("/download") | |
| 61 | public ResponseEntity<Resource> download( | |
| 62 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 63 | @Parameter(name = "startDate") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, | |
| 64 | @Parameter(name = "endDate") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, | |
| 65 | @Parameter(name = "criterion1Weight") @RequestParam int criterion1Weight, | |
| 66 | @Parameter(name = "criterion2Weight") @RequestParam int criterion2Weight, | |
| 67 | @Parameter(name = "criterion2MinDays") @RequestParam int criterion2MinDays, | |
| 68 | @Parameter(name = "criterion2PartialCredit") @RequestParam boolean criterion2PartialCredit, | |
| 69 | @Parameter(name = "criterion3Weight") @RequestParam int criterion3Weight, | |
| 70 | @Parameter(name = "totalPoints") @RequestParam double totalPoints) throws IOException { | |
| 71 | ||
| 72 | ParticipationGradeParams params = toParams(courseId, startDate, endDate, criterion1Weight, | |
| 73 | criterion2Weight, criterion2MinDays, criterion2PartialCredit, criterion3Weight, totalPoints); | |
| 74 | ||
| 75 | List<ParticipationGrade> grades = participationGradeService.computeGrades(params); | |
| 76 | ||
| 77 | String filename = String.format("participationGrades%05d.csv", courseId); | |
| 78 | ||
| 79 | ByteArrayInputStream bais = ParticipationGradeCSVHelper.toCSV(grades); | |
| 80 | InputStreamResource isr = new InputStreamResource(bais); | |
| 81 | ||
| 82 |
1
1. download : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ParticipationGradeController::download → KILLED |
return ResponseEntity.ok() |
| 83 | .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename) | |
| 84 | .contentType(MediaType.parseMediaType("application/csv")).body(isr); | |
| 85 | } | |
| 86 | ||
| 87 | private ParticipationGradeParams toParams(Long courseId, LocalDate startDate, LocalDate endDate, | |
| 88 | int criterion1Weight, int criterion2Weight, int criterion2MinDays, boolean criterion2PartialCredit, | |
| 89 | int criterion3Weight, double totalPoints) { | |
| 90 |
1
1. toParams : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ParticipationGradeController::toParams → KILLED |
return ParticipationGradeParams.builder() |
| 91 | .courseId(courseId) | |
| 92 | .startDate(startDate) | |
| 93 | .endDate(endDate) | |
| 94 | .criterion1Weight(criterion1Weight) | |
| 95 | .criterion2Weight(criterion2Weight) | |
| 96 | .criterion2MinDays(criterion2MinDays) | |
| 97 | .criterion2PartialCredit(criterion2PartialCredit) | |
| 98 | .criterion3Weight(criterion3Weight) | |
| 99 | .totalPoints(totalPoints) | |
| 100 | .build(); | |
| 101 | } | |
| 102 | } | |
Mutations | ||
| 55 |
1.1 |
|
| 82 |
1.1 |
|
| 90 |
1.1 |