@@ -11,6 +11,7 @@ namespace api.Controllers;
1111public class ThermalReferenceMetadataController (
1212 ILogger < ThermalReferenceMetadataController > logger ,
1313 IThermalReferenceMetadataService thermalReferenceMetadataService ,
14+ IThermalImageService thermalImageService ,
1415 IConfiguration configuration
1516) : ControllerBase
1617{
@@ -164,6 +165,41 @@ public async Task<ActionResult> DeleteThermalReferenceMetadata([FromRoute] Guid
164165 }
165166 }
166167
168+ [ HttpGet ( "id/{id}/image" ) ]
169+ [ Authorize ( Roles = Role . Any ) ]
170+ [ ProducesResponseType ( typeof ( FileContentResult ) , StatusCodes . Status200OK ) ]
171+ [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
172+ public async Task < ActionResult > GetThermalReferenceImage ( [ FromRoute ] Guid id )
173+ {
174+ try
175+ {
176+ var metadata = await thermalReferenceMetadataService . ReadById ( id ) ;
177+ if ( metadata is null )
178+ {
179+ return NotFound ( $ "Could not find thermal reference metadata with id { id } ") ;
180+ }
181+
182+ var result = await thermalImageService . GetThermalImageAsJpegAsync (
183+ metadata . ReferenceImageBlobStorageLocation
184+ ) ;
185+
186+ Response . Headers [ "X-Temperature-Min" ] = result . MinTemperature . ToString ( "F2" ) ;
187+ Response . Headers [ "X-Temperature-Max" ] = result . MaxTemperature . ToString ( "F2" ) ;
188+ Response . Headers [ "Access-Control-Expose-Headers" ] =
189+ "X-Temperature-Min, X-Temperature-Max" ;
190+
191+ return File ( result . JpegBytes , "image/jpeg" ) ;
192+ }
193+ catch ( Exception ex )
194+ {
195+ logger . LogError ( ex , "Error generating thermal reference image for id {Id}" , id ) ;
196+ return StatusCode (
197+ StatusCodes . Status500InternalServerError ,
198+ "An error occurred while generating the thermal reference image"
199+ ) ;
200+ }
201+ }
202+
167203 private (
168204 BlobStorageLocation imageLocation ,
169205 BlobStorageLocation polygonLocation
0 commit comments