1 | package edu.ucsb.cs156.spring.backenddemo.controllers; | |
2 | ||
3 | import org.springframework.web.bind.annotation.RestController; | |
4 | ||
5 | import edu.ucsb.cs156.spring.backenddemo.services.JokeQueryService; | |
6 | import lombok.extern.slf4j.Slf4j; | |
7 | ||
8 | import org.springframework.web.bind.annotation.GetMapping; | |
9 | import org.springframework.web.bind.annotation.RequestMapping; | |
10 | import org.springframework.web.bind.annotation.RequestParam; | |
11 | import org.springframework.beans.factory.annotation.Autowired; | |
12 | import org.springframework.http.ResponseEntity; | |
13 | ||
14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
15 | import com.fasterxml.jackson.databind.ObjectMapper; | |
16 | ||
17 | import io.swagger.v3.oas.annotations.Operation; | |
18 | import io.swagger.v3.oas.annotations.Parameter; | |
19 | import io.swagger.v3.oas.annotations.tags.Tag; | |
20 | ||
21 | @Tag(name = "Jokes from https://v2.jokeapi.dev/") | |
22 | @Slf4j | |
23 | @RestController | |
24 | @RequestMapping("/api/jokes") | |
25 | public class JokeController { | |
26 | ||
27 | ObjectMapper mapper = new ObjectMapper(); | |
28 | ||
29 | @Autowired | |
30 | JokeQueryService jokeQueryService; | |
31 | ||
32 | @Operation(summary = "Get jokes for a given category and amount") | |
33 | @GetMapping("/get") | |
34 | public ResponseEntity<String> getJokes( | |
35 | @Parameter(name="category", description="category of joke", example="Programming") @RequestParam String category, | |
36 | @Parameter(name="amount", description="amount of jokes to get", example="1") @RequestParam String amount | |
37 | ) throws JsonProcessingException { | |
38 | log.info("getJokes: category={} numJokes={}", category, amount); | |
39 | String result = jokeQueryService.getJSON(category, amount); | |
40 |
1
1. getJokes : replaced return value with null for edu/ucsb/cs156/spring/backenddemo/controllers/JokeController::getJokes → KILLED |
return ResponseEntity.ok().body(result); |
41 | } | |
42 | } | |
43 | ||
44 | ||
45 | ||
Mutations | ||
40 |
1.1 |