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