Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools.
- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first.
- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public interface IJsonFile<T> where T : class
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SAPSec.Infrastructure.Json
namespace SAPSec.Data.Json
{
public interface ISimilarSchoolsGroupsRow : ISimilarSchoolsRow
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SAPSec.Infrastructure.Json
namespace SAPSec.Data.Json
{
public interface ISimilarSchoolsRow
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using SAPSec.Core.Features.Attendance;
using SAPSec.Core.Interfaces.Repositories;
using SAPSec.Core.Model.Generated;
using SAPSec.Data.Dto;
using SAPSec.Data.Store;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonAbsenceRepository(
IEstablishmentRepository establishmentRepository,
IJsonFile<EstablishmentAbsence> establishmentAbsenceRepository,
IJsonFile<LAAbsence> laAbsenceRepository,
IJsonFile<EnglandAbsence> englandAbsenceRepository) : IAbsenceRepository
public class JsonAbsenceStore(
IEstablishmentStore establishmentStore,
IJsonFile<EstablishmentAbsence> establishmentAbsenceJsonFile,
IJsonFile<LAAbsence> laAbsenceJsonFile,
IJsonFile<EnglandAbsence> englandAbsenceJsonFile) : IAbsenceStore
{
public async Task<AbsenceData?> GetByUrnAsync(string urn)
{
Expand All @@ -28,10 +27,10 @@ public async Task<IReadOnlyCollection<AbsenceData>> GetByUrnsAsync(IEnumerable<s
return [];
}

var establishments = (await establishmentRepository.GetEstablishmentsAsync(requestedUrns))
var establishments = (await establishmentStore.GetEstablishmentsAsync(requestedUrns))
.Where(x => !string.IsNullOrWhiteSpace(x.URN))
.ToDictionary(x => x.URN, StringComparer.Ordinal);
var absenceByUrn = (await establishmentAbsenceRepository.ReadAllAsync())
var absenceByUrn = (await establishmentAbsenceJsonFile.ReadAllAsync())
.Where(x => establishments.ContainsKey(x.Id))
.ToDictionary(x => x.Id, StringComparer.Ordinal);

Expand All @@ -40,11 +39,11 @@ public async Task<IReadOnlyCollection<AbsenceData>> GetByUrnsAsync(IEnumerable<s
.Where(x => !string.IsNullOrWhiteSpace(x))
.Distinct(StringComparer.Ordinal)
.ToArray();
var localAuthorityAbsenceByLaId = (await laAbsenceRepository.ReadAllAsync())
var localAuthorityAbsenceByLaId = (await laAbsenceJsonFile.ReadAllAsync())
.Where(x => laIds.Contains(x.Id, StringComparer.Ordinal))
.ToDictionary(x => x.Id, StringComparer.Ordinal);

var englandAbsence = (await englandAbsenceRepository.ReadAllAsync()).FirstOrDefault();
var englandAbsence = (await englandAbsenceJsonFile.ReadAllAsync()).FirstOrDefault();

var results = new List<AbsenceData>(requestedUrns.Length);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Microsoft.Extensions.Logging;
using SAPSec.Core.Interfaces.Repositories;
using SAPSec.Core.Model.Generated;
using SAPSec.Data.Dto;
using SAPSec.Data.Store;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonEstablishmentEmailRepository : IEstablishmentEmailRepository
public class JsonEstablishmentEmailStore : IEstablishmentEmailStore
{
private readonly IJsonFile<EstablishmentEmail> _establishmentEmailJsonFile;

private ILogger<JsonEstablishmentEmailRepository> _logger;
private ILogger<JsonEstablishmentEmailStore> _logger;

public JsonEstablishmentEmailRepository(
public JsonEstablishmentEmailStore(
IJsonFile<EstablishmentEmail> establishmentEmailJsonFile,
ILogger<JsonEstablishmentEmailRepository> logger)
ILogger<JsonEstablishmentEmailStore> logger)
{
_establishmentEmailJsonFile = establishmentEmailJsonFile;
_logger = logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using Microsoft.Extensions.Logging;
using SAPSec.Core.Interfaces.Repositories;
using SAPSec.Core.Model.Generated;
using SAPSec.Data.Dto;
using SAPSec.Data.Store;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonEstablishmentRepository : IEstablishmentRepository
public class JsonEstablishmentStore : IEstablishmentStore
{
private readonly IJsonFile<Establishment> _establishmentJsonFile;
private readonly IJsonFile<EstablishmentEmail> _establishmentEmailJsonFile;

private ILogger<JsonEstablishmentRepository> _logger;
private ILogger<JsonEstablishmentStore> _logger;

public JsonEstablishmentRepository(
public JsonEstablishmentStore(
IJsonFile<Establishment> establishmentJsonFile,
IJsonFile<EstablishmentEmail> establishmentEmailJsonFile,
ILogger<JsonEstablishmentRepository> logger)
ILogger<JsonEstablishmentStore> logger)
{
_establishmentJsonFile = establishmentJsonFile;
_establishmentEmailJsonFile = establishmentEmailJsonFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonFile<T> : IJsonFile<T> where T : class
{
Expand All @@ -13,7 +13,7 @@ public JsonFile(ILogger<JsonFile<T>> logger)
{
_logger = logger ?? throw new ArgumentNullException();
var basePath = AppContext.BaseDirectory;
_filePath = Path.Combine(basePath, "Data", "Files", "Generated");
_filePath = Path.Combine(basePath, "Files", "Generated");
_cache = new Lazy<List<T>>(
LoadCache,
LazyThreadSafetyMode.ExecutionAndPublication);
Expand All @@ -26,37 +26,22 @@ public Task<IEnumerable<T>> ReadAllAsync()

private string ReadFile(string fileName)
{
try
{
var fullPath = Path.Combine(_filePath, $"{fileName}.json");
var fullPath = Path.Combine(_filePath, $"{fileName}.json");

return File.ReadAllText(fullPath);
}
catch (Exception ex)
{
_logger.LogError($"Failed to Read file {fileName}! - {ex.Message}, {ex}");
return string.Empty;
}
return File.ReadAllText(fullPath);
}

private List<T> LoadCache()
{
_logger.LogInformation("Loading lookup cache...");
var stopwatch = System.Diagnostics.Stopwatch.StartNew();

try
var fileData = ReadFile(typeof(T).Name);
if (string.IsNullOrWhiteSpace(fileData))
{
var fileData = ReadFile(typeof(T).Name);
if (!string.IsNullOrWhiteSpace(fileData))
{
return JsonConvert.DeserializeObject<List<T>>(fileData) ?? [];
}
}
catch (Exception ex)
{
_logger.LogError($"Failed to execute generic readall for {typeof(T).Name}! - {ex.Message}, {ex}");
}

return [];
return [];
}

return JsonConvert.DeserializeObject<List<T>>(fileData) ?? [];
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using SAPSec.Core.Features.Ks4HeadlineMeasures;
using SAPSec.Core.Interfaces.Repositories;
using SAPSec.Core.Model.Generated;
using SAPSec.Data.Dto;
using SAPSec.Data.Store;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonKs4DestinationsRepository(
IEstablishmentRepository establishmentRepository,
IJsonFile<EstablishmentDestinations> establishmentDestinationsRepository,
IJsonFile<LADestinations> localAuthorityDestinationsRepository,
IJsonFile<EnglandDestinations> englandDestinationsRepository) : IKs4DestinationsRepository
public class JsonKs4DestinationsStore(
IEstablishmentStore establishmentStore,
IJsonFile<EstablishmentDestinations> establishmentDestinationsJsonFile,
IJsonFile<LADestinations> localAuthorityDestinationsJsonFile,
IJsonFile<EnglandDestinations> englandDestinationsJsonFile) : IKs4DestinationsStore
{
public async Task<Ks4DestinationsData?> GetByUrnAsync(string urn)
{
Expand All @@ -28,10 +27,10 @@ public async Task<IReadOnlyCollection<Ks4DestinationsData>> GetByUrnsAsync(IEnum
return [];
}

var establishments = (await establishmentRepository.GetEstablishmentsAsync(requestedUrns))
var establishments = (await establishmentStore.GetEstablishmentsAsync(requestedUrns))
.Where(x => !string.IsNullOrWhiteSpace(x.URN))
.ToDictionary(x => x.URN, StringComparer.Ordinal);
var destinationsByUrn = (await establishmentDestinationsRepository.ReadAllAsync())
var destinationsByUrn = (await establishmentDestinationsJsonFile.ReadAllAsync())
.Where(x => establishments.ContainsKey(x.Id))
.ToDictionary(x => x.Id, StringComparer.Ordinal);

Expand All @@ -40,11 +39,11 @@ public async Task<IReadOnlyCollection<Ks4DestinationsData>> GetByUrnsAsync(IEnum
.Where(x => !string.IsNullOrWhiteSpace(x))
.Distinct(StringComparer.Ordinal)
.ToArray();
var localAuthorityDestinationsByLaId = (await localAuthorityDestinationsRepository.ReadAllAsync())
var localAuthorityDestinationsByLaId = (await localAuthorityDestinationsJsonFile.ReadAllAsync())
.Where(x => laIds.Contains(x.Id, StringComparer.Ordinal))
.ToDictionary(x => x.Id, StringComparer.Ordinal);

var englandDestinations = (await englandDestinationsRepository.ReadAllAsync()).FirstOrDefault();
var englandDestinations = (await englandDestinationsJsonFile.ReadAllAsync()).FirstOrDefault();

var results = new List<Ks4DestinationsData>(requestedUrns.Length);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using SAPSec.Core.Features.Ks4HeadlineMeasures;
using SAPSec.Core.Interfaces.Repositories;
using SAPSec.Core.Model.Generated;
using SAPSec.Data.Dto;
using SAPSec.Data.Store;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonKs4PerformanceRepository(
IEstablishmentRepository establishmentRepository,
IJsonFile<EstablishmentPerformance> establishmentPerformanceRepository,
IJsonFile<LAPerformance> localAuthorityPerformanceRepository,
IJsonFile<EnglandPerformance> englandPerformanceRepository) : IKs4PerformanceRepository
public class JsonKs4PerformanceStore(
IEstablishmentStore establishmentStore,
IJsonFile<EstablishmentPerformance> establishmentPerformanceJsonFile,
IJsonFile<LAPerformance> localAuthorityPerformanceJsonFile,
IJsonFile<EnglandPerformance> englandPerformanceJsonFile) : IKs4PerformanceStore
{
public async Task<Ks4PerformanceData?> GetByUrnAsync(string urn)
{
Expand All @@ -28,10 +27,10 @@ public async Task<IReadOnlyCollection<Ks4PerformanceData>> GetByUrnsAsync(IEnume
return [];
}

var establishments = (await establishmentRepository.GetEstablishmentsAsync(requestedUrns))
var establishments = (await establishmentStore.GetEstablishmentsAsync(requestedUrns))
.Where(x => !string.IsNullOrWhiteSpace(x.URN))
.ToDictionary(x => x.URN, StringComparer.Ordinal);
var performanceByUrn = (await establishmentPerformanceRepository.ReadAllAsync())
var performanceByUrn = (await establishmentPerformanceJsonFile.ReadAllAsync())
.Where(x => establishments.ContainsKey(x.Id))
.ToDictionary(x => x.Id, StringComparer.Ordinal);

Expand All @@ -40,11 +39,11 @@ public async Task<IReadOnlyCollection<Ks4PerformanceData>> GetByUrnsAsync(IEnume
.Where(x => !string.IsNullOrWhiteSpace(x))
.Distinct(StringComparer.Ordinal)
.ToArray();
var localAuthorityPerformanceByLaId = (await localAuthorityPerformanceRepository.ReadAllAsync())
var localAuthorityPerformanceByLaId = (await localAuthorityPerformanceJsonFile.ReadAllAsync())
.Where(x => laIds.Contains(x.Id, StringComparer.Ordinal))
.ToDictionary(x => x.Id, StringComparer.Ordinal);

var englandPerformance = (await englandPerformanceRepository.ReadAllAsync()).FirstOrDefault();
var englandPerformance = (await englandPerformanceJsonFile.ReadAllAsync()).FirstOrDefault();

var results = new List<Ks4PerformanceData>(requestedUrns.Length);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using SAPSec.Core.Features.SimilarSchools;
using SAPSec.Core.Model.Generated;
using SAPSec.Data.Dto;
using SAPSec.Data.Store;

namespace SAPSec.Infrastructure.Json;
namespace SAPSec.Data.Json;

public class JsonSimilarSchoolsSecondaryRepository : ISimilarSchoolsSecondaryRepository
public class JsonSimilarSchoolsSecondaryStore : ISimilarSchoolsSecondaryStore
{
private readonly IJsonFile<SimilarSchoolsSecondaryGroupsEntry> _similarSchoolsGroups;
private readonly IJsonFile<SimilarSchoolsSecondaryValuesEntry> _similarSchoolsValues;
private readonly IJsonFile<SimilarSchoolsSecondaryStandardDeviationsEntry> _standardDeviations;

public JsonSimilarSchoolsSecondaryRepository(
IJsonFile<SimilarSchoolsSecondaryGroupsEntry> similarSchoolsGroupsRepository,
IJsonFile<SimilarSchoolsSecondaryValuesEntry> similarSchoolsValuesRepository,
IJsonFile<SimilarSchoolsSecondaryStandardDeviationsEntry> standardDeviationsRepository)
public JsonSimilarSchoolsSecondaryStore(
IJsonFile<SimilarSchoolsSecondaryGroupsEntry> similarSchoolsGroupsJsonFile,
IJsonFile<SimilarSchoolsSecondaryValuesEntry> similarSchoolsValuesJsonFile,
IJsonFile<SimilarSchoolsSecondaryStandardDeviationsEntry> standardDeviationsJsonFile)
{
_similarSchoolsGroups = similarSchoolsGroupsRepository;
_similarSchoolsValues = similarSchoolsValuesRepository;
_standardDeviations = standardDeviationsRepository;
_similarSchoolsGroups = similarSchoolsGroupsJsonFile;
_similarSchoolsValues = similarSchoolsValuesJsonFile;
_standardDeviations = standardDeviationsJsonFile;
}

public async Task<IReadOnlyCollection<SimilarSchoolsSecondaryGroupsEntry>> GetSimilarSchoolsGroupAsync(string urn)
Expand Down
Loading