| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 4 | import edu.ucsb.cs156.courses.collections.UpdateCollection; | |
| 5 | import edu.ucsb.cs156.courses.documents.Update; | |
| 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 lombok.extern.slf4j.Slf4j; | |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.data.domain.PageRequest; | |
| 12 | import org.springframework.data.domain.Sort.Direction; | |
| 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 | @Slf4j | |
| 19 | @Tag(name = "Updates", description = "API for course history updates") | |
| 20 | @RequestMapping("/api/updates") | |
| 21 | @RestController | |
| 22 | public class UpdateController extends ApiController { | |
| 23 | @Autowired UpdateCollection updateCollection; | |
| 24 | ||
| 25 | @Autowired ObjectMapper mapper; | |
| 26 | ||
| 27 | @Operation(summary = "Get updates for a subject area and quarter (most recent first)") | |
| 28 | @GetMapping(value = "", produces = "application/json") | |
| 29 | public Iterable<Update> getUpdates( | |
| 30 | @Parameter( | |
| 31 | name = "subjectArea", | |
| 32 | description = "Course subject area code (e.g. CMPSC) or ALL for all subject areas", | |
| 33 | example = "ALL", | |
| 34 | required = true) | |
| 35 | @RequestParam | |
| 36 | String subjectArea, | |
| 37 | @Parameter( | |
| 38 | name = "quarter", | |
| 39 | description = "Quarter in yyyyq format (e.g. 20221) or ALL for all quarters", | |
| 40 | example = "ALL", | |
| 41 | required = true) | |
| 42 | @RequestParam | |
| 43 | String quarter, | |
| 44 | @Parameter( | |
| 45 | name = "page", | |
| 46 | description = "what page of the data", | |
| 47 | example = "0", | |
| 48 | required = true) | |
| 49 | @RequestParam | |
| 50 | int page, | |
| 51 | @Parameter( | |
| 52 | name = "pageSize", | |
| 53 | description = "size of each page", | |
| 54 | example = "5", | |
| 55 | required = true) | |
| 56 | @RequestParam | |
| 57 | int pageSize) { | |
| 58 | Iterable<Update> updates = null; | |
| 59 | PageRequest pageRequest = PageRequest.of(page, pageSize, Direction.DESC, "lastUpdate"); | |
| 60 | ||
| 61 |
2
1. getUpdates : negated conditional → KILLED 2. getUpdates : negated conditional → KILLED |
if (subjectArea.toUpperCase().equals("ALL") && quarter.toUpperCase().equals("ALL")) { |
| 62 | updates = updateCollection.findAll(pageRequest); | |
| 63 |
1
1. getUpdates : negated conditional → KILLED |
} else if (subjectArea.toUpperCase().equals("ALL")) { |
| 64 | updates = updateCollection.findByQuarter(quarter, pageRequest); | |
| 65 |
1
1. getUpdates : negated conditional → KILLED |
} else if (quarter.toUpperCase().equals("ALL")) { |
| 66 | updates = updateCollection.findBySubjectArea(subjectArea, pageRequest); | |
| 67 | } else { | |
| 68 | updates = updateCollection.findBySubjectAreaAndQuarter(subjectArea, quarter, pageRequest); | |
| 69 | } | |
| 70 | log.info("updates: {}", updates); | |
| 71 |
1
1. getUpdates : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UpdateController::getUpdates → KILLED |
return updates; |
| 72 | } | |
| 73 | } | |
Mutations | ||
| 61 |
1.1 2.2 |
|
| 63 |
1.1 |
|
| 65 |
1.1 |
|
| 71 |
1.1 |