From 7b22e6631039988940a72850eaf1b3659e54ba93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=97=E6=B5=94?= <2919054393@qq.com> Date: Sun, 20 Oct 2024 23:44:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apimanager_backend.sln | 25 +++++++++++ Apimanager_backend/Apimanager_backend.csproj | 13 ++++++ Apimanager_backend/Apimanager_backend.http | 6 +++ .../Controllers/WeatherForecastController.cs | 33 +++++++++++++++ Apimanager_backend/Program.cs | 25 +++++++++++ .../Properties/launchSettings.json | 41 +++++++++++++++++++ Apimanager_backend/WeatherForecast.cs | 13 ++++++ .../appsettings.Development.json | 8 ++++ Apimanager_backend/appsettings.json | 9 ++++ 9 files changed, 173 insertions(+) create mode 100644 Apimanager_backend.sln create mode 100644 Apimanager_backend/Apimanager_backend.csproj create mode 100644 Apimanager_backend/Apimanager_backend.http create mode 100644 Apimanager_backend/Controllers/WeatherForecastController.cs create mode 100644 Apimanager_backend/Program.cs create mode 100644 Apimanager_backend/Properties/launchSettings.json create mode 100644 Apimanager_backend/WeatherForecast.cs create mode 100644 Apimanager_backend/appsettings.Development.json create mode 100644 Apimanager_backend/appsettings.json diff --git a/Apimanager_backend.sln b/Apimanager_backend.sln new file mode 100644 index 0000000..36300f7 --- /dev/null +++ b/Apimanager_backend.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apimanager_backend", "Apimanager_backend\Apimanager_backend.csproj", "{F4FD5145-6971-4032-B2B6-D7A61AF8BB2E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F4FD5145-6971-4032-B2B6-D7A61AF8BB2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4FD5145-6971-4032-B2B6-D7A61AF8BB2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4FD5145-6971-4032-B2B6-D7A61AF8BB2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F4FD5145-6971-4032-B2B6-D7A61AF8BB2E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1E84B967-07AF-4318-9BC3-8C66563CE795} + EndGlobalSection +EndGlobal diff --git a/Apimanager_backend/Apimanager_backend.csproj b/Apimanager_backend/Apimanager_backend.csproj new file mode 100644 index 0000000..9daa180 --- /dev/null +++ b/Apimanager_backend/Apimanager_backend.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Apimanager_backend/Apimanager_backend.http b/Apimanager_backend/Apimanager_backend.http new file mode 100644 index 0000000..1122844 --- /dev/null +++ b/Apimanager_backend/Apimanager_backend.http @@ -0,0 +1,6 @@ +@Apimanager_backend_HostAddress = http://localhost:5292 + +GET {{Apimanager_backend_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Apimanager_backend/Controllers/WeatherForecastController.cs b/Apimanager_backend/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..028579e --- /dev/null +++ b/Apimanager_backend/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Apimanager_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.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Apimanager_backend/Program.cs b/Apimanager_backend/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Apimanager_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/Apimanager_backend/Properties/launchSettings.json b/Apimanager_backend/Properties/launchSettings.json new file mode 100644 index 0000000..dd75711 --- /dev/null +++ b/Apimanager_backend/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1132", + "sslPort": 44318 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5292", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7031;http://localhost:5292", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Apimanager_backend/WeatherForecast.cs b/Apimanager_backend/WeatherForecast.cs new file mode 100644 index 0000000..d21615d --- /dev/null +++ b/Apimanager_backend/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Apimanager_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/Apimanager_backend/appsettings.Development.json b/Apimanager_backend/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Apimanager_backend/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Apimanager_backend/appsettings.json b/Apimanager_backend/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Apimanager_backend/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}