CourseOverTimeDescriptionController.java

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 edu.ucsb.cs156.courses.documents.Primary;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import java.util.ArrayList;
11
import java.util.List;
12
import java.util.regex.Pattern;
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/description")
22
public class CourseOverTimeDescriptionController {
23
24
  private ObjectMapper mapper = new ObjectMapper();
25
26
  @Autowired ConvertedSectionCollection convertedSectionCollection;
27
28
  @Operation(summary = "Get a list of courses over time, filtered by course title or description")
29
  @GetMapping(value = "/search", produces = "application/json")
30
  public ResponseEntity<String> search(
31
      @Parameter(
32
              name = "startQtr",
33
              description =
34
                  "Starting quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
35
              example = "20232",
36
              required = true)
37
          @RequestParam
38
          String startQtr,
39
      @Parameter(
40
              name = "endQtr",
41
              description =
42
                  "Ending quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
43
              example = "20232",
44
              required = true)
45
          @RequestParam
46
          String endQtr,
47
      @Parameter(
48
              name = "searchTerms",
49
              description =
50
                  "Search terms to filter by course title or description, e.g. 'data science', 'computer architecture', etc.",
51
              example = "Data",
52
              required = true)
53
          @RequestParam
54
          String searchTerms,
55
      @Parameter(
56
              name = "lectureOnly",
57
              description = "Lectures only",
58
              example = "true",
59
              required = true)
60
          @RequestParam
61
          boolean lectureOnly)
62
      throws JsonProcessingException {
63
    List<ConvertedSection> courseResults;
64 1 1. search : negated conditional → KILLED
    String sectionRegex = lectureOnly ? ".*00$" : ".*";
65
    String escapedSearchTerms = Pattern.quote(searchTerms);
66
67
    courseResults =
68
        new ArrayList<>(
69
            convertedSectionCollection.findByQuarterRangeAndSearchTerms(
70
                startQtr, endQtr, escapedSearchTerms, sectionRegex));
71
72
    List<Primary> primaries = Primary.fromConvertedSections(courseResults);
73
74
    String body = mapper.writeValueAsString(primaries);
75 1 1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeDescriptionController::search → KILLED
    return ResponseEntity.ok().body(body);
76
  }
77
}

Mutations

64

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeDescriptionControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeDescriptionControllerTests]/[method:test_search_escapesRegexSpecialCharacters()]
negated conditional → KILLED

75

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeDescriptionControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeDescriptionControllerTests]/[method:test_search_emptyRequest()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeDescriptionController::search → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1