Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.vs
/Powerplants.Api/bin
/Powerplants.Api/obj
/Powerplants.BusinessLogic/bin
/Powerplants.BusinessLogic/obj
/Powerplants.UnitTests/bin
/Powerplants.UnitTests/obj
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8888


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["./Powerplants.Api/Powerplants.Api.csproj", "Powerplants.Api/"]
COPY ["./Powerplants.BusinessLogic/Powerplants.BusinessLogic.csproj", "PowerPlant.BusinessLogic/"]
RUN dotnet restore "Powerplants.Api/Powerplants.Api.csproj"
COPY . .
WORKDIR "/src/Powerplants.Api"
RUN dotnet build "./Powerplants.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build


FROM build AS publish
RUN dotnet publish "Powerplants.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false


FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Powerplants.Api.dll", "--urls", "http://0.0.0.0:8888"]
37 changes: 37 additions & 0 deletions Powerplant.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Powerplants.Api", "Powerplants.Api\Powerplants.Api.csproj", "{F763667A-EB16-4025-B63F-D7BC8A2484FB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Powerplants.BusinessLogic", "Powerplants.BusinessLogic\Powerplants.BusinessLogic.csproj", "{C857BECE-7512-4BA1-9CDA-BAACCF969312}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerPlants.UnitTests", "Powerplants.UnitTests\PowerPlants.UnitTests.csproj", "{43532438-5E93-44E9-A5AB-0C66B0E6875B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F763667A-EB16-4025-B63F-D7BC8A2484FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F763667A-EB16-4025-B63F-D7BC8A2484FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F763667A-EB16-4025-B63F-D7BC8A2484FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F763667A-EB16-4025-B63F-D7BC8A2484FB}.Release|Any CPU.Build.0 = Release|Any CPU
{C857BECE-7512-4BA1-9CDA-BAACCF969312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C857BECE-7512-4BA1-9CDA-BAACCF969312}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C857BECE-7512-4BA1-9CDA-BAACCF969312}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C857BECE-7512-4BA1-9CDA-BAACCF969312}.Release|Any CPU.Build.0 = Release|Any CPU
{43532438-5E93-44E9-A5AB-0C66B0E6875B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43532438-5E93-44E9-A5AB-0C66B0E6875B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43532438-5E93-44E9-A5AB-0C66B0E6875B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43532438-5E93-44E9-A5AB-0C66B0E6875B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AE04E8DA-1227-4549-A251-F801A2A0BEF0}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions Powerplants.Api/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using BusinessLogic.Models;
using BusinessLogic.Services.Calculation;
using Microsoft.AspNetCore.Mvc;
using System.Net;

namespace Powerplant.Controllers
{
[ApiController]
[Route("productionplan")]
public class ProductController : ControllerBase
{
private readonly ICalculationPowerPlanService _calculationService;

public ProductController(ICalculationPowerPlanService calculationService)
{
_calculationService = calculationService;
}
[HttpPost]
[ProducesResponseType(typeof(List<ProductResponse>), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public IActionResult CalculatePowerPlants([FromBody] ProductPlanInput productPlanDto)
{
List<ProductResponse> result = _calculationService.CalculatePowerPlants(productPlanDto);
return Ok(result);
}
}
}
6 changes: 6 additions & 0 deletions Powerplants.Api/Powerplant.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Powerplant_HostAddress = http://localhost:5041

GET {{Powerplant_HostAddress}}/weatherforecast/
Accept: application/json

###
20 changes: 20 additions & 0 deletions Powerplants.Api/Powerplants.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>23497340-e9d2-40a4-8e7a-77c37c456ba9</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Powerplants.BusinessLogic\Powerplants.BusinessLogic.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions Powerplants.Api/Powerplants.Api.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
31 changes: 31 additions & 0 deletions Powerplants.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

using BusinessLogic.Services.Calculation;
using System.Text.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
builder.Services.AddScoped<ICalculationPowerPlanService, CalculationPowerPlanService>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();


app.UseSwagger();
app.UseSwaggerUI();


app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions Powerplants.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"profiles": {
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:8888"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8888"
},
"publishAllPorts": true,
"useSSL": true
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56801/",
"sslPort": 8888
}
}
}
8 changes: 8 additions & 0 deletions Powerplants.Api/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 Powerplants.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
9 changes: 9 additions & 0 deletions Powerplants.BusinessLogic/Enums/TypePowerEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BusinessLogic.Enums
{
public enum TypePowerEnum
{
Gasfired,
Turbojet,
Windturbine
}
}
24 changes: 24 additions & 0 deletions Powerplants.BusinessLogic/Models/FuelInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace BusinessLogic.Models
{
public class FuelInput
{
[Required]
[JsonPropertyName("gas(euro/MWh)")]
public decimal GasEuroPerMWh { get; set; }

[Required]
[JsonPropertyName("kerosine(euro/MWh)")]
public decimal KerosineEuroPerMWh { get; set; }

[Required]
[JsonPropertyName("co2(euro/ton)")]
public decimal Co2EuroPerTon { get; set; }

[Required]
[JsonPropertyName("wind(%)")]
public decimal WindPercentage { get; set; }
}
}
23 changes: 23 additions & 0 deletions Powerplants.BusinessLogic/Models/PowerPlantInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BusinessLogic.Enums;
using System.ComponentModel.DataAnnotations;

namespace BusinessLogic.Models
{
public class PowerPlantInput
{
[Required]
public string Name { get; set; }

[Required]
public TypePowerEnum Type { get; set; }

[Required]
public decimal Efficiency { get; set; }

[Required]
public int Pmin { get; set; }

[Required]
public int Pmax { get; set; }
}
}
16 changes: 16 additions & 0 deletions Powerplants.BusinessLogic/Models/ProductPlanInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;

namespace BusinessLogic.Models
{
public class ProductPlanInput
{
[Required]
public int Load { get; set; }

[Required]
public FuelInput Fuels { get; set; }

[Required]
public List<PowerPlantInput> Powerplants { get; set; }
}
}
8 changes: 8 additions & 0 deletions Powerplants.BusinessLogic/Models/ProductResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BusinessLogic.Models
{
public class ProductResponse
{
public string Name { get; set; }
public decimal P { get; set; }
}
}
9 changes: 9 additions & 0 deletions Powerplants.BusinessLogic/Powerplants.BusinessLogic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
7 changes: 7 additions & 0 deletions Powerplants.BusinessLogic/Records/PriceMwh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BusinessLogic.Records
{
internal record PriceMwh(decimal Price, string Name)
{

}
}
Loading