| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | ||
| 5 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
| 6 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
| 7 | import io.swagger.annotations.ApiOperation; | |
| 8 | ||
| 9 | import org.slf4j.Logger; | |
| 10 | import org.slf4j.LoggerFactory; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.http.ResponseEntity; | |
| 13 | import org.springframework.web.bind.annotation.GetMapping; | |
| 14 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 15 | import org.springframework.web.bind.annotation.RequestParam; | |
| 16 | import org.springframework.web.bind.annotation.RestController; | |
| 17 | ||
| 18 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 20 | ||
| 21 | @RestController | |
| 22 | @RequestMapping("/api/public/courseovertime") | |
| 23 | public class CourseOverTimeController { | |
| 24 | ||
| 25 |     private final Logger logger = LoggerFactory.getLogger(CourseOverTimeController.class); | |
| 26 | ||
| 27 |     private ObjectMapper mapper = new ObjectMapper(); | |
| 28 | ||
| 29 |     @Autowired | |
| 30 |     ConvertedSectionCollection convertedSectionCollection; | |
| 31 | ||
| 32 |     @ApiOperation(value = "Get a list of courses over time") | |
| 33 |     @GetMapping(value = "/search", produces = "application/json") | |
| 34 |     public ResponseEntity<String> search( | |
| 35 |         @RequestParam String startQtr, | |
| 36 |         @RequestParam String endQtr, | |
| 37 |         @RequestParam String subjectArea, | |
| 38 |         @RequestParam String courseNumber | |
| 39 |     ) throws JsonProcessingException { | |
| 40 |         List<ConvertedSection> courseResults = convertedSectionCollection.findByQuarterRangeAndCourseId( | |
| 41 |             startQtr, | |
| 42 |             endQtr, | |
| 43 |             makeFormattedCourseId(subjectArea, courseNumber) | |
| 44 |         ); | |
| 45 |         String body = mapper.writeValueAsString(courseResults); | |
| 46 | 
1
1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED | 
        return ResponseEntity.ok().body(body); | 
| 47 |     } | |
| 48 | ||
| 49 |     String makeFormattedCourseId(String subjectArea, String courseNumber) { | |
| 50 |         String[] nums = courseNumber.split("[a-zA-Z]+"); | |
| 51 |         String[] suffs = courseNumber.split("[0-9]+"); | |
| 52 | 
2
1. makeFormattedCourseId : changed conditional boundary → KILLED 2. makeFormattedCourseId : negated conditional → KILLED  | 
        if (suffs.length < 2) { // no suffix | 
| 53 | 
1
1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED | 
            return | 
| 54 |                   String.format( "%-8s", subjectArea                ) // 'CMPSC   ' | |
| 55 |                 + String.format( "%3s" , nums[0]                    ) // '  8' | |
| 56 |             ; | |
| 57 |         } | |
| 58 | 
1
1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED | 
        return | 
| 59 |               String.format( "%-8s", subjectArea                ) // 'CMPSC   ' | |
| 60 |             + String.format( "%3s" , nums[0]                    ) // '  8' | |
| 61 |             + String.format( "%-2s", suffs[1]                   ) // 'A ' | |
| 62 |         ; | |
| 63 |     } | |
| 64 |      | |
| 65 | } | |
Mutations | ||
| 46 | 
 
 1.1  | 
|
| 52 | 
 
 1.1 2.2  | 
|
| 53 | 
 
 1.1  | 
|
| 58 | 
 
 1.1  |