package com.cesca.sensors.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cesca.sensors.entity.DHTSensor;
import com.cesca.sensors.service.DHTSensorService;

@RestController
@RequestMapping("/REST/DHTSensor")
public class DHTSensorController {
	
	@Autowired
	public DHTSensorService dhtSensorService;
	
	@RequestMapping(method = RequestMethod.GET)
	public DHTSensor getLatestData(){
		return this.dhtSensorService.getLatestData();
	}
	
	@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public DHTSensor addData(@RequestBody DHTSensor dht){
		return this.dhtSensorService.addDHTSensorData(dht);
	}

}

@@ -28,24 +28,56 @@
 ontroller;%0A%0A
+import org.apache.log4j.Logger;%0A
 import org.s
@@ -659,16 +659,75 @@
 vice;%0A%09%0A
+%09private Logger log = Logger.getLogger(this.getClass());%0A%09%0A
 %09@Reques
@@ -796,30 +796,54 @@
 stData()%7B%0A%09%09
-return
+%0A%09%09try %7B%0A%09%09%09DHTSensor sensor =
  this.dhtSen
@@ -870,16 +870,136 @@
 Data();%0A
+%09%09%09return sensor;%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09log.error(%22Failed to get latest data from Database%22);%0A%09%09%7D%0A%09%09return null;%0A
 %09%7D%0A%09%0A%09@R

Handle exception when getting Sensor Status from Empty Database