mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Add national days API to calendar
This commit is contained in:
@@ -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>
|
||||
@@ -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
|
||||
|
||||
###
|
||||
|
||||
21
Calendar/Service/Controllers/NationalDaysController.cs
Normal file
21
Calendar/Service/Controllers/NationalDaysController.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
12
Calendar/Service/Models/NationalDays/Entry.cs
Normal file
12
Calendar/Service/Models/NationalDays/Entry.cs
Normal 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;
|
||||
}
|
||||
17
Calendar/Service/Models/NationalDays/Meta.cs
Normal file
17
Calendar/Service/Models/NationalDays/Meta.cs
Normal 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;
|
||||
}
|
||||
11
Calendar/Service/Models/NationalDays/Response.cs
Normal file
11
Calendar/Service/Models/NationalDays/Response.cs
Normal 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>();
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
16
Calendar/Service/appsettings.Development.json
Normal file
16
Calendar/Service/appsettings.Development.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"Calendar": {
|
||||
"PersonalUrl": "",
|
||||
"HolidayUrl": "",
|
||||
"NationalDays": {
|
||||
"Url": "",
|
||||
"Key": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@
|
||||
},
|
||||
"Calendar": {
|
||||
"PersonalUrl": "",
|
||||
"HolidayUrl": ""
|
||||
"HolidayUrl": "",
|
||||
"NationalDays": {
|
||||
"Url": "",
|
||||
"Key": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user