From d5394c869f24a6b65ca0c7ea7f193675097f0ae7 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 25 Mar 2023 16:13:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= =?UTF-8?q?=20RestApi.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopRestApi.csproj | 13 ++++++ .../Controllers/WeatherForecastController.cs | 33 ++++++++++++++ .../BlackmithWorkshopRestApi/Program.cs | 45 +++++++++++++++++++ .../Properties/launchSettings.json | 31 +++++++++++++ .../WeatherForecast.cs | 13 ++++++ .../appsettings.Development.json | 8 ++++ .../BlackmithWorkshopRestApi/appsettings.json | 9 ++++ .../BlackmithWorkshopRestApi/log4net.config | 16 +++++++ BlacksmithWorkshop/BlacksmithWorkshop.sln | 8 +++- 9 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/WeatherForecastController.cs create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/Properties/launchSettings.json create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/WeatherForecast.cs create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.Development.json create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json create mode 100644 BlacksmithWorkshop/BlackmithWorkshopRestApi/log4net.config diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj b/BlacksmithWorkshop/BlackmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj new file mode 100644 index 0000000..60bf9ea --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/WeatherForecastController.cs b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..5015fd6 --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace BlackmithWorkshopRestApi.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 = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs new file mode 100644 index 0000000..9c4ad3f --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Program.cs @@ -0,0 +1,45 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogic; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); + +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); + +// Add services to the container. + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "BlacksmithWorkshopRestApi", Version = "v1" }); +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlacksmithWorkshopRestApi v1")); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/Properties/launchSettings.json b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..7cc13d2 --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:22588", + "sslPort": 44369 + } + }, + "profiles": { + "BlackmithWorkshopRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7272;http://localhost:5169", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/WeatherForecast.cs b/BlacksmithWorkshop/BlackmithWorkshopRestApi/WeatherForecast.cs new file mode 100644 index 0000000..446e2c4 --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace BlackmithWorkshopRestApi +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.Development.json b/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json b/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/BlacksmithWorkshop/BlackmithWorkshopRestApi/log4net.config b/BlacksmithWorkshop/BlackmithWorkshopRestApi/log4net.config new file mode 100644 index 0000000..e84682e --- /dev/null +++ b/BlacksmithWorkshop/BlackmithWorkshopRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 9bee79b..c6a8c00 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{58737D93-9A12-4D07-BF3F-86AC512CE626}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{EE03BAE3-52EE-4E3B-8992-382D89E61E1A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{EE03BAE3-52EE-4E3B-8992-382D89E61E1A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopRestApi", "BlackmithWorkshopRestApi\BlacksmithWorkshopRestApi.csproj", "{23DBD9A3-2107-44AB-8B87-6982BFD2E69A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {EE03BAE3-52EE-4E3B-8992-382D89E61E1A}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE03BAE3-52EE-4E3B-8992-382D89E61E1A}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE03BAE3-52EE-4E3B-8992-382D89E61E1A}.Release|Any CPU.Build.0 = Release|Any CPU + {23DBD9A3-2107-44AB-8B87-6982BFD2E69A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23DBD9A3-2107-44AB-8B87-6982BFD2E69A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23DBD9A3-2107-44AB-8B87-6982BFD2E69A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23DBD9A3-2107-44AB-8B87-6982BFD2E69A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE