✨ Notable days next
This commit is contained in:
@@ -48,4 +48,32 @@ public class NotableDaysController(NotableDaysService days) : ControllerBase
|
||||
var result = await days.GetNotableDays(currentYear, region);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("{regionCode}/next")]
|
||||
public async Task<ActionResult<NotableDay?>> GetNextHoliday(string regionCode)
|
||||
{
|
||||
var result = await days.GetNextHoliday(regionCode);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound("No upcoming holidays found");
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("me/next")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<NotableDay?>> GetAccountNextHoliday()
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||
|
||||
var region = currentUser.Region;
|
||||
if (string.IsNullOrWhiteSpace(region)) region = "us";
|
||||
|
||||
var result = await days.GetNextHoliday(region);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound("No upcoming holidays found");
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using Nager.Holiday;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Pass.Account;
|
||||
|
||||
@@ -31,4 +32,24 @@ public class NotableDaysService(ICacheService cache)
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
public async Task<NotableDay?> GetNextHoliday(string regionCode)
|
||||
{
|
||||
var currentDate = SystemClock.Instance.GetCurrentInstant();
|
||||
var currentYear = currentDate.InUtc().Year;
|
||||
|
||||
// Get holidays for current year and next year to cover all possibilities
|
||||
var currentYearHolidays = await GetNotableDays(currentYear, regionCode);
|
||||
var nextYearHolidays = await GetNotableDays(currentYear + 1, regionCode);
|
||||
|
||||
var allHolidays = currentYearHolidays.Concat(nextYearHolidays);
|
||||
|
||||
// Find the first holiday that is today or in the future
|
||||
var nextHoliday = allHolidays
|
||||
.Where(day => day.Date >= currentDate)
|
||||
.OrderBy(day => day.Date)
|
||||
.FirstOrDefault();
|
||||
|
||||
return nextHoliday;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user