Skip to content

Commit

Permalink
feat: Created UpdateParticipant function (#3)
Browse files Browse the repository at this point in the history
* feat: Created UpdateParticipant function

* refactor: Moved Participant class to separate file
  • Loading branch information
OswellHita authored Jul 25, 2024
1 parent 43be19e commit 4112479
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
!project.code-workspace

# Please, add your custom content below!


# Builds
bin
obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Participant
{
public string NhsNumber { get; set; }
}
11 changes: 11 additions & 0 deletions src/ParticipantManagementService/UpdateParticipant/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{

})
.Build();
host.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
"updateParticipant": {
"commandName": "Project",
"commandLineArgs": "--port 7253",
"launchBrowser": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace updateParticipant;

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;


public class UpdateParticipant
{
private readonly ILogger<UpdateParticipant> _logger;

public UpdateParticipant(ILogger<UpdateParticipant> logger)
{
_logger = logger;
}

[Function("updateParticipant")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
Participant participant;
try
{
using (StreamReader reader = new StreamReader(req.Body, Encoding.UTF8))
{
var postData = reader.ReadToEnd();
participant = JsonSerializer.Deserialize<Participant>(postData);
}

_logger.LogInformation(participant.NhsNumber);

return req.CreateResponse(HttpStatusCode.OK);

}
catch
{
_logger.LogError("Could not read participant");

return req.CreateResponse(HttpStatusCode.BadRequest);
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<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>
</Project>
12 changes: 12 additions & 0 deletions src/ParticipantManagementService/UpdateParticipant/host.json
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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"Host": {
"LocalHttpPort": 6000
}
}

0 comments on commit 4112479

Please sign in to comment.