Compare commits

..

2 commits

Author SHA1 Message Date
2f161d3481
feat: TemperaturesService 2024-07-16 22:22:42 +02:00
b34f5b3301
feat: TemperaturesController 2024-07-16 21:57:52 +02:00
4 changed files with 69 additions and 0 deletions

View file

@ -36,3 +36,8 @@ Write an application that, at the endpoint specified by you, returns the yearly
} }
] ]
``` ```
## Usage
Temperature statistics endpoint: `/api/temperatures/{city}`
Returns HTTP 200 when city is found, 404 otherwise.

View 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);
}

View file

@ -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.");
}
}

View file

@ -0,0 +1,32 @@
package eu.ztsh.lfr.web;
import eu.ztsh.lfr.core.TemperaturesService;
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.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<Entry>> getTemperatures(@PathVariable String city) {
var data = temperaturesService.getTemperaturesFor(city);
return data.isEmpty() ? ResponseEntity.notFound().build() : ResponseEntity.ok(data);
}
}