From 3111e4e1091efd1df376b262f54579211056dda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 6 Apr 2023 17:19:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20RestApi,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20log=20(=D0=92=D1=81=D0=B5=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F,=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D1=81=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hotel/Hotel.sln | 8 ++++- .../Controllers/WeatherForecastController.cs | 33 +++++++++++++++++ Hotel/HotelRestApi/HotelRestApi.csproj | 14 ++++++++ Hotel/HotelRestApi/Program.cs | 36 +++++++++++++++++++ .../Properties/launchSettings.json | 31 ++++++++++++++++ Hotel/HotelRestApi/WeatherForecast.cs | 13 +++++++ .../HotelRestApi/appsettings.Development.json | 8 +++++ Hotel/HotelRestApi/appsettings.json | 9 +++++ Hotel/HotelRestApi/log4net.config | 16 +++++++++ 9 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 Hotel/HotelRestApi/Controllers/WeatherForecastController.cs create mode 100644 Hotel/HotelRestApi/HotelRestApi.csproj create mode 100644 Hotel/HotelRestApi/Program.cs create mode 100644 Hotel/HotelRestApi/Properties/launchSettings.json create mode 100644 Hotel/HotelRestApi/WeatherForecast.cs create mode 100644 Hotel/HotelRestApi/appsettings.Development.json create mode 100644 Hotel/HotelRestApi/appsettings.json create mode 100644 Hotel/HotelRestApi/log4net.config diff --git a/Hotel/Hotel.sln b/Hotel/Hotel.sln index 22461ca..80d58e3 100644 --- a/Hotel/Hotel.sln +++ b/Hotel/Hotel.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataModels", "HotelDat EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{234B3526-A74E-43D2-9333-E74B4FF9A356}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelRestApi", "HotelRestApi\HotelRestApi.csproj", "{1D7D511E-66E9-480F-92B9-9E1A33916DCF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Release|Any CPU.Build.0 = Release|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D7D511E-66E9-480F-92B9-9E1A33916DCF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hotel/HotelRestApi/Controllers/WeatherForecastController.cs b/Hotel/HotelRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..469de39 --- /dev/null +++ b/Hotel/HotelRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace HotelRestApi.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/Hotel/HotelRestApi/HotelRestApi.csproj b/Hotel/HotelRestApi/HotelRestApi.csproj new file mode 100644 index 0000000..2cd3993 --- /dev/null +++ b/Hotel/HotelRestApi/HotelRestApi.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Hotel/HotelRestApi/Program.cs b/Hotel/HotelRestApi/Program.cs new file mode 100644 index 0000000..d067d73 --- /dev/null +++ b/Hotel/HotelRestApi/Program.cs @@ -0,0 +1,36 @@ +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); + +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); + +/* +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddControllers();*/ +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "ConfectoneryRestApi", + Version = "v1" + }); +}); +var app = builder.Build(); +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "ConfectoneryRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); diff --git a/Hotel/HotelRestApi/Properties/launchSettings.json b/Hotel/HotelRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..b7528ce --- /dev/null +++ b/Hotel/HotelRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:18210", + "sslPort": 44326 + } + }, + "profiles": { + "HotelRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7079;http://localhost:5079", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Hotel/HotelRestApi/WeatherForecast.cs b/Hotel/HotelRestApi/WeatherForecast.cs new file mode 100644 index 0000000..78d86f6 --- /dev/null +++ b/Hotel/HotelRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace HotelRestApi +{ + 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/Hotel/HotelRestApi/appsettings.Development.json b/Hotel/HotelRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Hotel/HotelRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Hotel/HotelRestApi/appsettings.json b/Hotel/HotelRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Hotel/HotelRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Hotel/HotelRestApi/log4net.config b/Hotel/HotelRestApi/log4net.config new file mode 100644 index 0000000..43b77f9 --- /dev/null +++ b/Hotel/HotelRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file