File tree Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -161,4 +161,4 @@ public object GetResolutionStatus()
161161 return "Nenhum processo iniciado ou resolução não encontrada para hoje." ;
162162 }
163163 }
164- }
164+ }
Original file line number Diff line number Diff line change @@ -50,18 +50,37 @@ public IActionResult GetResolutionStatus()
5050 }
5151 }
5252
53- [ HttpGet ( "{date}.json " ) ]
54- public IActionResult GetDnsResolution ( string date )
53+ [ HttpGet ( "dns " ) ]
54+ public IActionResult GetDnsResolution ( [ FromQuery ] string ? date = null )
5555 {
56- var filePath = Path . Combine ( _storagePath , $ "{ date } .json") ;
56+ try
57+ {
58+ string filePath ;
5759
58- if ( System . IO . File . Exists ( filePath ) )
60+ if ( ! string . IsNullOrEmpty ( date ) )
61+ {
62+ filePath = Path . Combine ( _storagePath , $ "{ date } .json") ;
63+ }
64+ else
65+ {
66+ filePath = Directory . GetFiles ( _storagePath , "*.json" )
67+ . OrderByDescending ( f => System . IO . File . GetCreationTimeUtc ( f ) )
68+ . FirstOrDefault ( ) ?? string . Empty ;
69+ }
70+
71+ if ( System . IO . File . Exists ( filePath ) )
72+ {
73+ var jsonContent = System . IO . File . ReadAllText ( filePath ) ;
74+ var jsonObject = System . Text . Json . JsonSerializer . Deserialize < object > ( jsonContent ) ;
75+
76+ return Ok ( jsonObject ) ;
77+ }
78+
79+ return NotFound ( new { message = "Arquivo não encontrado." } ) ;
80+ } catch ( Exception ex )
5981 {
60- var json = System . IO . File . ReadAllText ( filePath ) ;
61- return Ok ( json ) ;
82+ return StatusCode ( 500 , new { message = "Erro interno ao processar a solicitação." , details = ex . Message } ) ;
6283 }
63-
64- return NotFound ( "Arquivo não encontrado." ) ;
6584 }
6685 }
6786}
You can’t perform that action at this time.
0 commit comments