| 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 CourseOverTimeDescriptionController { | |
| 20 | ||
| 21 | private ObjectMapper mapper = new ObjectMapper(); | |
| 22 | ||
| 23 | @Autowired ConvertedSectionCollection convertedSectionCollection; | |
| 24 | ||
| 25 | @Operation( | |
| 26 | summary = "Get a list of courses over time, filtered by course description search terms") | |
| 27 | @GetMapping(value = "/descriptionsearch", produces = "application/json") | |
| 28 | public ResponseEntity<String> search( | |
| 29 | @Parameter( | |
| 30 | name = "searchTerms", | |
| 31 | description = | |
| 32 | "Search terms for the course description or title, e.g. 'Data' OR 'Algorithms'", | |
| 33 | example = "Data", | |
| 34 | required = true) | |
| 35 | @RequestParam(required = true) | |
| 36 | String searchTerms, | |
| 37 | @Parameter( | |
| 38 | name = "startQtr", | |
| 39 | description = | |
| 40 | "Starting 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 startQtr, | |
| 45 | @Parameter( | |
| 46 | name = "endQtr", | |
| 47 | description = | |
| 48 | "Ending quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
| 49 | example = "20231", | |
| 50 | required = true) | |
| 51 | @RequestParam | |
| 52 | String endQtr, | |
| 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.findBySearchTermsAndQuarterRange( | |
| 65 | searchTerms, startQtr, endQtr, "00$"); | |
| 66 | } else { | |
| 67 | courseResults = | |
| 68 | convertedSectionCollection.findBySearchTermsAndQuarterRange( | |
| 69 | searchTerms, startQtr, endQtr, ".*"); | |
| 70 | } | |
| 71 |
1
1. search : removed call to java/util/List::sort → KILLED |
courseResults.sort(new ConvertedSection.ConvertedSectionSortDescendingByQuarterComparator()); |
| 72 | String body = mapper.writeValueAsString(courseResults); | |
| 73 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeDescriptionController::search → KILLED |
return ResponseEntity.ok().body(body); |
| 74 | } | |
| 75 | } | |
Mutations | ||
| 62 |
1.1 |
|
| 71 |
1.1 |
|
| 73 |
1.1 |