RestApi Create

This commit is contained in:
Игорь Гордеев 2024-04-29 21:38:18 +04:00
parent ccb78dd53d
commit 13f9cd4920
9 changed files with 157 additions and 2 deletions

View File

@ -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

View File

@ -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<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> 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();
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@ElectronicsShopResrAPI_HostAddress = http://localhost:5176
GET {{ElectronicsShopResrAPI_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -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();

View File

@ -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"
}
}
}
}

View File

@ -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; }
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}