diff options
| author | marcinzelent <zelent.marcin@gmail.com> | 2017-11-23 11:42:09 +0100 | 
|---|---|---|
| committer | marcinzelent <zelent.marcin@gmail.com> | 2017-11-23 11:42:09 +0100 | 
| commit | 55fa1f08621a975f439c50d853c4b55fe044e15f (patch) | |
| tree | a51c58fba8c63b4c5830a84d5ec4ed1c3b3d3e81 | |
| parent | 8f083ddb74fb74d6c2b5d347472aa26f18a4b15c (diff) | |
Added method for getting latest reading.
| -rw-r--r-- | AirPollutionWebApi.userprefs | 15 | ||||
| -rw-r--r-- | AirPollutionWebApi/Controllers/ReadingsController.cs | 19 | 
2 files changed, 32 insertions, 2 deletions
| diff --git a/AirPollutionWebApi.userprefs b/AirPollutionWebApi.userprefs index 68dadb7..fc3817b 100644 --- a/AirPollutionWebApi.userprefs +++ b/AirPollutionWebApi.userprefs @@ -1 +1,14 @@ -<Properties />
\ No newline at end of file +<Properties StartupConfiguration="{22C32F4C-0DEB-40EA-9D56-48942CBB2A07}|"> +  <MonoDevelop.Ide.ItemProperties.AirPollutionWebApi PreferredExecutionTarget="MonoDevelop.Default" /> +  <MonoDevelop.Ide.Workbench ActiveDocument="AirPollutionWebApi/Controllers/ReadingsController.cs"> +    <Files> +      <File FileName="AirPollutionWebApi/Controllers/ReadingsController.cs" Line="26" Column="18" /> +    </Files> +  </MonoDevelop.Ide.Workbench> +  <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> +  <MonoDevelop.Ide.DebuggingService.Breakpoints> +    <BreakpointStore /> +  </MonoDevelop.Ide.DebuggingService.Breakpoints> +  <MonoDevelop.Ide.DebuggingService.PinnedWatches /> +  <MultiItemStartupConfigurations /> +</Properties>
\ No newline at end of file diff --git a/AirPollutionWebApi/Controllers/ReadingsController.cs b/AirPollutionWebApi/Controllers/ReadingsController.cs index e8eb0fa..9173f72 100644 --- a/AirPollutionWebApi/Controllers/ReadingsController.cs +++ b/AirPollutionWebApi/Controllers/ReadingsController.cs @@ -21,7 +21,24 @@ namespace AirPollutionWebApi.Controllers  			if (reading != null) return Ok(reading);  			else return NotFound(); -		} +		}
 +
 +        [Route("/api/Readings/latest")]
 +        public IHttpActionResult GetLatestReading()
 +        {
 +            var readings = SqlOperator.GetAllReadings();
 +            Reading latestReading = null;
 + +            foreach(var reading in readings)
 +            {
 +                if (latestReading == null) latestReading = reading;
 +                if (reading.TimeStamp > latestReading.TimeStamp)
 +                    latestReading = reading;
 +            }
 + +			if (latestReading != null) return Ok(latestReading); +			else return NotFound();
 +        }  		public IHttpActionResult PutReading(int id, Reading reading)  		{ |