1 | package edu.ucsb.cs156.courses.controllers; | |
2 | ||
3 | import java.util.List; | |
4 | ||
5 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
6 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
7 | import io.swagger.annotations.ApiOperation; | |
8 | import io.swagger.annotations.ApiParam; | |
9 | ||
10 | import org.slf4j.Logger; | |
11 | import org.slf4j.LoggerFactory; | |
12 | import org.springframework.beans.factory.annotation.Autowired; | |
13 | import org.springframework.http.ResponseEntity; | |
14 | import org.springframework.web.bind.annotation.GetMapping; | |
15 | import org.springframework.web.bind.annotation.RequestMapping; | |
16 | import org.springframework.web.bind.annotation.RequestParam; | |
17 | import org.springframework.web.bind.annotation.RestController; | |
18 | ||
19 | import com.fasterxml.jackson.core.JsonProcessingException; | |
20 | import com.fasterxml.jackson.databind.ObjectMapper; | |
21 | ||
22 | @RestController | |
23 | @RequestMapping("/api/public/coursebyinstructor") | |
24 | public class CourseByInstructorController { | |
25 | ||
26 | private final Logger logger = LoggerFactory.getLogger(CourseOverTimeController.class); | |
27 | ||
28 | private ObjectMapper mapper = new ObjectMapper(); | |
29 | ||
30 | @Autowired | |
31 | ConvertedSectionCollection convertedSectionCollection; | |
32 | ||
33 | @ApiOperation(value = "Get a list of courses by instructor over time") | |
34 | @GetMapping(value = "/search", produces = "application/json") | |
35 | public ResponseEntity<String> search( | |
36 | @ApiParam(name = "startQtr", type = "String", value = "Start quarter in YYYYQ format", example = "20221", required = true) @RequestParam String startQtr, | |
37 | @ApiParam(name = "endQtr", type = "String", value = "End quarter in YYYYQ format", example = "20222", required = true) @RequestParam String endQtr, | |
38 | @ApiParam(name = "instructor", type = "String", value = "Instructor name", example = "CONRAD P T", required = true) @RequestParam String instructor, | |
39 | @ApiParam(name = "lectureOnly", type = "boolean", value = "Lectures only", example = "true", required = true) @RequestParam boolean lectureOnly | |
40 | ) throws JsonProcessingException { | |
41 | List<ConvertedSection> courseResults; | |
42 |
1
1. search : negated conditional → KILLED |
if (lectureOnly) { |
43 | courseResults = convertedSectionCollection.findByQuarterRangeAndInstructor( | |
44 | startQtr, | |
45 | endQtr, | |
46 | "^"+instructor.toUpperCase(), | |
47 | "^(Teaching and in charge)"); | |
48 | } else { | |
49 | courseResults = convertedSectionCollection.findByQuarterRangeAndInstructor( | |
50 | startQtr, | |
51 | endQtr, | |
52 | "^"+instructor.toUpperCase(), | |
53 | "^.*"); | |
54 | } | |
55 | String body = mapper.writeValueAsString(courseResults); | |
56 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseByInstructorController::search → KILLED |
return ResponseEntity.ok().body(body); |
57 | } | |
58 | } | |
Mutations | ||
42 |
1.1 |
|
56 |
1.1 |