diff --git a/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java b/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java index e14a623cf58f50f92f8e672375a8cc278c44c6fb..e3da5c7e3537c1ed77f91e80b442fb47a2c486d6 100644 --- a/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/DatasetsApi.java @@ -5,21 +5,22 @@ package eu.hbp.mip.controllers; -import io.swagger.annotations.*; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import eu.hbp.mip.model.Dataset; +import io.swagger.annotations.*; import eu.hbp.mip.repositories.DatasetRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -// TODO: deprecate this @RestController @RequestMapping(value = "/datasets", produces = {APPLICATION_JSON_VALUE}) @@ -27,18 +28,30 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; public class DatasetsApi { private static final Logger LOGGER = LoggerFactory.getLogger(DatasetsApi.class); + private static final Gson gson = new Gson(); @Autowired private DatasetRepository datasetRepository; - @ApiOperation(value = "Get a dataset", response = Dataset.class) - @RequestMapping(value = "/{code}", method = RequestMethod.GET) - public ResponseEntity<Dataset> getADataset( - @ApiParam(value = "code", required = true) @PathVariable("code") String code + @ApiOperation(value = "Get dataset list", response = Dataset.class, responseContainer = "List") + @RequestMapping(method = RequestMethod.GET) + public ResponseEntity getDatasets( ) { - LOGGER.info("Get a dataset"); + LOGGER.info("Get dataset list"); + + JsonArray datasets = new JsonArray(); + + JsonObject o = new JsonObject(); + o.addProperty("code", "chuv"); + o.addProperty("label", "ĈHUV"); + datasets.add(o); + + JsonObject p = new JsonObject(); + p.addProperty("code", "brescia"); + p.addProperty("label", "Brescia"); + datasets.add(p); - return ResponseEntity.ok(datasetRepository.findOne(code)); + return ResponseEntity.ok(gson.toJson(datasets)); } }