From 0384879bead3b0ca0e6a3af531573560ab8b69c2 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Wed, 1 Apr 2026 12:16:17 -0400 Subject: [PATCH] Handle multiple countries for national days --- .../Service/Controllers/NationalDaysController.cs | 9 +++++---- Calendar/Service/Models/HolidayCalendar/Country.cs | 11 +++++++++++ Calendar/Service/Models/HolidayCalendar/Item.cs | 1 + Calendar/Service/appsettings.json | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 Calendar/Service/Models/HolidayCalendar/Country.cs diff --git a/Calendar/Service/Controllers/NationalDaysController.cs b/Calendar/Service/Controllers/NationalDaysController.cs index 4a85924..aefecb5 100644 --- a/Calendar/Service/Controllers/NationalDaysController.cs +++ b/Calendar/Service/Controllers/NationalDaysController.cs @@ -1,8 +1,8 @@ using ChrisKaczor.HomeMonitor.Calendar.Service.Models; -using DaysOfTheYear = ChrisKaczor.HomeMonitor.Calendar.Service.Models.DaysOfTheYear; -using HolidayCalendar = ChrisKaczor.HomeMonitor.Calendar.Service.Models.HolidayCalendar; using Microsoft.AspNetCore.Mvc; using RestSharp; +using DaysOfTheYear = ChrisKaczor.HomeMonitor.Calendar.Service.Models.DaysOfTheYear; +using HolidayCalendar = ChrisKaczor.HomeMonitor.Calendar.Service.Models.HolidayCalendar; namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers; @@ -51,17 +51,18 @@ public class NationalDaysController(IConfiguration configuration, RestClient res var now = DateTimeOffset.UtcNow.ToOffset(timeZoneOffset); var dateString = now.ToString("yyyy-MM-dd"); + var countries = configuration.GetSection("Calendar:HolidayCalendar:CountryCodes").Get>() ?? []; + var restRequest = new RestRequest(configuration["Calendar:HolidayCalendar:Url"]); restRequest.AddHeader("Authorization", $"Bearer {configuration["Calendar:HolidayCalendar:Key"] ?? string.Empty}"); restRequest.AddQueryParameter("limit", 100); - restRequest.AddQueryParameter("country", configuration["Calendar:HolidayCalendar:Country"]); restRequest.AddQueryParameter("type", "Day"); restRequest.AddQueryParameter("startDate", dateString); restRequest.AddQueryParameter("endDate", dateString); var response = await restClient.GetAsync(restRequest); - var nationalDays = response?.Data.Items.Select(i => new NationalDay(i)); + var nationalDays = response?.Data.Items.Where(i => countries.Contains(i.Country.Code)).Select(i => new NationalDay(i)); return nationalDays; } diff --git a/Calendar/Service/Models/HolidayCalendar/Country.cs b/Calendar/Service/Models/HolidayCalendar/Country.cs new file mode 100644 index 0000000..2865928 --- /dev/null +++ b/Calendar/Service/Models/HolidayCalendar/Country.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; + +namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models.HolidayCalendar; + +[PublicAPI] +public class Country +{ + public required string Id { get; set; } + public required string Name { get; set; } + public required string Code { get; set; } +} \ No newline at end of file diff --git a/Calendar/Service/Models/HolidayCalendar/Item.cs b/Calendar/Service/Models/HolidayCalendar/Item.cs index 62b5ca7..ff84ef1 100644 --- a/Calendar/Service/Models/HolidayCalendar/Item.cs +++ b/Calendar/Service/Models/HolidayCalendar/Item.cs @@ -10,4 +10,5 @@ public class Item public required string Excerpt { get; set; } public required string Url { get; set; } public required string Type { get; set; } + public required Country Country { get; set; } } \ No newline at end of file diff --git a/Calendar/Service/appsettings.json b/Calendar/Service/appsettings.json index fec28cb..fc9d9e0 100644 --- a/Calendar/Service/appsettings.json +++ b/Calendar/Service/appsettings.json @@ -19,7 +19,7 @@ "HolidayCalendar": { "Url": "", "Key": "", - "Country": "recYxvMVBeTBnsPrJ" + "CountryCodes": [ "US", "INTL" ] }, "NationalDays": { "Provider": "HolidayCalendar"