Skip to content

Commit

Permalink
Merge pull request #172 from nationalarchives/feature/get_holiday_fro…
Browse files Browse the repository at this point in the history
…m_linked_view

Moving the bank-holiday data fetch from record-copying to doris
  • Loading branch information
ACTNA authored Sep 20, 2024
2 parents d6fc5f1 + 10c449f commit 2d238a1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 91 deletions.
14 changes: 0 additions & 14 deletions book-a-reading-room-visit.api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using NLog.Web;
using System.Net.Http.Headers;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -34,19 +33,6 @@

builder.Services.AddMemoryCache();

string sRecordCopyingUrl = Environment.GetEnvironmentVariable("RecordCopying_WebApi_URL") ?? string.Empty;

if (String.IsNullOrEmpty(sRecordCopyingUrl))
{
throw new ApplicationException("RecordCopying WebApi URL must be provided via the RecordCopying_WebApi_URL environment variable.");
}

builder.Services.AddHttpClient<IBankHolidayAPI, BankHolidayAPI>(c =>
{
c.BaseAddress = new Uri(sRecordCopyingUrl);
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.Host = Environment.GetEnvironmentVariable("RecordCopying_Header");
});
builder.Services.AddScoped<IWorkingDayService, WorkingDayService>();
builder.Services.AddScoped<IAvailabilityService, AvailabilityService>();
builder.Services.AddScoped<IBookingService, BookingService>();
Expand Down
4 changes: 0 additions & 4 deletions book-a-reading-room-visit.api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"applicationUrl": "https://localhost:7140;http://localhost:5148",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"RecordCopying_WebApi_URL": "http://localhost:82/RecordCopyingServiceAPI/",
"RecordCopying_Header": "services.nationalarchives.web.local",
"KewBookingConnection": "Data Source= (localdb)\\MSSQLLocalDB; Initial Catalog=KewBooking",
"HomeURL": "https://dev-www.nationalarchives.gov.uk/book-a-reading-room-visit",
"AWS_PROFILE": "dev",
Expand All @@ -33,8 +31,6 @@
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"RecordCopying_WebApi_URL": "http://localhost:82/RecordCopyingServiceAPI/",
"RecordCopying_Header": "services.nationalarchives.web.local",
"KewBookingConnection": "Data Source= (localdb)\\MSSQLLocalDB; Initial Catalog=KewBooking",
"HomeURL": "https://dev-www.nationalarchives.gov.uk/book-a-reading-room-visit",
"AWS_PROFILE": "dev",
Expand Down
39 changes: 0 additions & 39 deletions book-a-reading-room-visit.api/Service/Impl/BankHolidayAPI.cs

This file was deleted.

29 changes: 16 additions & 13 deletions book-a-reading-room-visit.api/Service/Impl/WorkingDayService.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using book_a_reading_room_visit.data;
using book_a_reading_room_visit.domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;

namespace book_a_reading_room_visit.api.Service
{
public class WorkingDayService : IWorkingDayService
{
private IMemoryCache _cache;
private readonly IConfiguration _configuration;
private readonly IBankHolidayAPI _bankHolidayAPI;
private readonly BookingContext _context;
private readonly DayOfWeek[] WorkingWeekDays = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday };
private readonly DayOfWeek[] OneDayOrderOpeningWeekDays = new DayOfWeek[] { DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday };
private readonly DayOfWeek[] TwoDayOrderOpeningWeekDays = new DayOfWeek[] { DayOfWeek.Tuesday, DayOfWeek.Thursday, };

public WorkingDayService(IConfiguration configuration, IBankHolidayAPI bankHolidayAPI, IMemoryCache memoryCache)
public WorkingDayService(IConfiguration configuration, BookingContext context, IMemoryCache memoryCache)
{
_configuration = configuration;
_bankHolidayAPI = bankHolidayAPI;
_context = context;
_cache = memoryCache;
}
public async Task<List<DateTime>> GetOneDayOrderAvailableDatesAsync()
Expand Down Expand Up @@ -69,7 +67,9 @@ public async Task<List<DateTime>> GetTwoDayOrderAvailableDatesAsync()

public async Task<DateTime> GetNextWorkingDayAsync(DateTime dateTime, int daysToAdd)
{
var holidays = await _bankHolidayAPI.GetBankHolidaysAsync();
var holidays = await (from holiday in _context.Set<TNAHoliday>()
select holiday.date_closed).ToListAsync();

var dateToReturn = dateTime;
while (daysToAdd > 0)
{
Expand All @@ -82,7 +82,8 @@ public async Task<DateTime> GetNextWorkingDayAsync(DateTime dateTime, int daysTo

public async Task<DateTime> GetNextOneDayOrderOpeningDayAsync(DateTime dateTime, int daysToAdd)
{
var holidays = await _bankHolidayAPI.GetBankHolidaysAsync();
var holidays = await (from holiday in _context.Set<TNAHoliday>()
select holiday.date_closed).ToListAsync();
var dateToReturn = dateTime;
while (daysToAdd > 0)
{
Expand All @@ -95,7 +96,8 @@ public async Task<DateTime> GetNextOneDayOrderOpeningDayAsync(DateTime dateTime,

public async Task<DateTime> GetNextTwoDayOrderOpeningDayAsync(DateTime dateTime, int daysToAdd)
{
var holidays = await _bankHolidayAPI.GetBankHolidaysAsync();
var holidays = await (from holiday in _context.Set<TNAHoliday>()
select holiday.date_closed).ToListAsync();
var dateToReturn = dateTime;
while (daysToAdd > 0)
{
Expand All @@ -109,7 +111,8 @@ public async Task<DateTime> GetNextTwoDayOrderOpeningDayAsync(DateTime dateTime,
public async Task<DateTime> GetCompleteByDateAsync(DateTime dateTime)
{
int daysToDeduct = int.Parse(_configuration.GetSection("BookingTimeLine:DocumentsPreparationDays").Value);
var holidays = await _bankHolidayAPI.GetBankHolidaysAsync();
var holidays = await (from holiday in _context.Set<TNAHoliday>()
select holiday.date_closed).ToListAsync();
var dateToReturn = dateTime;
while (daysToDeduct > 0)
{
Expand Down
12 changes: 0 additions & 12 deletions book-a-reading-room-visit.api/Service/Interface/IBankHolidayAPI.cs

This file was deleted.

3 changes: 3 additions & 0 deletions book-a-reading-room-visit.data/BookingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public BookingContext(DbContextOptions<BookingContext> options)
public DbSet<Seat> Seats { get; set; }
public DbSet<BookingStatus> BookingStatus { get; set; }
public DbSet<OrderDocument> OrderDocuments { get; set; }
public DbSet<TNAHoliday> TNAHoliday { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -43,6 +44,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<OrderDocument>().Property(e => e.PieceReference).HasMaxLength(40);
modelBuilder.Entity<OrderDocument>().Property(e => e.ItemReference).HasMaxLength(40);
modelBuilder.Entity<OrderDocument>().Property(e => e.Site).HasMaxLength(20);

modelBuilder.Entity<TNAHoliday>().ToView(nameof(TNAHoliday)).HasNoKey();
}
}
}
10 changes: 10 additions & 0 deletions book-a-reading-room-visit.domain/TNAHoliday.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace book_a_reading_room_visit.domain
{
public class TNAHoliday
{
public DateTime date_closed { get; set; }
public string description { get; set; }
}
}
9 changes: 0 additions & 9 deletions book-a-reading-room-visit.model/BankHoliday.cs

This file was deleted.

0 comments on commit 2d238a1

Please sign in to comment.