From 88cf5d1b83c28ea19933998e5250f3567587b47e Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Thu, 19 Dec 2024 09:51:38 -0500 Subject: [PATCH] Add holiday flag to data --- Calendar/Service/Controllers/CalendarController.cs | 8 ++++---- Calendar/Service/Controllers/HolidayController.cs | 2 +- Calendar/Service/Models/CalendarEntry.cs | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Calendar/Service/Controllers/CalendarController.cs b/Calendar/Service/Controllers/CalendarController.cs index 41810b2..fb3c217 100644 --- a/Calendar/Service/Controllers/CalendarController.cs +++ b/Calendar/Service/Controllers/CalendarController.cs @@ -7,7 +7,7 @@ namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers; [ApiController] public class CalendarController(IConfiguration configuration, HttpClient httpClient) : ControllerBase { - private async Task> GetCalendarEntries(string calendarUrl, int days) + private async Task> GetCalendarEntries(string calendarUrl, int days, bool isHoliday) { var data = await httpClient.GetStringAsync(calendarUrl); @@ -18,7 +18,7 @@ public class CalendarController(IConfiguration configuration, HttpClient httpCli var calendarEntries = calendar .GetOccurrences(start, end) - .Select(o => new CalendarEntry(o)) + .Select(o => new CalendarEntry(o, isHoliday)) .OrderBy(ce => ce.Start); return calendarEntries; @@ -27,12 +27,12 @@ public class CalendarController(IConfiguration configuration, HttpClient httpCli [HttpGet("upcoming")] public async Task>> GetUpcoming([FromQuery] int days = 1, [FromQuery] bool includeHolidays = false) { - var calendarEntries = await GetCalendarEntries(configuration["Calendar:PersonalUrl"]!, days); + var calendarEntries = await GetCalendarEntries(configuration["Calendar:PersonalUrl"]!, days, false); if (!includeHolidays) return Ok(calendarEntries); - var holidayEntries = await GetCalendarEntries(configuration["Calendar:HolidayUrl"]!, days); + var holidayEntries = await GetCalendarEntries(configuration["Calendar:HolidayUrl"]!, days, true); calendarEntries = calendarEntries.Concat(holidayEntries).OrderBy(c => c.Start); return Ok(calendarEntries); diff --git a/Calendar/Service/Controllers/HolidayController.cs b/Calendar/Service/Controllers/HolidayController.cs index 2127d22..eaab254 100644 --- a/Calendar/Service/Controllers/HolidayController.cs +++ b/Calendar/Service/Controllers/HolidayController.cs @@ -21,7 +21,7 @@ public class HolidayController(IConfiguration configuration, HttpClient httpClie var calendarEntries = calendar .GetOccurrences(start, end) - .Select(o => new CalendarEntry(o)) + .Select(o => new CalendarEntry(o, true)) .OrderBy(ce => ce.Start); var nextCalendarEntry = calendarEntries.First(); diff --git a/Calendar/Service/Models/CalendarEntry.cs b/Calendar/Service/Models/CalendarEntry.cs index 528f8f2..48ed2c1 100644 --- a/Calendar/Service/Models/CalendarEntry.cs +++ b/Calendar/Service/Models/CalendarEntry.cs @@ -5,10 +5,11 @@ using JetBrains.Annotations; namespace ChrisKaczor.HomeMonitor.Calendar.Service.Models; [PublicAPI] -public class CalendarEntry(Occurrence occurrence) +public class CalendarEntry(Occurrence occurrence, bool isHoliday) { public string Summary { get; set; } = ((CalendarEvent)occurrence.Source).Summary; public bool IsAllDay { get; set; } = ((CalendarEvent)occurrence.Source).IsAllDay; public DateTimeOffset Start { get; set; } = occurrence.Period.StartTime.AsDateTimeOffset; public DateTimeOffset End { get; set; } = occurrence.Period.EndTime.AsDateTimeOffset; + public bool IsHoliday { get; set; } = isHoliday; } \ No newline at end of file