Skip to content

Commit 823256d

Browse files
committed
Add optional "includeSunday" query parameter to holiday endpoints
- Updated `HolidayRoutes` to include the optional `includeSunday` query parameter for fetching holidays. - Enhanced `ColombiaHolidays.GetHolidaysByYear` to support filtering holidays that fall on Sundays. - Adjusted validation and response logic in holiday endpoints accordingly.
1 parent c0eca55 commit 823256d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

api/Routes/HolidayRoutes.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using api.Models;
22
using api.Utils;
3+
using Microsoft.AspNetCore.Mvc;
34
using Swashbuckle.AspNetCore.Annotations;
45
using HolidayEndpointMetadataMessages = api.Utils.Messages.EndpointMetadata.HolidayEndpoint;
56

@@ -12,14 +13,14 @@ public static void RegisterHolidayAPI(WebApplication app)
1213
{
1314
const string API_HOLIDAY_ROUTE_COMPLETE = $"{Util.API_ROUTE}{Util.API_VERSION}{Util.HOLIDAY_ROUTE}";
1415

15-
app.MapGet($"{API_HOLIDAY_ROUTE_COMPLETE}/year/{{year}}", async (int year, DBContext db) =>
16+
app.MapGet($"{API_HOLIDAY_ROUTE_COMPLETE}/year/{{year}}", async (int year,[FromQuery] bool? includeSunday, DBContext db) =>
1617
{
1718
if (year < DateTime.MinValue.Year || year > DateTime.MaxValue.Year)
1819
{
1920
return Results.BadRequest(Messages.EndpointMetadata.HolidayEndpoint.BadRequestInvalidYear);
2021
}
2122

22-
List<Holiday> holidays = ColombiaHolidays.GetHolidaysByYear(year);
23+
List<Holiday> holidays = ColombiaHolidays.GetHolidaysByYear(year, includeSunday ?? false);
2324
return Results.Ok(holidays);
2425
})
2526
.Produces<List<Holiday>?>(200)
@@ -29,19 +30,19 @@ public static void RegisterHolidayAPI(WebApplication app)
2930
));
3031

3132

32-
app.MapGet($"{API_HOLIDAY_ROUTE_COMPLETE}/year/{{year}}/month/{{month}}", async (int year, int month, DBContext db) =>
33+
app.MapGet($"{API_HOLIDAY_ROUTE_COMPLETE}/year/{{year}}/month/{{month}}", async (int year, int month,[FromQuery] bool? includeSunday, DBContext db) =>
3334
{
34-
if (year < DateTime.MinValue.Year || year > DateTime.MaxValue.Year)
35+
if (year < DateTime.MinValue.Year || year > DateTime.MaxValue.Year)
3536
{
3637
return Results.BadRequest(Messages.EndpointMetadata.HolidayEndpoint.BadRequestInvalidYear);
3738
}
3839

39-
if ((month < 1 || month > 12))
40+
if (month is < 1 or > 12)
4041
{
4142
return Results.BadRequest(Messages.EndpointMetadata.HolidayEndpoint.BadRequestInvalidMonth);
4243
}
4344

44-
List<Holiday> holidays = ColombiaHolidays.GetHolidaysByYear(year);
45+
List<Holiday> holidays = ColombiaHolidays.GetHolidaysByYear(year, includeSunday ?? false);
4546

4647
var filteredHolidays = holidays
4748
.Where(h => h.Date.Month == month)
@@ -61,7 +62,7 @@ public static void RegisterHolidayAPI(WebApplication app)
6162

6263
public static class ColombiaHolidays
6364
{
64-
public static List<Holiday> GetHolidaysByYear(int year)
65+
public static List<Holiday> GetHolidaysByYear(int year, bool includeSundays = false)
6566
{
6667
HashSet<DateTime> holidayDates = new HashSet<DateTime>();
6768
List<Holiday> holidays = new List<Holiday>();
@@ -90,10 +91,14 @@ public static List<Holiday> GetHolidaysByYear(int year)
9091
DateTime holyThursday = easterSunday.AddDays(-3);
9192
DateTime holyFriday = easterSunday.AddDays(-2);
9293

93-
holidays.Add(new Holiday(sundaypalms, Messages.EndpointMetadata.Holidays.SUNDAY_PALMS_DESCRIPTION));
94-
holidays.Add(new Holiday(holyThursday, Messages.EndpointMetadata.Holidays.HOLY_THURSDAY_DESCRIPTION));
94+
if(includeSundays)
95+
holidays.Add(new Holiday(sundaypalms, Messages.EndpointMetadata.Holidays.SUNDAY_PALMS_DESCRIPTION));
96+
97+
holidays.Add(new Holiday(holyThursday, Messages.EndpointMetadata.Holidays.HOLY_THURSDAY_DESCRIPTION));
9598
holidays.Add(new Holiday(holyFriday, Messages.EndpointMetadata.Holidays.HOLY_FRIDAY_DESCRIPTION));
96-
holidays.Add(new Holiday(easterSunday, Messages.EndpointMetadata.Holidays.RESURRECTION_DESCRIPTION));
99+
100+
if(includeSundays)
101+
holidays.Add(new Holiday(easterSunday, Messages.EndpointMetadata.Holidays.RESURRECTION_DESCRIPTION));
97102

98103
holidays.Add(new Holiday(new DateTime(year, month: may, day: 1), Messages.EndpointMetadata.Holidays.LABOR_DAY_DESCRIPTION));
99104

0 commit comments

Comments
 (0)