Add timezone to national days API

This commit is contained in:
2024-12-21 22:09:32 -05:00
parent 6c00cf12e1
commit b27ccc1f49
3 changed files with 14 additions and 1 deletions

View File

@@ -34,3 +34,8 @@ GET {{Calendar_HostAddress}}/national-days/today
Accept: application/json
###
GET {{Calendar_HostAddress}}/national-days/today?timezone=America/New_York
Accept: application/json
###

View File

@@ -9,10 +9,14 @@ namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers;
public class NationalDaysController(IConfiguration configuration, RestClient restClient) : ControllerBase
{
[HttpGet("today")]
public async Task<ActionResult<Response>> GetToday()
public async Task<ActionResult<Response>> GetToday([FromQuery] string timezone = "Etc/UTC")
{
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timezone);
var timeZoneOffset = timeZoneInfo.GetUtcOffset(DateTimeOffset.Now).TotalHours;
var restRequest = new RestRequest(configuration["Calendar:NationalDays:Url"]);
restRequest.AddHeader("X-Api-Key", configuration["Calendar:NationalDays:Key"] ?? string.Empty);
restRequest.AddQueryParameter("timezone_offset", timeZoneOffset);
var response = await restClient.GetAsync<Response>(restRequest);