EarthquakesController.java
package edu.ucsb.cs156.spring.backenddemo.controllers;
import org.springframework.web.bind.annotation.RestController;
import edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name="Earthquake info from USGS")
@Slf4j
@RestController
@RequestMapping("/api/earthquakes")
public class EarthquakesController {
ObjectMapper mapper = new ObjectMapper();
@Autowired
EarthquakeQueryService earthquakeQueryService;
@Operation(summary = "Get earthquakes a certain distance from UCSB's Storke Tower", description = "JSON return format documented here: https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php")
@GetMapping("/get")
public ResponseEntity<String> getEarthquakes(
@Parameter(name="distance", description="distance in km from Storke Tower", example="100") @RequestParam String distance,
@Parameter(name="minMag", description="minimum magnitude", example="2.5") @RequestParam String minMag
) throws JsonProcessingException {
log.info("getEarthquakes: distance={} minMag={}", distance, minMag);
String result = earthquakeQueryService.getJSON(distance, minMag);
return ResponseEntity.ok().body(result);
}
}