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 java.util.Set; | |
11 | import java.util.TreeSet; | |
12 | import java.util.stream.Collectors; | |
13 | import java.util.stream.Stream; | |
14 | import org.springframework.beans.factory.annotation.Autowired; | |
15 | import org.springframework.http.ResponseEntity; | |
16 | import org.springframework.web.bind.annotation.GetMapping; | |
17 | import org.springframework.web.bind.annotation.RequestMapping; | |
18 | import org.springframework.web.bind.annotation.RequestParam; | |
19 | import org.springframework.web.bind.annotation.RestController; | |
20 | ||
21 | @RestController | |
22 | @RequestMapping("/api/public/courseovertime") | |
23 | public class CourseOverTimeBuildingController { | |
24 | ||
25 | private ObjectMapper mapper = new ObjectMapper(); | |
26 | ||
27 | @Autowired ConvertedSectionCollection convertedSectionCollection; | |
28 | ||
29 | @Operation(summary = "Get a list of courses over time, filtered by (abbreviated) building code") | |
30 | @GetMapping(value = "/buildingsearch", produces = "application/json") | |
31 | public ResponseEntity<String> search( | |
32 | @Parameter( | |
33 | name = "startQtr", | |
34 | description = | |
35 | "Starting quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
36 | example = "20232", | |
37 | required = true) | |
38 | @RequestParam | |
39 | String startQtr, | |
40 | @Parameter( | |
41 | name = "endQtr", | |
42 | description = | |
43 | "Ending quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
44 | example = "20232", | |
45 | required = true) | |
46 | @RequestParam | |
47 | String endQtr, | |
48 | @Parameter( | |
49 | name = "buildingCode", | |
50 | description = "Building code such as PHELP for Phelps, GIRV for Girvetz", | |
51 | example = "GIRV", | |
52 | required = true) | |
53 | @RequestParam | |
54 | String buildingCode) | |
55 | throws JsonProcessingException { | |
56 | List<ConvertedSection> courseResults = | |
57 | new java.util.ArrayList<>( | |
58 | convertedSectionCollection.findByQuarterRangeAndBuildingCode( | |
59 | startQtr, endQtr, buildingCode)); | |
60 | ||
61 |
1
1. search : removed call to java/util/List::sort → KILLED |
courseResults.sort(new ConvertedSection.ConvertedSectionSortDescendingByQuarterComparator()); |
62 | ||
63 | String body = mapper.writeValueAsString(courseResults); | |
64 | ||
65 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::search → KILLED |
return ResponseEntity.ok().body(body); |
66 | } | |
67 | ||
68 | @Operation( | |
69 | summary = | |
70 | "Get a list of classroom numbers within a particular building, given a quarter and building code") | |
71 | @GetMapping(value = "/buildingsearch/classrooms", produces = "application/json") | |
72 | public ResponseEntity<String> searchNew( | |
73 | @Parameter( | |
74 | name = "quarter", | |
75 | description = | |
76 | "Quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
77 | example = "20232", | |
78 | required = true) | |
79 | @RequestParam | |
80 | String quarter, | |
81 | @Parameter( | |
82 | name = "buildingCode", | |
83 | description = "Building code such as PHELP for Phelps, GIRV for Girvetz", | |
84 | example = "GIRV", | |
85 | required = true) | |
86 | @RequestParam | |
87 | String buildingCode) | |
88 | throws JsonProcessingException { | |
89 | List<ConvertedSection> courseResults = | |
90 | convertedSectionCollection.findByQuarterAndBuildingCode(quarter, buildingCode); | |
91 | ||
92 | Set<String> classrooms = | |
93 | courseResults.stream() | |
94 | .flatMap( | |
95 | result -> { | |
96 |
1
1. lambda$searchNew$0 : negated conditional → KILLED |
if (result.getSection() != null |
97 |
1
1. lambda$searchNew$0 : negated conditional → KILLED |
&& result.getSection().getTimeLocations() != null) { |
98 |
1
1. lambda$searchNew$0 : replaced return value with Stream.empty for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::lambda$searchNew$0 → KILLED |
return result.getSection().getTimeLocations().stream(); |
99 | } else { | |
100 | return Stream.empty(); | |
101 | } | |
102 | }) | |
103 | .filter( | |
104 | loc -> | |
105 |
3
1. lambda$searchNew$1 : negated conditional → KILLED 2. lambda$searchNew$1 : replaced boolean return with true for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::lambda$searchNew$1 → KILLED 3. lambda$searchNew$1 : negated conditional → KILLED |
loc.getBuilding() != null && loc.getBuilding().equalsIgnoreCase(buildingCode)) |
106 |
1
1. lambda$searchNew$2 : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::lambda$searchNew$2 → KILLED |
.map(loc -> loc.getRoom()) |
107 |
3
1. lambda$searchNew$3 : replaced boolean return with true for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::lambda$searchNew$3 → KILLED 2. lambda$searchNew$3 : negated conditional → KILLED 3. lambda$searchNew$3 : negated conditional → KILLED |
.filter(room -> room != null && !room.isEmpty()) |
108 | .collect(Collectors.toCollection(TreeSet::new)); | |
109 | ||
110 | String body = mapper.writeValueAsString(classrooms); | |
111 |
1
1. searchNew : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::searchNew → KILLED |
return ResponseEntity.ok().body(body); |
112 | } | |
113 | } | |
Mutations | ||
61 |
1.1 |
|
65 |
1.1 |
|
96 |
1.1 |
|
97 |
1.1 |
|
98 |
1.1 |
|
105 |
1.1 2.2 3.3 |
|
106 |
1.1 |
|
107 |
1.1 2.2 3.3 |
|
111 |
1.1 |