From 17785848eb53f8d0420f6b6b3be00a0d10be4e1e Mon Sep 17 00:00:00 2001 From: Paweł Bernaciak Date: Sat, 14 Oct 2023 21:04:48 +0200 Subject: Create backend project --- .../Controllers/WeatherForecastController.cs | 32 +++++++++++++++++ backend/Elements.Backend/Elements.Backend.csproj | 18 ++++++++++ backend/Elements.Backend/Program.cs | 25 +++++++++++++ .../Properties/launchSettings.json | 41 ++++++++++++++++++++++ backend/Elements.Backend/WeatherForecast.cs | 12 +++++++ .../Elements.Backend/appsettings.Development.json | 8 +++++ backend/Elements.Backend/appsettings.json | 9 +++++ backend/Elements.Data/ApplicationDbContext.cs | 7 ++++ backend/Elements.Data/Elements.Data.csproj | 13 +++++++ backend/Elements.Data/Models/Element.cs | 5 +++ backend/elements-backend.sln | 27 ++++++++++++++ backend/justfile | 2 ++ 12 files changed, 199 insertions(+) create mode 100644 backend/Elements.Backend/Controllers/WeatherForecastController.cs create mode 100644 backend/Elements.Backend/Elements.Backend.csproj create mode 100644 backend/Elements.Backend/Program.cs create mode 100644 backend/Elements.Backend/Properties/launchSettings.json create mode 100644 backend/Elements.Backend/WeatherForecast.cs create mode 100644 backend/Elements.Backend/appsettings.Development.json create mode 100644 backend/Elements.Backend/appsettings.json create mode 100644 backend/Elements.Data/ApplicationDbContext.cs create mode 100644 backend/Elements.Data/Elements.Data.csproj create mode 100644 backend/Elements.Data/Models/Element.cs create mode 100644 backend/elements-backend.sln create mode 100644 backend/justfile (limited to 'backend') diff --git a/backend/Elements.Backend/Controllers/WeatherForecastController.cs b/backend/Elements.Backend/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..9a70e36 --- /dev/null +++ b/backend/Elements.Backend/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Elements.Backend.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/backend/Elements.Backend/Elements.Backend.csproj b/backend/Elements.Backend/Elements.Backend.csproj new file mode 100644 index 0000000..0c664a6 --- /dev/null +++ b/backend/Elements.Backend/Elements.Backend.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + diff --git a/backend/Elements.Backend/Program.cs b/backend/Elements.Backend/Program.cs new file mode 100644 index 0000000..15eacee --- /dev/null +++ b/backend/Elements.Backend/Program.cs @@ -0,0 +1,25 @@ +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.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/backend/Elements.Backend/Properties/launchSettings.json b/backend/Elements.Backend/Properties/launchSettings.json new file mode 100644 index 0000000..0a48056 --- /dev/null +++ b/backend/Elements.Backend/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:32536", + "sslPort": 44324 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5102", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7014;http://localhost:5102", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/backend/Elements.Backend/WeatherForecast.cs b/backend/Elements.Backend/WeatherForecast.cs new file mode 100644 index 0000000..7c8962e --- /dev/null +++ b/backend/Elements.Backend/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Elements.Backend; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/backend/Elements.Backend/appsettings.Development.json b/backend/Elements.Backend/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/backend/Elements.Backend/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/backend/Elements.Backend/appsettings.json b/backend/Elements.Backend/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/backend/Elements.Backend/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/backend/Elements.Data/ApplicationDbContext.cs b/backend/Elements.Data/ApplicationDbContext.cs new file mode 100644 index 0000000..619719a --- /dev/null +++ b/backend/Elements.Data/ApplicationDbContext.cs @@ -0,0 +1,7 @@ +using Microsoft.EntityFrameworkCore; + +namespace Elements.Data; +public class ApplicationDbContext : DbContext +{ + +} diff --git a/backend/Elements.Data/Elements.Data.csproj b/backend/Elements.Data/Elements.Data.csproj new file mode 100644 index 0000000..408fea2 --- /dev/null +++ b/backend/Elements.Data/Elements.Data.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/backend/Elements.Data/Models/Element.cs b/backend/Elements.Data/Models/Element.cs new file mode 100644 index 0000000..2f602e5 --- /dev/null +++ b/backend/Elements.Data/Models/Element.cs @@ -0,0 +1,5 @@ +namespace Elements.Data.Models; + +public class Element { + +} \ No newline at end of file diff --git a/backend/elements-backend.sln b/backend/elements-backend.sln new file mode 100644 index 0000000..700c51d --- /dev/null +++ b/backend/elements-backend.sln @@ -0,0 +1,27 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elements.Backend", "Elements.Backend\Elements.Backend.csproj", "{2E7A83DE-9B0C-4ACE-BCAB-ADBB8B624EF8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elements.Data", "Elements.Data\Elements.Data.csproj", "{9772A869-D6F0-4BE4-A42F-A64420405223}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2E7A83DE-9B0C-4ACE-BCAB-ADBB8B624EF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E7A83DE-9B0C-4ACE-BCAB-ADBB8B624EF8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E7A83DE-9B0C-4ACE-BCAB-ADBB8B624EF8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E7A83DE-9B0C-4ACE-BCAB-ADBB8B624EF8}.Release|Any CPU.Build.0 = Release|Any CPU + {9772A869-D6F0-4BE4-A42F-A64420405223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9772A869-D6F0-4BE4-A42F-A64420405223}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9772A869-D6F0-4BE4-A42F-A64420405223}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9772A869-D6F0-4BE4-A42F-A64420405223}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/backend/justfile b/backend/justfile new file mode 100644 index 0000000..59f4670 --- /dev/null +++ b/backend/justfile @@ -0,0 +1,2 @@ +dev: + dotnet watch --project ./Elements.Backend \ No newline at end of file -- cgit v1.2.3