PLQuestionController.java

1
package edu.ucsb.cs.scaffold.controller;
2
3
import edu.ucsb.cs.scaffold.entity.PlQuestion;
4
import edu.ucsb.cs.scaffold.entity.PlRepo;
5
import edu.ucsb.cs.scaffold.errors.EntityNotFoundException;
6
import edu.ucsb.cs.scaffold.repository.PlQuestionRepository;
7
import edu.ucsb.cs.scaffold.repository.PlRepoRepository;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import java.util.List;
12
import lombok.extern.slf4j.Slf4j;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.security.access.prepost.PreAuthorize;
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
/**
21
 * Read-only: PlQuestions are created, updated, and deleted by the SyncPlRepo job (issues #45/#47),
22
 * which mirrors the repo's questions directory on GitHub — not by POST/DELETE endpoints.
23
 */
24
@Tag(name = "PlQuestion")
25
@RequestMapping("/api/plQuestion")
26
@RestController
27
@Slf4j
28
public class PLQuestionController extends ApiController {
29
30
  @Autowired private PlQuestionRepository plQuestionRepository;
31
32
  @Autowired private PlRepoRepository plRepoRepository;
33
34
  @Operation(summary = "List all PlQuestions for a PlRepo")
35
  @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_INSTRUCTOR')")
36
  @GetMapping("")
37
  public List<PlQuestion> allPlQuestions(
38
      @Parameter(name = "plrepoId") @RequestParam Long plrepoId) {
39 1 1. allPlQuestions : removed call to edu/ucsb/cs/scaffold/controller/PLQuestionController::ensurePlRepoExists → KILLED
    ensurePlRepoExists(plrepoId);
40 1 1. allPlQuestions : replaced return value with Collections.emptyList for edu/ucsb/cs/scaffold/controller/PLQuestionController::allPlQuestions → KILLED
    return plQuestionRepository.findByPlRepoId(plrepoId);
41
  }
42
43
  private void ensurePlRepoExists(Long plRepoId) {
44
    plRepoRepository
45
        .findById(plRepoId)
46 1 1. lambda$ensurePlRepoExists$0 : replaced return value with null for edu/ucsb/cs/scaffold/controller/PLQuestionController::lambda$ensurePlRepoExists$0 → KILLED
        .orElseThrow(() -> new EntityNotFoundException(PlRepo.class, plRepoId));
47
  }
48
}

Mutations

39

1.1
Location : allPlQuestions
Killed by : edu.ucsb.cs.scaffold.controller.PLQuestionControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controller.PLQuestionControllerTests]/[method:get_all_questions_for_non_existant_repo_returns_404()]
removed call to edu/ucsb/cs/scaffold/controller/PLQuestionController::ensurePlRepoExists → KILLED

40

1.1
Location : allPlQuestions
Killed by : edu.ucsb.cs.scaffold.controller.PLQuestionControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controller.PLQuestionControllerTests]/[method:instructor_can_get_all_questions_for_a_repo()]
replaced return value with Collections.emptyList for edu/ucsb/cs/scaffold/controller/PLQuestionController::allPlQuestions → KILLED

46

1.1
Location : lambda$ensurePlRepoExists$0
Killed by : edu.ucsb.cs.scaffold.controller.PLQuestionControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controller.PLQuestionControllerTests]/[method:get_all_questions_for_non_existant_repo_returns_404()]
replaced return value with null for edu/ucsb/cs/scaffold/controller/PLQuestionController::lambda$ensurePlRepoExists$0 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0