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 | convertedSectionCollection.findByQuarterRangeAndBuildingCode( | |
58 | startQtr, endQtr, buildingCode); | |
59 | String body = mapper.writeValueAsString(courseResults); | |
60 | ||
61 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::search → KILLED |
return ResponseEntity.ok().body(body); |
62 | } | |
63 | ||
64 | @Operation( | |
65 | summary = | |
66 | "Get a list of classroom numbers within a particular building, given a quarter and building code") | |
67 | @GetMapping(value = "/buildingsearch/classrooms", produces = "application/json") | |
68 | public ResponseEntity<String> searchNew( | |
69 | @Parameter( | |
70 | name = "quarter", | |
71 | description = | |
72 | "Quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
73 | example = "20232", | |
74 | required = true) | |
75 | @RequestParam | |
76 | String quarter, | |
77 | @Parameter( | |
78 | name = "buildingCode", | |
79 | description = "Building code such as PHELP for Phelps, GIRV for Girvetz", | |
80 | example = "GIRV", | |
81 | required = true) | |
82 | @RequestParam | |
83 | String buildingCode) | |
84 | throws JsonProcessingException { | |
85 | List<ConvertedSection> courseResults = | |
86 | convertedSectionCollection.findByQuarterAndBuildingCode(quarter, buildingCode); | |
87 | ||
88 | Set<String> classrooms = | |
89 | courseResults.stream() | |
90 | .flatMap( | |
91 | result -> { | |
92 |
1
1. lambda$searchNew$0 : negated conditional → KILLED |
if (result.getSection() != null |
93 |
1
1. lambda$searchNew$0 : negated conditional → KILLED |
&& result.getSection().getTimeLocations() != null) { |
94 |
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(); |
95 | } else { | |
96 | return Stream.empty(); | |
97 | } | |
98 | }) | |
99 | .filter( | |
100 | loc -> | |
101 |
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)) |
102 |
1
1. lambda$searchNew$2 : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::lambda$searchNew$2 → KILLED |
.map(loc -> loc.getRoom()) |
103 |
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()) |
104 | .collect(Collectors.toCollection(TreeSet::new)); | |
105 | ||
106 | String body = mapper.writeValueAsString(classrooms); | |
107 |
1
1. searchNew : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeBuildingController::searchNew → KILLED |
return ResponseEntity.ok().body(body); |
108 | } | |
109 | } | |
Mutations | ||
61 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
101 |
1.1 2.2 3.3 |
|
102 |
1.1 |
|
103 |
1.1 2.2 3.3 |
|
107 |
1.1 |