| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
| 6 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
| 7 | import io.swagger.v3.oas.annotations.Operation; | |
| 8 | import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | import java.util.ArrayList; | |
| 10 | import java.util.List; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.http.ResponseEntity; | |
| 13 | import org.springframework.web.bind.annotation.GetMapping; | |
| 14 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 15 | import org.springframework.web.bind.annotation.RequestParam; | |
| 16 | import org.springframework.web.bind.annotation.RestController; | |
| 17 | ||
| 18 | @RestController | |
| 19 | @RequestMapping("/api/public/courseovertime") | |
| 20 | public class CourseOverTimeInstructorController { | |
| 21 | ||
| 22 | private ObjectMapper mapper = new ObjectMapper(); | |
| 23 | ||
| 24 | @Autowired ConvertedSectionCollection convertedSectionCollection; | |
| 25 | ||
| 26 | @Operation(summary = "Get a list of courses over time, filtered by instructor name") | |
| 27 | @GetMapping(value = "/instructorsearch", produces = "application/json") | |
| 28 | public ResponseEntity<String> search( | |
| 29 | @Parameter( | |
| 30 | name = "startQtr", | |
| 31 | description = | |
| 32 | "Starting quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
| 33 | example = "20231", | |
| 34 | required = true) | |
| 35 | @RequestParam | |
| 36 | String startQtr, | |
| 37 | @Parameter( | |
| 38 | name = "endQtr", | |
| 39 | description = | |
| 40 | "Ending quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
| 41 | example = "20231", | |
| 42 | required = true) | |
| 43 | @RequestParam | |
| 44 | String endQtr, | |
| 45 | @Parameter( | |
| 46 | name = "instructor", | |
| 47 | description = "Instructor name; e.g. 'conrad' or 'CONRAD' or 'CONRAD P T'", | |
| 48 | example = "CONRAD", | |
| 49 | required = true) | |
| 50 | @RequestParam | |
| 51 | String instructor, | |
| 52 | @Parameter( | |
| 53 | name = "lectureOnly", | |
| 54 | description = "Lectures only", | |
| 55 | example = "true", | |
| 56 | required = true) | |
| 57 | @RequestParam | |
| 58 | boolean lectureOnly) | |
| 59 | throws JsonProcessingException { | |
| 60 | List<ConvertedSection> courseResults; | |
| 61 |
1
1. search : negated conditional → KILLED |
if (lectureOnly) { |
| 62 | courseResults = | |
| 63 | new ArrayList<>( | |
| 64 | convertedSectionCollection.findByQuarterRangeAndInstructor( | |
| 65 | startQtr, endQtr, "^" + instructor.toUpperCase(), "^(Teaching and in charge)")); | |
| 66 | } else { | |
| 67 | courseResults = | |
| 68 | new ArrayList<>( | |
| 69 | convertedSectionCollection.findByQuarterRangeAndInstructor( | |
| 70 | startQtr, endQtr, "^" + instructor.toUpperCase(), "^.*")); | |
| 71 | } | |
| 72 |
1
1. search : removed call to java/util/List::sort → KILLED |
courseResults.sort(new ConvertedSection.ConvertedSectionSortDescendingByQuarterComparator()); |
| 73 | String body = mapper.writeValueAsString(courseResults); | |
| 74 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::search → KILLED |
return ResponseEntity.ok().body(body); |
| 75 | } | |
| 76 | } | |
Mutations | ||
| 61 |
1.1 |
|
| 72 |
1.1 |
|
| 74 |
1.1 |