diff --git a/BKRCalculator.sln b/BKRCalculator.sln index ce2b1ea..c266785 100644 --- a/BKRCalculator.sln +++ b/BKRCalculator.sln @@ -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 @@ -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 diff --git a/BKRCalculatorApi/BKRCalculatorApi.csproj b/BKRCalculatorApi/BKRCalculatorApi.csproj new file mode 100644 index 0000000..0d83392 --- /dev/null +++ b/BKRCalculatorApi/BKRCalculatorApi.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + diff --git a/BKRCalculatorApi/Controllers/GroupAnalysisController.cs b/BKRCalculatorApi/Controllers/GroupAnalysisController.cs new file mode 100644 index 0000000..434ebb5 --- /dev/null +++ b/BKRCalculatorApi/Controllers/GroupAnalysisController.cs @@ -0,0 +1,32 @@ +using KDVManager.BKRCalculator; +using Microsoft.AspNetCore.Mvc; + +namespace BKRCalculatorApi.Controllers; + +[ApiController] +[Route("[controller]")] +public class GroupAnalysisController : ControllerBase +{ + private readonly ILogger _logger; + + public GroupAnalysisController(ILogger logger) + { + _logger = logger; + } + + [HttpPost(Name = "CalculateBKR")] + public ActionResult 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 }); + } + } +} diff --git a/BKRCalculatorApi/Program.cs b/BKRCalculatorApi/Program.cs new file mode 100644 index 0000000..919f5f7 --- /dev/null +++ b/BKRCalculatorApi/Program.cs @@ -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(); diff --git a/BKRCalculatorApi/Properties/launchSettings.json b/BKRCalculatorApi/Properties/launchSettings.json new file mode 100644 index 0000000..150a147 --- /dev/null +++ b/BKRCalculatorApi/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/BKRCalculatorApi/appsettings.Development.json b/BKRCalculatorApi/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/BKRCalculatorApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BKRCalculatorApi/appsettings.json b/BKRCalculatorApi/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/BKRCalculatorApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}