Skip to content

Commit 8a23686

Browse files
authored
Merge pull request #9 from RobsonTrasel/main
Refatoração do endpoint DNS para suportar query parameter data e formato JSON
2 parents 4baf285 + c1ce6e5 commit 8a23686

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

bet-blocker/Business/BetBusiness.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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+
}

bet-blocker/Controllers/APIManagerController.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)