| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.courses.documents.Primary; | |
| 4 | import edu.ucsb.cs156.courses.repositories.UserRepository; | |
| 5 | import edu.ucsb.cs156.courses.services.UCSBCurriculumService; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import java.util.ArrayList; | |
| 10 | import java.util.HashSet; | |
| 11 | import java.util.List; | |
| 12 | import java.util.Set; | |
| 13 | import lombok.extern.slf4j.Slf4j; | |
| 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 | @Tag(name = "UCSBCurriculumController") | |
| 22 | @RestController | |
| 23 | @RequestMapping("/api/public") | |
| 24 | @Slf4j | |
| 25 | public class UCSBCurriculumController extends ApiController { | |
| 26 | ||
| 27 | @Autowired UserRepository userRepository; | |
| 28 | @Autowired UCSBCurriculumService ucsbCurriculumService; | |
| 29 | ||
| 30 | @Operation( | |
| 31 | summary = | |
| 32 | "Get course data (in original UCSB API format) for a given quarter, department, and level") | |
| 33 | @GetMapping(value = "/basicsearch", produces = "application/json") | |
| 34 | public ResponseEntity<String> basicsearch( | |
| 35 | @RequestParam String qtr, @RequestParam String dept, @RequestParam String level) | |
| 36 | throws Exception { | |
| 37 | ||
| 38 | String body = ucsbCurriculumService.getJSON(dept, qtr, level); | |
| 39 | ||
| 40 |
1
1. basicsearch : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::basicsearch → KILLED |
return ResponseEntity.ok().body(body); |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Get primaries for a given quarter, department, and level. This endpoint returns a list of | |
| 45 | * Primary objects. | |
| 46 | * | |
| 47 | * @param qtr the quarter in YYYYQ format | |
| 48 | * @param dept the department code (e.g., "CS") | |
| 49 | * @param level the course level (e.g., "UG" for undergraduate) | |
| 50 | * @return a list of Primary objects | |
| 51 | */ | |
| 52 | @Operation(summary = "Get primaries for a given quarter, department, and level") | |
| 53 | @GetMapping(value = "/primaries", produces = "application/json") | |
| 54 | public List<Primary> primaries( | |
| 55 | @RequestParam String qtr, @RequestParam String dept, @RequestParam String level) | |
| 56 | throws Exception { | |
| 57 | ||
| 58 | List<Primary> primaries = ucsbCurriculumService.getPrimaries(dept, qtr, level); | |
| 59 | ||
| 60 |
1
1. primaries : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primaries → KILLED |
return primaries; |
| 61 | } | |
| 62 | ||
| 63 | @Operation(summary = "Get primaries for a given quarter and GE area (use 'ALL' for all areas)") | |
| 64 | @GetMapping(value = "/primariesge", produces = "application/json") | |
| 65 | public List<Primary> primariesGE(@RequestParam String qtr, @RequestParam String area) | |
| 66 | throws Exception { | |
| 67 |
1
1. primariesGE : negated conditional → KILLED |
if ("ALL".equals(area)) { |
| 68 | List<String> allCodes = ucsbCurriculumService.getAllRequirementCodes(); | |
| 69 | List<Primary> combined = new ArrayList<>(); | |
| 70 | Set<String> seen = new HashSet<>(); | |
| 71 | for (String code : allCodes) { | |
| 72 | List<Primary> primaries = ucsbCurriculumService.getPrimariesByGE(qtr, code); | |
| 73 | for (Primary p : primaries) { | |
| 74 |
1
1. primariesGE : negated conditional → KILLED |
if (seen.add(p.getCourseId())) { |
| 75 | combined.add(p); | |
| 76 | } | |
| 77 | } | |
| 78 | } | |
| 79 |
1
1. primariesGE : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primariesGE → KILLED |
return combined; |
| 80 | } | |
| 81 | List<Primary> primaries = ucsbCurriculumService.getPrimariesByGE(qtr, area); | |
| 82 | Set<String> seen = new HashSet<>(); | |
| 83 | List<Primary> deduped = new ArrayList<>(); | |
| 84 | for (Primary p : primaries) { | |
| 85 |
1
1. primariesGE : negated conditional → KILLED |
if (seen.add(p.getCourseId())) { |
| 86 | deduped.add(p); | |
| 87 | } | |
| 88 | } | |
| 89 |
1
1. primariesGE : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primariesGE → KILLED |
return deduped; |
| 90 | } | |
| 91 | ||
| 92 | // Backend for final exam info, similar to the above operation: | |
| 93 | @Operation(summary = "Get final exam information for a given quarter and course enrollment code") | |
| 94 | @GetMapping(value = "/finalsInfo", produces = "application/json") | |
| 95 | public ResponseEntity<String> finalsInfo( | |
| 96 | @RequestParam String quarterYYYYQ, @RequestParam String enrollCd) | |
| 97 | throws Exception { // Looks for quarter and code | |
| 98 | ||
| 99 | String body = ucsbCurriculumService.getFinalsInfo(quarterYYYYQ, enrollCd); | |
| 100 | ||
| 101 |
1
1. finalsInfo : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::finalsInfo → KILLED |
return ResponseEntity.ok().body(body); |
| 102 | } | |
| 103 | ||
| 104 | @Operation(summary = "Get General Education areas, optionally filtered by collegeCode") | |
| 105 | @GetMapping(value = "/generalEducationInfo", produces = "application/json") | |
| 106 | public ResponseEntity<?> generalEducationInfo( | |
| 107 | @Parameter(description = "Enter either L&S, ENGR, or CRST") | |
| 108 | @RequestParam(value = "collegeCode", required = false) | |
| 109 | String collegeCode) | |
| 110 | throws Exception { | |
| 111 | ||
| 112 |
1
1. generalEducationInfo : negated conditional → KILLED |
if (collegeCode != null) { |
| 113 | // returns List<String> of requirementCode | |
| 114 | List<String> codes = ucsbCurriculumService.getRequirementCodesByCollege(collegeCode); | |
| 115 |
1
1. generalEducationInfo : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::generalEducationInfo → KILLED |
return ResponseEntity.ok().body(codes); |
| 116 | } else { | |
| 117 | // returns the full raw JSON array | |
| 118 | String body = ucsbCurriculumService.getGeneralEducationInfo(); | |
| 119 |
1
1. generalEducationInfo : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::generalEducationInfo → KILLED |
return ResponseEntity.ok().body(body); |
| 120 | } | |
| 121 | } | |
| 122 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 60 |
1.1 |
|
| 67 |
1.1 |
|
| 74 |
1.1 |
|
| 79 |
1.1 |
|
| 85 |
1.1 |
|
| 89 |
1.1 |
|
| 101 |
1.1 |
|
| 112 |
1.1 |
|
| 115 |
1.1 |
|
| 119 |
1.1 |