mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Add optional holidays to upcoming
This commit is contained in:
@@ -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
|
GET {{Calendar_HostAddress}}/events/next
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class CalendarController(IConfiguration configuration, HttpClient httpClient) : ControllerBase
|
public class CalendarController(IConfiguration configuration, HttpClient httpClient) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("upcoming")]
|
private async Task<IEnumerable<CalendarEntry>> GetCalendarEntries(string calendarUrl, int days)
|
||||||
public async Task<ActionResult<IEnumerable<CalendarEntry>>> GetUpcoming([FromQuery] int days = 1)
|
|
||||||
{
|
{
|
||||||
var data = await httpClient.GetStringAsync(configuration["Calendar:PersonalUrl"]);
|
var data = await httpClient.GetStringAsync(calendarUrl);
|
||||||
|
|
||||||
var calendar = Ical.Net.Calendar.Load(data);
|
var calendar = Ical.Net.Calendar.Load(data);
|
||||||
|
|
||||||
@@ -22,6 +21,20 @@ public class CalendarController(IConfiguration configuration, HttpClient httpCli
|
|||||||
.Select(o => new CalendarEntry(o))
|
.Select(o => new CalendarEntry(o))
|
||||||
.OrderBy(ce => ce.Start);
|
.OrderBy(ce => ce.Start);
|
||||||
|
|
||||||
|
return calendarEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("upcoming")]
|
||||||
|
public async Task<ActionResult<IEnumerable<CalendarEntry>>> 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);
|
return Ok(calendarEntries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user