| 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 edu.ucsb.cs156.courses.documents.Primary; | |
| 8 | import edu.ucsb.cs156.courses.models.Quarter; | |
| 9 | import edu.ucsb.cs156.courses.services.UpdateService; | |
| 10 | import io.swagger.v3.oas.annotations.Operation; | |
| 11 | import io.swagger.v3.oas.annotations.Parameter; | |
| 12 | import java.util.ArrayList; | |
| 13 | import java.util.List; | |
| 14 | import java.util.Map; | |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.http.ResponseEntity; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestParam; | |
| 20 | import org.springframework.web.bind.annotation.RestController; | |
| 21 | ||
| 22 | @RestController | |
| 23 | @RequestMapping("/api/public/courseovertime") | |
| 24 | public class CourseOverTimeController { | |
| 25 | ||
| 26 | private ObjectMapper mapper = new ObjectMapper(); | |
| 27 | ||
| 28 | @Autowired ConvertedSectionCollection convertedSectionCollection; | |
| 29 | @Autowired UpdateService updateService; | |
| 30 | ||
| 31 | @Operation(summary = "Get a list of courses over time") | |
| 32 | @GetMapping(value = "/search", produces = "application/json") | |
| 33 | public ResponseEntity<String> search( | |
| 34 | @Parameter( | |
| 35 | name = "startQtr", | |
| 36 | description = | |
| 37 | "starting quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
| 38 | example = "20231", | |
| 39 | required = true) | |
| 40 | @RequestParam | |
| 41 | String startQtr, | |
| 42 | @Parameter( | |
| 43 | name = "endQtr", | |
| 44 | description = | |
| 45 | "ending quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
| 46 | example = "20231", | |
| 47 | required = true) | |
| 48 | @RequestParam | |
| 49 | String endQtr, | |
| 50 | @Parameter( | |
| 51 | name = "subjectArea", | |
| 52 | description = "simplified area name, e.g. CMPSC for computer science", | |
| 53 | example = "CMPSC", | |
| 54 | required = true) | |
| 55 | @RequestParam | |
| 56 | String subjectArea, | |
| 57 | @Parameter( | |
| 58 | name = "courseNumber", | |
| 59 | description = "the specific course number, e.g. 130A for CS130A", | |
| 60 | example = "130A", | |
| 61 | required = true) | |
| 62 | @RequestParam | |
| 63 | String courseNumber) | |
| 64 | throws JsonProcessingException { | |
| 65 | List<String> missingQuarters = new ArrayList<>(); | |
| 66 | ||
| 67 | for (Quarter quarter : Quarter.quarterList(startQtr, endQtr)) { | |
| 68 | String quarterYYYYQ = quarter.getYYYYQ(); | |
| 69 |
1
1. search : negated conditional → KILLED |
if (!updateService.hasCompleteUpdate(subjectArea, quarterYYYYQ)) { |
| 70 | missingQuarters.add(quarterYYYYQ); | |
| 71 | } | |
| 72 | } | |
| 73 | List<ConvertedSection> courseResults = | |
| 74 | new ArrayList<ConvertedSection>( | |
| 75 | convertedSectionCollection.findByQuarterRangeAndCourseId( | |
| 76 | startQtr, endQtr, makeFormattedCourseId(subjectArea, courseNumber))); | |
| 77 | ||
| 78 | List<Primary> primaries = Primary.fromConvertedSections(courseResults); | |
| 79 | ||
| 80 | String body = | |
| 81 | mapper.writeValueAsString(Map.of("courses", primaries, "missingQuarters", missingQuarters)); | |
| 82 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED |
return ResponseEntity.ok().body(body); |
| 83 | } | |
| 84 | ||
| 85 | String makeFormattedCourseId(String subjectArea, String courseNumber) { | |
| 86 | String[] nums = courseNumber.split("[a-zA-Z]+"); | |
| 87 | String[] suffs = courseNumber.split("[0-9]+"); | |
| 88 |
2
1. makeFormattedCourseId : changed conditional boundary → KILLED 2. makeFormattedCourseId : negated conditional → KILLED |
if (suffs.length < 2) { // no suffix |
| 89 |
1
1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED |
return String.format("%-8s", subjectArea) // 'CMPSC ' |
| 90 | + String.format("%3s", nums[0]) // ' 8' | |
| 91 | ; | |
| 92 | } | |
| 93 |
1
1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED |
return String.format("%-8s", subjectArea) // 'CMPSC ' |
| 94 | + String.format("%3s", nums[0]) // ' 8' | |
| 95 | + String.format("%-2s", suffs[1]) // 'A ' | |
| 96 | ; | |
| 97 | } | |
| 98 | } | |
Mutations | ||
| 69 |
1.1 |
|
| 82 |
1.1 |
|
| 88 |
1.1 2.2 |
|
| 89 |
1.1 |
|
| 93 |
1.1 |