2020-02-20 23:39:46 +01:00
|
|
|
package click.poweronoff.satellite.api;
|
|
|
|
|
|
|
|
|
2020-02-24 22:31:13 +01:00
|
|
|
import click.poweronoff.satellite.domain.Feature;
|
|
|
|
import click.poweronoff.satellite.service.DataService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2020-02-25 22:26:44 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
2020-02-20 23:39:46 +01:00
|
|
|
import org.springframework.stereotype.Controller;
|
2020-02-25 22:26:44 +01:00
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
2020-02-20 23:39:46 +01:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
2020-02-24 22:31:13 +01:00
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
2020-02-20 23:39:46 +01:00
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
2020-02-25 22:26:44 +01:00
|
|
|
import org.springframework.web.server.ResponseStatusException;
|
2020-02-20 23:39:46 +01:00
|
|
|
|
2020-02-24 22:31:13 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2020-02-20 23:39:46 +01:00
|
|
|
@Controller
|
|
|
|
public class FeaturesController {
|
2020-02-24 22:31:13 +01:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
DataService dataService;
|
|
|
|
|
|
|
|
@RequestMapping(value = "/features", method = RequestMethod.GET, produces = "application/json")
|
2020-02-25 22:26:44 +01:00
|
|
|
@ResponseBody
|
|
|
|
public List<Feature> features() {
|
2020-02-24 22:31:13 +01:00
|
|
|
return dataService.getAllFeatures();
|
2020-02-20 23:39:46 +01:00
|
|
|
}
|
|
|
|
|
2020-02-25 22:26:44 +01:00
|
|
|
@RequestMapping(value = "/features/{id}", method = RequestMethod.GET, produces = "application/json")
|
|
|
|
@ResponseBody
|
|
|
|
public Feature featureById(@PathVariable String id) {
|
|
|
|
return dataService.getFeature(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Unable to find feature"));
|
|
|
|
}
|
|
|
|
|
2020-02-27 11:26:46 +01:00
|
|
|
@RequestMapping(value = "/features/{id}/quicklook", method = RequestMethod.GET, produces = "image/png")
|
|
|
|
@ResponseBody
|
|
|
|
public byte[] quicklookByFeatureId(@PathVariable String id) {
|
|
|
|
return dataService.getPicture(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Unable to find feature"));
|
|
|
|
}
|
|
|
|
|
2020-02-20 23:39:46 +01:00
|
|
|
}
|