-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from UKGovernmentBEIS/develop
Merge develop to staging
- Loading branch information
Showing
24 changed files
with
2,063 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
HerPublicWebsite.BusinessLogic/Services/RegularJobs/ReferralFollowUpService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using HerPublicWebsite.BusinessLogic.Models; | ||
|
||
namespace HerPublicWebsite.BusinessLogic.Services.RegularJobs; | ||
|
||
public interface IReferralFollowUpService | ||
{ | ||
public Task<IList<ReferralRequest>> GetReferralsPastTenWorkingDayThresholdWithNoFollowUp(); | ||
} | ||
|
||
public class ReferralFollowUpService : IReferralFollowUpService | ||
{ | ||
private readonly IDataAccessProvider dataProvider; | ||
private readonly CsvFileCreator.CsvFileCreator csvFileCreator; | ||
private readonly IWorkingDayHelperService workingDayHelperService; | ||
|
||
public ReferralFollowUpService( | ||
IDataAccessProvider dataProvider, | ||
CsvFileCreator.CsvFileCreator csvFileCreator, | ||
IWorkingDayHelperService workingDayHelperService) | ||
{ | ||
this.dataProvider = dataProvider; | ||
this.csvFileCreator = csvFileCreator; | ||
this.workingDayHelperService = workingDayHelperService; | ||
} | ||
|
||
public async Task<IList<ReferralRequest>> GetReferralsPastTenWorkingDayThresholdWithNoFollowUp() | ||
{ | ||
var endDate = await workingDayHelperService.AddWorkingDaysToDateTime(DateTime.Today, -10); | ||
return await dataProvider.GetReferralRequestsWithNoFollowUpBeforeDate(endDate); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
HerPublicWebsite.BusinessLogic/Services/RegularJobs/WorkingDayHelperService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using HerPublicWebsite.BusinessLogic.ExternalServices.Common; | ||
|
||
namespace HerPublicWebsite.BusinessLogic.Services.RegularJobs; | ||
|
||
public interface IWorkingDayHelperService | ||
{ | ||
public Task<DateTime> AddWorkingDaysToDateTime(DateTime initialDateTime, int workingDaysToAdd); | ||
} | ||
|
||
public class WorkingDayHelperService : IWorkingDayHelperService | ||
{ | ||
public async Task<DateTime> AddWorkingDaysToDateTime(DateTime initialDateTime, int workingDaysToAdd) | ||
{ | ||
var direction = workingDaysToAdd < 0 ? -1 : 1; | ||
var holidays = await getHolidays(); | ||
var newDateTime = initialDateTime; | ||
while (workingDaysToAdd != 0) | ||
{ | ||
newDateTime = newDateTime.AddDays(direction); | ||
if (newDateTime.DayOfWeek != DayOfWeek.Saturday && | ||
newDateTime.DayOfWeek != DayOfWeek.Sunday && | ||
!holidays.Contains(newDateTime.Date)) | ||
{ | ||
workingDaysToAdd -= direction; | ||
} | ||
} | ||
return newDateTime; | ||
} | ||
|
||
private async Task<List<DateTime>> getHolidays() { | ||
var parameters = new RequestParameters | ||
{ | ||
BaseAddress = "https://www.gov.uk/bank-holidays.json", | ||
}; | ||
var holidayDataJson = await HttpRequestHelper.SendGetRequestAsync<Dictionary<string, Holidays>>(parameters); | ||
var englandAndWalesHolidays = holidayDataJson["england-and-wales"]; | ||
return englandAndWalesHolidays.events.Select(x => x.date).ToList(); | ||
} | ||
|
||
private class Holidays { | ||
public List<Event> events { get; set;} | ||
} | ||
private class Event { | ||
public DateTime date { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.