1 | package edu.ucsb.cs156.spring.backenddemo.controllers; | |
2 | ||
3 | import org.springframework.web.bind.annotation.RestController; | |
4 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | |
5 | ||
6 | import io.swagger.v3.oas.annotations.Operation; | |
7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
8 | import lombok.extern.slf4j.Slf4j; | |
9 | ||
10 | import org.springframework.web.bind.annotation.GetMapping; | |
11 | import org.springframework.http.ResponseEntity; | |
12 | ||
13 | import java.net.URI; | |
14 | import java.util.ArrayList; | |
15 | import java.util.HashMap; | |
16 | import java.util.List; | |
17 | import java.util.Map; | |
18 | ||
19 | import com.fasterxml.jackson.core.JsonProcessingException; | |
20 | import com.fasterxml.jackson.databind.ObjectMapper; | |
21 | ||
22 | @Tag(name = "Home Page with links to documentation") | |
23 | @Slf4j | |
24 | @RestController | |
25 | public class HomeController { | |
26 | ||
27 | @Operation(summary = "Get general info about the server, including link to api documentation") | |
28 | @GetMapping("/") | |
29 | public ResponseEntity<String> getHome() throws JsonProcessingException { | |
30 | log.info("Home Page accessed"); | |
31 | ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequestUri(); | |
32 | // builder.scheme("http"); | |
33 | URI uri = builder.build().toUri(); | |
34 | ||
35 | String body = getHomePageObjectJSON(uri.toString()); | |
36 |
1
1. getHome : replaced return value with null for edu/ucsb/cs156/spring/backenddemo/controllers/HomeController::getHome → KILLED |
return ResponseEntity.ok().body(body); |
37 | } | |
38 | ||
39 | public static String getHomePageObjectJSON(String baseUrl) throws JsonProcessingException { | |
40 | ObjectMapper mapper = new ObjectMapper(); | |
41 | ||
42 | Map<String, Object> resultMap = new HashMap<String, Object>(); | |
43 | resultMap.put("greeting", "Greetings from Spring Boot!"); | |
44 | ||
45 | List<String> team = new ArrayList<String>(); | |
46 | team.add("Jing P."); | |
47 | team.add("Christian S."); | |
48 | team.add("Guy W."); | |
49 | team.add("Phill C."); | |
50 | resultMap.put("team", team); | |
51 | resultMap.put("repo", "https://github.com/ucsb-cs156-s24/STARTER-team01"); | |
52 | resultMap.put("api-documentation", baseUrl + "swagger-ui/index.html"); | |
53 |
1
1. getHomePageObjectJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/controllers/HomeController::getHomePageObjectJSON → KILLED |
return mapper.writeValueAsString(resultMap); |
54 | } | |
55 | } | |
Mutations | ||
36 |
1.1 |
|
53 |
1.1 |