large-file-reading-challenge/src/main/java/eu/ztsh/lfr/web/TemperaturesController.java

32 lines
1 KiB
Java

package eu.ztsh.lfr.web;
import eu.ztsh.lfr.core.TemperaturesService;
import eu.ztsh.lfr.model.Average;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/temperatures")
public class TemperaturesController {
private final TemperaturesService temperaturesService;
@Autowired
public TemperaturesController(TemperaturesService temperaturesService) {
this.temperaturesService = temperaturesService;
}
@GetMapping("/{city}")
public ResponseEntity<List<Average>> getTemperatures(@PathVariable String city) {
var data = temperaturesService.getTemperaturesFor(city);
return data.isEmpty() ? ResponseEntity.notFound().build() : ResponseEntity.ok(data);
}
}