| 1 | package edu.ucsb.cs156.spring.backenddemo.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.spring.backenddemo.services.ZipCodeQueryService; | |
| 4 | import lombok.extern.slf4j.Slf4j; | |
| 5 | ||
| 6 | import org.springframework.web.bind.annotation.GetMapping; | |
| 7 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | import org.springframework.web.bind.annotation.RequestParam; | |
| 9 | import org.springframework.web.bind.annotation.RestController; | |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.http.ResponseEntity; | |
| 12 | ||
| 13 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 14 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 15 | ||
| 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="Zip Code info from https://api.zippopotam.us/") | |
| 22 | @Slf4j | |
| 23 | @RestController | |
| 24 | @RequestMapping("/api/zipcode") | |
| 25 | public class ZipCodeController { | |
| 26 | ||
| 27 |     ObjectMapper mapper = new ObjectMapper(); | |
| 28 | ||
| 29 |     @Autowired | |
| 30 |     ZipCodeQueryService zipCodeQueryService; | |
| 31 | ||
| 32 |     @Operation(summary="Get info about a zip code", description ="Get country, place, longitude, latitude, and state info about a zipcode") | |
| 33 |     @GetMapping("/get") | |
| 34 |     public ResponseEntity<String> getZipCodes( | |
| 35 |         @Parameter(name="zipcode", example="93106") @RequestParam String zipcode | |
| 36 |     ) throws JsonProcessingException { | |
| 37 |         log.info("getZipCode: zipcode={}", zipcode); | |
| 38 |         String result = zipCodeQueryService.getJSON(zipcode); | |
| 39 | 1
1. getZipCodes : replaced return value with null for edu/ucsb/cs156/spring/backenddemo/controllers/ZipCodeController::getZipCodes → KILLED |         return ResponseEntity.ok().body(result); | 
| 40 |     } | |
| 41 | ||
| 42 | } | |
| Mutations | ||
| 39 | 1.1 |