feat: TemperaturesService
This commit is contained in:
parent
b34f5b3301
commit
2f161d3481
3 changed files with 46 additions and 2 deletions
13
src/main/java/eu/ztsh/lfr/core/TemperaturesService.java
Normal file
13
src/main/java/eu/ztsh/lfr/core/TemperaturesService.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package eu.ztsh.lfr.core;
|
||||||
|
|
||||||
|
import eu.ztsh.lfr.model.Entry;
|
||||||
|
import jakarta.annotation.Nonnull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface TemperaturesService {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
List<Entry> getTemperaturesFor(String city);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package eu.ztsh.lfr.core.impl;
|
||||||
|
|
||||||
|
import eu.ztsh.lfr.core.TemperaturesService;
|
||||||
|
import eu.ztsh.lfr.model.Entry;
|
||||||
|
import jakarta.annotation.Nonnull;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TemperaturesServiceImpl implements TemperaturesService {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public List<Entry> getTemperaturesFor(String city) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
package eu.ztsh.lfr.web;
|
package eu.ztsh.lfr.web;
|
||||||
|
|
||||||
|
import eu.ztsh.lfr.core.TemperaturesService;
|
||||||
import eu.ztsh.lfr.model.Entry;
|
import eu.ztsh.lfr.model.Entry;
|
||||||
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -12,9 +15,18 @@ import java.util.List;
|
||||||
@RequestMapping("/api/temperatures")
|
@RequestMapping("/api/temperatures")
|
||||||
public class TemperaturesController {
|
public class TemperaturesController {
|
||||||
|
|
||||||
|
private final TemperaturesService temperaturesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public TemperaturesController(TemperaturesService temperaturesService) {
|
||||||
|
this.temperaturesService = temperaturesService;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/{city}")
|
@GetMapping("/{city}")
|
||||||
public List<Entry> getTemperatures(@PathVariable String city) {
|
public ResponseEntity<List<Entry>> getTemperatures(@PathVariable String city) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
var data = temperaturesService.getTemperaturesFor(city);
|
||||||
|
|
||||||
|
return data.isEmpty() ? ResponseEntity.notFound().build() : ResponseEntity.ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue