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