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.ArrayList; | |
10 | import java.util.List; | |
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 | @RestController | |
19 | @RequestMapping("/api/public/courseovertime") | |
20 | public class CourseOverTimeController { | |
21 | ||
22 | private ObjectMapper mapper = new ObjectMapper(); | |
23 | ||
24 | @Autowired ConvertedSectionCollection convertedSectionCollection; | |
25 | ||
26 | @Operation(summary = "Get a list of courses over time") | |
27 | @GetMapping(value = "/search", produces = "application/json") | |
28 | public ResponseEntity<String> search( | |
29 | @Parameter( | |
30 | name = "startQtr", | |
31 | description = | |
32 | "starting quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
33 | example = "20231", | |
34 | required = true) | |
35 | @RequestParam | |
36 | String startQtr, | |
37 | @Parameter( | |
38 | name = "endQtr", | |
39 | description = | |
40 | "ending 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 endQtr, | |
45 | @Parameter( | |
46 | name = "subjectArea", | |
47 | description = "simplified area name, e.g. CMPSC for computer science", | |
48 | example = "CMPSC", | |
49 | required = true) | |
50 | @RequestParam | |
51 | String subjectArea, | |
52 | @Parameter( | |
53 | name = "courseNumber", | |
54 | description = "the specific course number, e.g. 130A for CS130A", | |
55 | example = "130A", | |
56 | required = true) | |
57 | @RequestParam | |
58 | String courseNumber) | |
59 | throws JsonProcessingException { | |
60 | List<ConvertedSection> courseResults = | |
61 | new ArrayList<ConvertedSection>( | |
62 | convertedSectionCollection.findByQuarterRangeAndCourseId( | |
63 | startQtr, endQtr, makeFormattedCourseId(subjectArea, courseNumber))); | |
64 | ||
65 |
1
1. search : removed call to java/util/List::sort → KILLED |
courseResults.sort(new ConvertedSection.ConvertedSectionSortDescendingByQuarterComparator()); |
66 | ||
67 | String body = mapper.writeValueAsString(courseResults); | |
68 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED |
return ResponseEntity.ok().body(body); |
69 | } | |
70 | ||
71 | String makeFormattedCourseId(String subjectArea, String courseNumber) { | |
72 | String[] nums = courseNumber.split("[a-zA-Z]+"); | |
73 | String[] suffs = courseNumber.split("[0-9]+"); | |
74 |
2
1. makeFormattedCourseId : changed conditional boundary → KILLED 2. makeFormattedCourseId : negated conditional → KILLED |
if (suffs.length < 2) { // no suffix |
75 |
1
1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED |
return String.format("%-8s", subjectArea) // 'CMPSC ' |
76 | + String.format("%3s", nums[0]) // ' 8' | |
77 | ; | |
78 | } | |
79 |
1
1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED |
return String.format("%-8s", subjectArea) // 'CMPSC ' |
80 | + String.format("%3s", nums[0]) // ' 8' | |
81 | + String.format("%-2s", suffs[1]) // 'A ' | |
82 | ; | |
83 | } | |
84 | } | |
Mutations | ||
65 |
1.1 |
|
68 |
1.1 |
|
74 |
1.1 2.2 |
|
75 |
1.1 |
|
79 |
1.1 |