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