-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountryCodeController.java
42 lines (32 loc) · 1.6 KB
/
CountryCodeController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package edu.ucsb.cs156.spring.backenddemo.controllers;
import edu.ucsb.cs156.spring.backenddemo.services.CountryCodeQueryService;
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.web.bind.annotation.RestController;
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="Country Code info from https://public.opendatasoft.com/explore/dataset/countries-codes")
@Slf4j
@RestController
@RequestMapping("/api/countrycodes")
public class CountryCodeController {
ObjectMapper mapper = new ObjectMapper();
@Autowired
CountryCodeQueryService countryCodeQueryService;
@Operation(summary="Get a country's ISO codes and more", description ="Country data uploaded to OpenDataSoft by the International Labour Organization")
@GetMapping("/get")
public ResponseEntity<String> getCountryCodes(
@Parameter(name="country", example="United States") @RequestParam String country
) throws JsonProcessingException {
log.info("getCountryCodes: country={}", country);
String result = countryCodeQueryService.getJSON(country);
return ResponseEntity.ok().body(result);
}
}