Add national days API to calendar

This commit is contained in:
2024-12-19 11:03:40 -05:00
parent 532ee37169
commit edc4d13d85
11 changed files with 102 additions and 1 deletions

View File

@@ -1,2 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kaczor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -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
###

View File

@@ -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<ActionResult<Response>> 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<Response>(restRequest);
return Ok(response?.Data.Where(d => d.Type == "day"));
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<Entry> Data { get; set; } = Array.Empty<Entry>();
}

View File

@@ -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<HttpClient>();
builder.Services.AddSingleton(new RestClient());
builder.Services.AddControllers();

View File

@@ -17,6 +17,7 @@
</PackageReference>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
</ItemGroup>

View File

@@ -0,0 +1,16 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Calendar": {
"PersonalUrl": "",
"HolidayUrl": "",
"NationalDays": {
"Url": "",
"Key": ""
}
}
}

View File

@@ -11,6 +11,10 @@
},
"Calendar": {
"PersonalUrl": "",
"HolidayUrl": ""
"HolidayUrl": "",
"NationalDays": {
"Url": "",
"Key": ""
}
}
}

View File

@@ -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