generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DTOSS 5431 create get participant screening profile functions (#55
) * feat: adding two new functions for getting profile data * feat: minor improvements * feat: logging improvements * feat: some corrections and starting unit tests * feat: adding unit tests for GetParticipantScreeningProfileData * feat: testing and minor improvements * feat: adding new funcs to the compose files * fix: formatting issues * fix: fixing small unit test issue * fix: fixing small unit test issue * fix: fixing small unit test issue * fix: fixing small unit test issue * feat: adding datetime format provider * feat: changing to use host.RunAsync() * feat: changing to use host.RunAsync() * fix: unit testing issue * fix: fixing unit test issue * feat: updating tables and related code * fix: fixing type mismatch * feat: correcting db context * feat: updating objects according to new data model * feat: changing mapping function * fix: build issue * fix: changing logs to SonarCloud is happy * feat: changing to find * fix: changing localhost to 127.0.0.1 * fix: changing localhost to function name * fix: fixing mac compose file * fix: fixing syntax issue
- Loading branch information
1 parent
ca2426c
commit a4b3128
Showing
40 changed files
with
1,054 additions
and
231 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
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
15 changes: 15 additions & 0 deletions
15
src/BIAnalyticsDataService/GetParticipantScreeningProfileData/Dockerfile
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,15 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS installer-env | ||
|
||
COPY ./BIAnalyticsDataService/GetParticipantScreeningProfileData /src/dotnet-function-app | ||
COPY ./Shared /Shared | ||
RUN cd /src/dotnet-function-app && \ | ||
mkdir -p /home/site/wwwroot && \ | ||
dotnet publish *.csproj --output /home/site/wwwroot | ||
|
||
# To enable ssh & remote debugging on app service change the base image to the one below | ||
# FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0-appservice | ||
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 | ||
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ | ||
AzureFunctionsJobHost__Logging__Console__IsEnabled=true | ||
|
||
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"] |
57 changes: 57 additions & 0 deletions
57
...yticsDataService/GetParticipantScreeningProfileData/GetParticipantScreeningProfileData.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,57 @@ | ||
using System.Net; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Globalization; | ||
using NHS.ServiceInsights.Data; | ||
using NHS.ServiceInsights.Model; | ||
|
||
namespace NHS.ServiceInsights.BIAnalyticsDataService; | ||
|
||
public class GetParticipantScreeningProfileData | ||
{ | ||
private readonly ILogger<GetParticipantScreeningProfileData> _logger; | ||
|
||
private readonly IParticipantScreeningProfileRepository _participantScreeningProfileRepository; | ||
|
||
public GetParticipantScreeningProfileData(ILogger<GetParticipantScreeningProfileData> logger, IParticipantScreeningProfileRepository participantScreeningProfileRepository) | ||
{ | ||
_logger = logger; | ||
_participantScreeningProfileRepository = participantScreeningProfileRepository; | ||
} | ||
|
||
[Function("GetParticipantScreeningProfileData")] | ||
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) | ||
{ | ||
int page = int.Parse(req.Query["page"]); | ||
int pageSize = int.Parse(req.Query["pageSize"]); | ||
DateTime startDate = DateTime.Parse(req.Query["startDate"], CultureInfo.InvariantCulture); | ||
DateTime endDate = DateTime.Parse(req.Query["endDate"], CultureInfo.InvariantCulture); | ||
|
||
var numberOfRowsToSkip = (page - 1) * pageSize; | ||
|
||
try | ||
{ | ||
ProfilesDataPage result = await _participantScreeningProfileRepository.GetParticipantProfile(page, pageSize, startDate, endDate, numberOfRowsToSkip); | ||
if (result.Profiles.Count == 0) | ||
{ | ||
_logger.LogInformation("GetParticipantScreeningProfileData: Could not find any participant profiles."); | ||
return req.CreateResponse(HttpStatusCode.NotFound); | ||
} | ||
|
||
_logger.LogInformation("GetParticipantScreeningProfileData: Participant profiles found successfully."); | ||
|
||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
response.Headers.Add("Content-Type", "application/json"); | ||
await JsonSerializer.SerializeAsync(response.Body, result); | ||
return response; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, "GetParticipantScreeningProfileData: Failed to get participant profiles from the database.\nException: {Message}", ex.Message); | ||
return req.CreateResponse(HttpStatusCode.InternalServerError); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...sDataService/GetParticipantScreeningProfileData/GetParticipantScreeningProfileData.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | ||
<OutputType>Exe</OutputType> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\Shared\Model\Model.csproj" /> | ||
<ProjectReference Include="..\..\Shared\Data\Data.csproj" /> | ||
</ItemGroup> | ||
</Project> |
15 changes: 15 additions & 0 deletions
15
src/BIAnalyticsDataService/GetParticipantScreeningProfileData/Program.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,15 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using NHS.ServiceInsights.Data; | ||
|
||
var host = new HostBuilder() | ||
.ConfigureFunctionsWorkerDefaults() | ||
.ConfigureServices(services => | ||
{ | ||
services.AddScoped<IParticipantScreeningProfileRepository, ParticipantScreeningProfileRepository>(); | ||
services.AddDbContext<ServiceInsightsDbContext>( | ||
options => options.UseSqlServer(Environment.GetEnvironmentVariable("ServiceInsightsDbConnectionString"))); | ||
}) | ||
.Build(); | ||
await host.RunAsync(); |
9 changes: 9 additions & 0 deletions
9
src/BIAnalyticsDataService/GetParticipantScreeningProfileData/Properties/launchSettings.json
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,9 @@ | ||
{ | ||
"profiles": { | ||
"GetEpisode": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--port 7208", | ||
"launchBrowser": false | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/BIAnalyticsDataService/GetParticipantScreeningProfileData/host.json
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,12 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true, | ||
"excludedTypes": "Request" | ||
}, | ||
"enableLiveMetricsFilters": true | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/BIAnalyticsDataService/GetParticipantScreeningProfileData/local.settings.json.template
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,11 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "UseDevelopmentStorage=true", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", | ||
"ServiceInsightsDbConnectionString": "YOUR_CONNECTION_STRING" | ||
}, | ||
"Host": { | ||
"LocalHttpPort": 6062 | ||
} | ||
} |
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.