From 13f9cd4920e86f7f8b5d03564416a0def5c0d031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Mon, 29 Apr 2024 21:38:18 +0400 Subject: [PATCH] RestApi Create --- ElectronicsShop/ElectronicsShop.sln | 10 ++++- .../Controllers/WeatherForecastController.cs | 33 +++++++++++++++ .../ElectronicsShopResrAPI.csproj | 14 +++++++ .../ElectronicsShopResrAPI.http | 6 +++ .../ElectronicsShopResrAPI/Program.cs | 25 +++++++++++ .../Properties/launchSettings.json | 41 +++++++++++++++++++ .../ElectronicsShopResrAPI/WeatherForecast.cs | 13 ++++++ .../appsettings.Development.json | 8 ++++ .../ElectronicsShopResrAPI/appsettings.json | 9 ++++ 9 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/Controllers/WeatherForecastController.cs create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.csproj create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.http create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/Program.cs create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/Properties/launchSettings.json create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/WeatherForecast.cs create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/appsettings.Development.json create mode 100644 ElectronicsShop/ElectronicsShopResrAPI/appsettings.json diff --git a/ElectronicsShop/ElectronicsShop.sln b/ElectronicsShop/ElectronicsShop.sln index 46ecf12..abe021b 100644 --- a/ElectronicsShop/ElectronicsShop.sln +++ b/ElectronicsShop/ElectronicsShop.sln @@ -7,9 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopDataModels", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopContracts", "ElectronicsShopContracts\ElectronicsShopContracts.csproj", "{69411E41-F304-4D1B-8F15-48DD08585C7A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopBusinessLogic", "ElectronicsShopBusinessLogic\ElectronicsShopBusinessLogic.csproj", "{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopBusinessLogic", "ElectronicsShopBusinessLogic\ElectronicsShopBusinessLogic.csproj", "{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopDataBaseImplement", "ElectronicsShopDataBaseImplement\ElectronicsShopDataBaseImplement.csproj", "{03442D38-4C09-49D1-85F3-F8F563072F9B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopDataBaseImplement", "ElectronicsShopDataBaseImplement\ElectronicsShopDataBaseImplement.csproj", "{03442D38-4C09-49D1-85F3-F8F563072F9B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopResrAPI", "ElectronicsShopResrAPI\ElectronicsShopResrAPI.csproj", "{BDEC8526-DB9D-49F3-93B5-8777339CC040}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {03442D38-4C09-49D1-85F3-F8F563072F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU {03442D38-4C09-49D1-85F3-F8F563072F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU {03442D38-4C09-49D1-85F3-F8F563072F9B}.Release|Any CPU.Build.0 = Release|Any CPU + {BDEC8526-DB9D-49F3-93B5-8777339CC040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BDEC8526-DB9D-49F3-93B5-8777339CC040}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BDEC8526-DB9D-49F3-93B5-8777339CC040}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BDEC8526-DB9D-49F3-93B5-8777339CC040}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ElectronicsShop/ElectronicsShopResrAPI/Controllers/WeatherForecastController.cs b/ElectronicsShop/ElectronicsShopResrAPI/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..9a094e4 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace ElectronicsShopResrAPI.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.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.csproj b/ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.csproj new file mode 100644 index 0000000..ba558e4 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + true + + + + + + + diff --git a/ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.http b/ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.http new file mode 100644 index 0000000..2730b38 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/ElectronicsShopResrAPI.http @@ -0,0 +1,6 @@ +@ElectronicsShopResrAPI_HostAddress = http://localhost:5176 + +GET {{ElectronicsShopResrAPI_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/ElectronicsShop/ElectronicsShopResrAPI/Program.cs b/ElectronicsShop/ElectronicsShopResrAPI/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/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/ElectronicsShop/ElectronicsShopResrAPI/Properties/launchSettings.json b/ElectronicsShop/ElectronicsShopResrAPI/Properties/launchSettings.json new file mode 100644 index 0000000..8a84e85 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:50570", + "sslPort": 44304 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5176", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7183;http://localhost:5176", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/ElectronicsShop/ElectronicsShopResrAPI/WeatherForecast.cs b/ElectronicsShop/ElectronicsShopResrAPI/WeatherForecast.cs new file mode 100644 index 0000000..f7a49c6 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace ElectronicsShopResrAPI +{ + 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/ElectronicsShop/ElectronicsShopResrAPI/appsettings.Development.json b/ElectronicsShop/ElectronicsShopResrAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/ElectronicsShop/ElectronicsShopResrAPI/appsettings.json b/ElectronicsShop/ElectronicsShopResrAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopResrAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}