Replace calendar service with new .NET version

This commit is contained in:
2024-12-18 11:59:05 -05:00
parent 4dbedee94b
commit 40ebbf38cb
25 changed files with 767 additions and 3504 deletions

View File

@@ -0,0 +1,27 @@
using ChrisKaczor.HomeMonitor.Calendar.Service.Models;
using Microsoft.AspNetCore.Mvc;
namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers;
[Route("calendar")]
[ApiController]
public class CalendarController(IConfiguration configuration, HttpClient httpClient) : ControllerBase
{
[HttpGet("upcoming")]
public async Task<ActionResult<IEnumerable<CalendarEntry>>> GetUpcoming([FromQuery] int? days)
{
var data = await httpClient.GetStringAsync(configuration["Calendar:PersonalUrl"]);
var calendar = Ical.Net.Calendar.Load(data);
var start = DateTimeOffset.Now.Date;
var end = start.AddDays(days ?? 1);
var calendarEntries = calendar
.GetOccurrences(start, end)
.Select(o => new CalendarEntry(o))
.OrderBy(ce => ce.Start);
return Ok(calendarEntries);
}
}

View File

@@ -0,0 +1,35 @@
using ChrisKaczor.HomeMonitor.Calendar.Service.Models;
using Microsoft.AspNetCore.Mvc;
namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers;
[Route("events")]
[ApiController]
public class HolidayController(IConfiguration configuration, HttpClient httpClient) : ControllerBase
{
[HttpGet("next")]
public async Task<ActionResult<IEnumerable<CalendarEntry>>> GetNext([FromQuery] string timezone = "Etc/UTC")
{
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timezone);
var data = await httpClient.GetStringAsync(configuration["Calendar:HolidayUrl"]);
var calendar = Ical.Net.Calendar.Load(data);
var start = DateTimeOffset.Now.Date;
var end = start.AddYears(1);
var calendarEntries = calendar
.GetOccurrences(start, end)
.Select(o => new CalendarEntry(o))
.OrderBy(ce => ce.Start);
var nextCalendarEntry = calendarEntries.First();
var holidayEntry = new HolidayEntry(nextCalendarEntry, timeZoneInfo);
var holidayResponse = new HolidayResponse(holidayEntry, timeZoneInfo);
return Ok(holidayResponse);
}
}