Skip to content

Commit

Permalink
feat: Add api project
Browse files Browse the repository at this point in the history
Add api project that encapsulate the library in a minimal api.
  • Loading branch information
LuukvH committed Jan 5, 2024
1 parent 2ea005a commit 909381f
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BKRCalculator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BKRCalculator", "BKRCalcula
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BKRCalculatorTest", "BKRCalculatorTest\BKRCalculatorTest.csproj", "{1C9D03F8-2CFD-4AF9-812A-9EBD7C497F76}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BKRCalculatorApi", "BKRCalculatorApi\BKRCalculatorApi.csproj", "{4F0B5B4E-E8C6-4B40-9AA2-E38C46747947}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +26,9 @@ Global
{1C9D03F8-2CFD-4AF9-812A-9EBD7C497F76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C9D03F8-2CFD-4AF9-812A-9EBD7C497F76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C9D03F8-2CFD-4AF9-812A-9EBD7C497F76}.Release|Any CPU.Build.0 = Release|Any CPU
{4F0B5B4E-E8C6-4B40-9AA2-E38C46747947}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F0B5B4E-E8C6-4B40-9AA2-E38C46747947}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F0B5B4E-E8C6-4B40-9AA2-E38C46747947}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F0B5B4E-E8C6-4B40-9AA2-E38C46747947}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions BKRCalculatorApi/BKRCalculatorApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BKRCalculator\BKRCalculator.csproj" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions BKRCalculatorApi/Controllers/GroupAnalysisController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using KDVManager.BKRCalculator;
using Microsoft.AspNetCore.Mvc;

namespace BKRCalculatorApi.Controllers;

[ApiController]
[Route("[controller]")]
public class GroupAnalysisController : ControllerBase
{
private readonly ILogger<GroupAnalysisController> _logger;

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

[HttpPost(Name = "CalculateBKR")]
public ActionResult<GroupAnalysisResult> CalculateBKR([FromBody] AgeGroupCounts counts)
{
GroupAnalyzer groupAnalyzer = new GroupAnalyzer();

try
{
var result = groupAnalyzer.CalculateBKR(counts);
return Ok(result);
}
catch (Exception ex)
{
return BadRequest(new { message = ex.Message });
}
}
}
21 changes: 21 additions & 0 deletions BKRCalculatorApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions BKRCalculatorApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63372",
"sslPort": 44306
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5083",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7257;http://localhost:5083",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions BKRCalculatorApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions BKRCalculatorApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit 909381f

Please sign in to comment.