-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: #869: Add new debug endpoint for Atlas donor store to test don…
…or import.
- Loading branch information
Showing
6 changed files
with
51,158 additions
and
56,999 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Atlas.Common.Debugging.Donors | ||
{ | ||
public static class DebugDonorsHelper | ||
{ | ||
public static DebugDonorsResult<TDonor, TDonorId> BuildDebugDonorsResult<TDonor, TDonorId>( | ||
IReadOnlyCollection<TDonorId> allDonorIds, | ||
IReadOnlyCollection<TDonor> presentDonors, | ||
Func<TDonor, TDonorId> idSelector) | ||
{ | ||
var absentDonorIds = allDonorIds.Except(presentDonors.Select(idSelector)).ToList(); | ||
|
||
return new DebugDonorsResult<TDonor, TDonorId> | ||
{ | ||
DonorCounts = new DebugDonorsResult<TDonor, TDonorId>.Counts | ||
{ | ||
Absent = absentDonorIds.Count, | ||
Present = presentDonors.Count, | ||
Received = allDonorIds.Count | ||
}, | ||
AbsentDonorIds = absentDonorIds, | ||
PresentDonors = presentDonors, | ||
ReceivedDonorIds = allDonorIds | ||
}; | ||
} | ||
} | ||
} |
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,42 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Atlas.Common.Debugging.Donors | ||
{ | ||
public class DebugDonorsResult<TDonor, TDonorId> | ||
{ | ||
public Counts DonorCounts { get; set; } | ||
|
||
/// <summary> | ||
/// Ids of donors that were NOT found in the donor store | ||
/// </summary> | ||
public IEnumerable<TDonorId> AbsentDonorIds { get; set; } | ||
|
||
/// <summary> | ||
/// Info of donors that were found in the donor store | ||
/// </summary> | ||
public IEnumerable<TDonor> PresentDonors { get; set; } | ||
|
||
/// <summary> | ||
/// List of all ids provided in the debug request | ||
/// </summary> | ||
public IEnumerable<TDonorId> ReceivedDonorIds { get; set; } | ||
|
||
public class Counts | ||
{ | ||
/// <summary> | ||
/// Count of donors NOT found in the donor store | ||
/// </summary> | ||
public int Absent { get; set; } | ||
|
||
/// <summary> | ||
/// Count of donors that were found in the donor store | ||
/// </summary> | ||
public int Present { get; set; } | ||
|
||
/// <summary> | ||
/// Count of all donor Ids provided in the debug request | ||
/// </summary> | ||
public int Received { get; set; } | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Atlas.DonorImport.Functions/Functions/Debug/DonorFunctions.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,42 @@ | ||
using Atlas.Common.Debugging.Donors; | ||
using Atlas.Common.Utils.Http; | ||
using Atlas.DonorImport.ExternalInterface; | ||
using Atlas.DonorImport.ExternalInterface.Models; | ||
using AzureFunctions.Extensions.Swashbuckle.Attribute; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Newtonsoft.Json; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
namespace Atlas.DonorImport.Functions.Functions.Debug | ||
{ | ||
public class DonorFunctions | ||
{ | ||
private readonly IDonorReader donorReader; | ||
|
||
public DonorFunctions(IDonorReader donorReader) | ||
{ | ||
this.donorReader = donorReader; | ||
} | ||
|
||
[FunctionName(nameof(GetDonors))] | ||
[ProducesResponseType(typeof(DebugDonorsResult<Donor, string>), (int)HttpStatusCode.OK)] | ||
public async Task<IActionResult> GetDonors( | ||
[HttpTrigger(AuthorizationLevel.Function, "post", Route = $"{RouteConstants.DebugRoutePrefix}/donors")] | ||
[RequestBodyType(typeof(string[]), "Donor Record Ids")] | ||
HttpRequest request) | ||
{ | ||
var recordIds = JsonConvert.DeserializeObject<string[]>(await new StreamReader(request.Body).ReadToEndAsync()); | ||
|
||
var donors = await donorReader.GetDonorsByExternalDonorCodes(recordIds); | ||
|
||
return new JsonResult( | ||
DebugDonorsHelper.BuildDebugDonorsResult(recordIds, donors.Values.ToList(), d => d.ExternalDonorCode)); | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
Atlas.MatchingAlgorithm.Functions/Functions/Debug/DonorFunctions.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,44 @@ | ||
using Atlas.Common.Utils.Http; | ||
using Atlas.MatchingAlgorithm.Data.Models.DonorInfo; | ||
using Atlas.MatchingAlgorithm.Data.Repositories.DonorRetrieval; | ||
using Atlas.MatchingAlgorithm.Services.ConfigurationProviders.TransientSqlDatabase.RepositoryFactories; | ||
using AzureFunctions.Extensions.Swashbuckle.Attribute; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
using Atlas.Common.Debugging.Donors; | ||
|
||
namespace Atlas.MatchingAlgorithm.Functions.Functions.Debug | ||
{ | ||
public class DonorFunctions | ||
{ | ||
private readonly IDonorInspectionRepository inspectionRepository; | ||
|
||
public DonorFunctions(IActiveRepositoryFactory activeRepositoryFactory) | ||
{ | ||
inspectionRepository = activeRepositoryFactory.GetDonorInspectionRepository(); | ||
} | ||
|
||
[FunctionName(nameof(GetDonorsFromActiveDb))] | ||
[ProducesResponseType(typeof(IEnumerable<DebugDonorsResult<DonorInfo, int>>), (int)HttpStatusCode.OK)] | ||
public async Task<IActionResult> GetDonorsFromActiveDb( | ||
[HttpTrigger(AuthorizationLevel.Function, "post", Route = $"{RouteConstants.DebugRoutePrefix}/donors/active")] | ||
[RequestBodyType(typeof(int[]), "Atlas Donor Ids")] | ||
HttpRequest request) | ||
{ | ||
var donorIds = JsonConvert.DeserializeObject<int[]>(await new StreamReader(request.Body).ReadToEndAsync()); | ||
|
||
var donors = await inspectionRepository.GetDonors(donorIds); | ||
|
||
return new JsonResult( | ||
DebugDonorsHelper.BuildDebugDonorsResult(donorIds, donors.Values.ToList(), d => d.DonorId)); | ||
} | ||
} | ||
} |
Oops, something went wrong.