diff --git a/Calendar/Service/Calendar.http b/Calendar/Service/Calendar.http index 9db878a..32d3b8f 100644 --- a/Calendar/Service/Calendar.http +++ b/Calendar/Service/Calendar.http @@ -10,6 +10,16 @@ Accept: application/json ### +GET {{Calendar_HostAddress}}/calendar/upcoming?includeHolidays=true +Accept: application/json + +### + +GET {{Calendar_HostAddress}}/calendar/upcoming?days=7&includeHolidays=true +Accept: application/json + +### + GET {{Calendar_HostAddress}}/events/next Accept: application/json diff --git a/Calendar/Service/Controllers/CalendarController.cs b/Calendar/Service/Controllers/CalendarController.cs index 5e90b63..41810b2 100644 --- a/Calendar/Service/Controllers/CalendarController.cs +++ b/Calendar/Service/Controllers/CalendarController.cs @@ -7,10 +7,9 @@ namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers; [ApiController] public class CalendarController(IConfiguration configuration, HttpClient httpClient) : ControllerBase { - [HttpGet("upcoming")] - public async Task>> GetUpcoming([FromQuery] int days = 1) + private async Task> GetCalendarEntries(string calendarUrl, int days) { - var data = await httpClient.GetStringAsync(configuration["Calendar:PersonalUrl"]); + var data = await httpClient.GetStringAsync(calendarUrl); var calendar = Ical.Net.Calendar.Load(data); @@ -22,6 +21,20 @@ public class CalendarController(IConfiguration configuration, HttpClient httpCli .Select(o => new CalendarEntry(o)) .OrderBy(ce => ce.Start); + return calendarEntries; + } + + [HttpGet("upcoming")] + public async Task>> GetUpcoming([FromQuery] int days = 1, [FromQuery] bool includeHolidays = false) + { + var calendarEntries = await GetCalendarEntries(configuration["Calendar:PersonalUrl"]!, days); + + if (!includeHolidays) + return Ok(calendarEntries); + + var holidayEntries = await GetCalendarEntries(configuration["Calendar:HolidayUrl"]!, days); + calendarEntries = calendarEntries.Concat(holidayEntries).OrderBy(c => c.Start); + return Ok(calendarEntries); } } \ No newline at end of file