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.HashSet; | |
11 | import java.util.List; | |
12 | import java.util.Set; | |
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.http.ResponseEntity; | |
15 | import org.springframework.web.bind.annotation.GetMapping; | |
16 | import org.springframework.web.bind.annotation.RequestMapping; | |
17 | import org.springframework.web.bind.annotation.RequestParam; | |
18 | import org.springframework.web.bind.annotation.RestController; | |
19 | ||
20 | @RestController | |
21 | @RequestMapping("/api/public/coursebuildingroom") | |
22 | public class CourseBuildingRoomController { | |
23 | ||
24 | private ObjectMapper mapper = new ObjectMapper(); | |
25 | ||
26 | @Autowired ConvertedSectionCollection convertedSectionCollection; | |
27 | ||
28 | @Operation(summary = "Get a list of classroom numbers from a building for a specified quarter") | |
29 | @GetMapping(value = "/buildingroomsearch", produces = "application/json") | |
30 | public ResponseEntity<String> search( | |
31 | @Parameter( | |
32 | name = "targetQtr", | |
33 | description = | |
34 | "Quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)", | |
35 | example = "20231", | |
36 | required = true) | |
37 | @RequestParam | |
38 | String targetQtr, | |
39 | @Parameter( | |
40 | name = "buildingCode", | |
41 | description = "Building code such as PHELP for Phelps, GIRV for Girvetz", | |
42 | example = "GIRV", | |
43 | required = true) | |
44 | @RequestParam | |
45 | String buildingCode) | |
46 | throws JsonProcessingException { | |
47 | ||
48 | // Fetch courses for the specified quarter and building | |
49 | List<ConvertedSection> courseResults = | |
50 | convertedSectionCollection.findByQuarterAndBuildingCode(targetQtr, buildingCode); | |
51 | ||
52 | // Use a Set to ensure unique room numbers | |
53 | Set<String> classroomNumbers = new HashSet<>(); | |
54 | ||
55 | // Iterate over each course and its timeLocations | |
56 | for (ConvertedSection course : courseResults) { | |
57 | // Iterate over the timeLocation array of each section | |
58 | for (edu.ucsb.cs156.courses.documents.TimeLocation timeLocation : | |
59 | course.getSection().getTimeLocations()) { | |
60 | String room = | |
61 | timeLocation | |
62 | .getRoom(); // Assuming `getRoom()` fetches the room number from timeLocation | |
63 |
2
1. search : negated conditional → KILLED 2. search : negated conditional → KILLED |
if (room != null && !room.isEmpty()) { |
64 | classroomNumbers.add(room); // Add room to the set, automatically ensuring uniqueness | |
65 | } | |
66 | } | |
67 | } | |
68 | ||
69 | // Convert the set of unique classroom numbers to a list | |
70 | List<String> uniqueClassrooms = new ArrayList<>(classroomNumbers); | |
71 | ||
72 | // Convert the classroom numbers list to JSON | |
73 | String body = mapper.writeValueAsString(uniqueClassrooms); | |
74 |
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseBuildingRoomController::search → KILLED |
return ResponseEntity.ok().body(body); |
75 | } | |
76 | } | |
Mutations | ||
63 |
1.1 2.2 |
|
74 |
1.1 |