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