Skip to content

Commit

Permalink
Merge pull request #236 from UKGovernmentBEIS/develop
Browse files Browse the repository at this point in the history
Merge develop to staging
  • Loading branch information
jamiehumphries authored Jan 31, 2024
2 parents ddae3bf + dfed241 commit 87e27e1
Show file tree
Hide file tree
Showing 24 changed files with 2,063 additions and 33 deletions.
1 change: 1 addition & 0 deletions HerPublicWebsite.BusinessLogic/IDataAccessProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IDataAccessProvider
Task<ReferralRequest> PersistNewReferralRequestAsync(ReferralRequest referralRequest);
Task PersistNotificationConsentAsync(string referralId, NotificationDetails notificationDetails);
Task<IList<ReferralRequest>> GetUnsubmittedReferralRequestsAsync();
Task<IList<ReferralRequest>> GetReferralRequestsWithNoFollowUpBeforeDate(DateTime date);
Task<IList<ReferralRequest>> GetReferralRequestsByCustodianAndRequestDateAsync(string custodianCode, int month, int year);
Task<AnonymisedReport> PersistAnonymisedReportAsync(AnonymisedReport report);
Task<PerReferralReport> PersistPerReferralReportAsync(PerReferralReport report);
Expand Down
4 changes: 3 additions & 1 deletion HerPublicWebsite.BusinessLogic/Models/ReferralRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class ReferralRequest

public DateTime RequestDate { get; set; }

public bool ReferralWrittenToCsv { get; set; } = false;
public bool ReferralWrittenToCsv { get; set; }

public bool FollowUpEmailSent { get; set; }

public string ReferralCode { get; set; }

Expand Down
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);
}
}

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using HerPublicWebsite.BusinessLogic.ExternalServices.S3FileWriter;
using HerPublicWebsite.BusinessLogic.ExternalServices.S3FileWriter;

namespace HerPublicWebsite.BusinessLogic.Services.RegularJobs;

public interface IRegularJobsService
public interface IUnsubmittedReferralRequestsService
{
public Task RunNightlyTasksAsync();
public Task WriteUnsubmittedReferralRequestsToCsv();
}

public class RegularJobsService : IRegularJobsService
public class UnsubmittedReferralRequestsService : IUnsubmittedReferralRequestsService
{
private readonly IDataAccessProvider dataProvider;
private readonly IS3FileWriter s3FileWriter;
private readonly CsvFileCreator.CsvFileCreator csvFileCreator;

public RegularJobsService(
public UnsubmittedReferralRequestsService(
IDataAccessProvider dataProvider,
IS3FileWriter s3FileWriter,
CsvFileCreator.CsvFileCreator csvFileCreator)
Expand All @@ -22,8 +22,8 @@ public RegularJobsService(
this.s3FileWriter = s3FileWriter;
this.csvFileCreator = csvFileCreator;
}

public async Task RunNightlyTasksAsync()
public async Task WriteUnsubmittedReferralRequestsToCsv()
{
var newReferrals = await dataProvider.GetUnsubmittedReferralRequestsAsync();

Expand All @@ -46,3 +46,4 @@ public async Task RunNightlyTasksAsync()
}
}
}

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; }

}
}
7 changes: 7 additions & 0 deletions HerPublicWebsite.Data/DataAccessProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public async Task<IList<ReferralRequest>> GetUnsubmittedReferralRequestsAsync()
.ToListAsync();
}

public async Task<IList<ReferralRequest>> GetReferralRequestsWithNoFollowUpBeforeDate(DateTime cutoffDate)
{
return await context.ReferralRequests
.Where(rr => rr.RequestDate <= cutoffDate && !rr.FollowUpEmailSent)
.ToListAsync();
}

public async Task<IList<ReferralRequest>> GetReferralRequestsByCustodianAndRequestDateAsync(string custodianCode, int month, int year)
{
return await context.ReferralRequests
Expand Down
Loading

0 comments on commit 87e27e1

Please sign in to comment.