diff --git a/Calendar/Calendar.sln.DotSettings b/Calendar/Calendar.sln.DotSettings index c960585..52c4ba6 100644 --- a/Calendar/Calendar.sln.DotSettings +++ b/Calendar/Calendar.sln.DotSettings @@ -1,2 +1,4 @@  + NEVER + NEVER True \ No newline at end of file diff --git a/Calendar/Service/Calendar.http b/Calendar/Service/Calendar.http index 32d3b8f..1bfc3ec 100644 --- a/Calendar/Service/Calendar.http +++ b/Calendar/Service/Calendar.http @@ -29,3 +29,8 @@ GET {{Calendar_HostAddress}}/events/next?timezone=America/New_York Accept: application/json ### + +GET {{Calendar_HostAddress}}/national-days/today +Accept: application/json + +### diff --git a/Calendar/Service/Controllers/NationalDaysController.cs b/Calendar/Service/Controllers/NationalDaysController.cs new file mode 100644 index 0000000..710fc76 --- /dev/null +++ b/Calendar/Service/Controllers/NationalDaysController.cs @@ -0,0 +1,21 @@ +using ChrisKaczor.HomeMonitor.Calendar.Service.Models.NationalDays; +using Microsoft.AspNetCore.Mvc; +using RestSharp; + +namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers; + +[Route("national-days")] +[ApiController] +public class NationalDaysController(IConfiguration configuration, RestClient restClient) : ControllerBase +{ + [HttpGet("today")] + public async Task> GetToday() + { + var restRequest = new RestRequest(configuration["Calendar:NationalDays:Url"]); + restRequest.AddHeader("X-Api-Key", configuration["Calendar:NationalDays:Key"] ?? string.Empty); + + var response = await restClient.GetAsync(restRequest); + + return Ok(response?.Data.Where(d => d.Type == "day")); + } +} \ No newline at end of file diff --git a/Calendar/Service/Models/NationalDays/Entry.cs b/Calendar/Service/Models/NationalDays/Entry.cs new file mode 100644 index 0000000..6ce8f08 --- /dev/null +++ b/Calendar/Service/Models/NationalDays/Entry.cs @@ -0,0 +1,12 @@ +using JetBrains.Annotations; + +namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models.NationalDays; + +[PublicAPI] +public class Entry +{ + public string Name { get; set; } = string.Empty; + public string Url { get; set; } = string.Empty; + public string Excerpt { get; set; } = string.Empty; + public string Type { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Calendar/Service/Models/NationalDays/Meta.cs b/Calendar/Service/Models/NationalDays/Meta.cs new file mode 100644 index 0000000..5c4312f --- /dev/null +++ b/Calendar/Service/Models/NationalDays/Meta.cs @@ -0,0 +1,17 @@ +using JetBrains.Annotations; +using System.Text.Json.Serialization; + +namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models.NationalDays; + +[PublicAPI] +public class Meta +{ + [JsonPropertyName("cache_status")] + public string CacheStatus { get; set; } = string.Empty; + + [JsonPropertyName("response_count")] + public int ResponseCount { get; set; } + + [JsonPropertyName("request_type")] + public string RequestType { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Calendar/Service/Models/NationalDays/Response.cs b/Calendar/Service/Models/NationalDays/Response.cs new file mode 100644 index 0000000..e1db250 --- /dev/null +++ b/Calendar/Service/Models/NationalDays/Response.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; + +namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models.NationalDays; + +[PublicAPI] +public class Response +{ + public int Code { get; set; } + public Meta Meta { get; set; } = new(); + public IEnumerable Data { get; set; } = Array.Empty(); +} \ No newline at end of file diff --git a/Calendar/Service/Program.cs b/Calendar/Service/Program.cs index 5c5e3f9..2d9fd26 100644 --- a/Calendar/Service/Program.cs +++ b/Calendar/Service/Program.cs @@ -1,4 +1,5 @@ using ChrisKaczor.Common.OpenTelemetry; +using RestSharp; using System.Reflection; namespace ChrisKaczor.HomeMonitor.Calendar.Service; @@ -21,6 +22,7 @@ public static class Program builder.Configuration["Telemetry:Endpoint"]); builder.Services.AddSingleton(); + builder.Services.AddSingleton(new RestClient()); builder.Services.AddControllers(); diff --git a/Calendar/Service/Service.csproj b/Calendar/Service/Service.csproj index 7958ba6..f6c9621 100644 --- a/Calendar/Service/Service.csproj +++ b/Calendar/Service/Service.csproj @@ -17,6 +17,7 @@ + diff --git a/Calendar/Service/appsettings.Development.json b/Calendar/Service/appsettings.Development.json new file mode 100644 index 0000000..2ac0399 --- /dev/null +++ b/Calendar/Service/appsettings.Development.json @@ -0,0 +1,16 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "Calendar": { + "PersonalUrl": "", + "HolidayUrl": "", + "NationalDays": { + "Url": "", + "Key": "" + } + } +} diff --git a/Calendar/Service/appsettings.json b/Calendar/Service/appsettings.json index 9efb8d9..0d35321 100644 --- a/Calendar/Service/appsettings.json +++ b/Calendar/Service/appsettings.json @@ -11,6 +11,10 @@ }, "Calendar": { "PersonalUrl": "", - "HolidayUrl": "" + "HolidayUrl": "", + "NationalDays": { + "Url": "", + "Key": "" + } } } diff --git a/Calendar/Service/deploy/manifest.yaml b/Calendar/Service/deploy/manifest.yaml index 7f5012e..c42259d 100644 --- a/Calendar/Service/deploy/manifest.yaml +++ b/Calendar/Service/deploy/manifest.yaml @@ -35,6 +35,16 @@ spec: secretKeyRef: name: calendar-config key: HOLIDAYS_URL + - name: Calendar__NationalDays__Url + valueFrom: + secretKeyRef: + name: calendar-config + key: NATIONAL_DAYS_URL + - name: Calendar__NationalDays__Key + valueFrom: + secretKeyRef: + name: calendar-config + key: NATIONAL_DAYS_KEY restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: ClusterFirst