From 0dd6a438d5bd29d583e38f176922dda31936e79d Mon Sep 17 00:00:00 2001 From: Peace Date: Tue, 11 Jun 2024 11:06:03 +0900 Subject: [PATCH] initial commit --- AspNetCoreLearnOfficial.sln | 25 +++++++++++ .../Controllers/WeatherForecastController.cs | 32 +++++++++++++++ WebApi/Program.cs | 25 +++++++++++ WebApi/Properties/launchSettings.json | 41 +++++++++++++++++++ WebApi/WeatherForecast.cs | 12 ++++++ WebApi/WebApi.csproj | 13 ++++++ WebApi/WebApi.http | 6 +++ WebApi/appsettings.Development.json | 8 ++++ WebApi/appsettings.json | 9 ++++ 9 files changed, 171 insertions(+) create mode 100644 AspNetCoreLearnOfficial.sln create mode 100644 WebApi/Controllers/WeatherForecastController.cs create mode 100644 WebApi/Program.cs create mode 100644 WebApi/Properties/launchSettings.json create mode 100644 WebApi/WeatherForecast.cs create mode 100644 WebApi/WebApi.csproj create mode 100644 WebApi/WebApi.http create mode 100644 WebApi/appsettings.Development.json create mode 100644 WebApi/appsettings.json diff --git a/AspNetCoreLearnOfficial.sln b/AspNetCoreLearnOfficial.sln new file mode 100644 index 0000000..05f29d1 --- /dev/null +++ b/AspNetCoreLearnOfficial.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csproj", "{9FAB855B-340B-4F20-9C96-091F36B18706}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9FAB855B-340B-4F20-9C96-091F36B18706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FAB855B-340B-4F20-9C96-091F36B18706}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FAB855B-340B-4F20-9C96-091F36B18706}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FAB855B-340B-4F20-9C96-091F36B18706}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EAE6BC68-7A3E-4C7D-8D32-B86228BEDCEC} + EndGlobalSection +EndGlobal diff --git a/WebApi/Controllers/WeatherForecastController.cs b/WebApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..54a483b --- /dev/null +++ b/WebApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApi.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/WebApi/Program.cs b/WebApi/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/WebApi/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/WebApi/Properties/launchSettings.json b/WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..34d5b45 --- /dev/null +++ b/WebApi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12166", + "sslPort": 44336 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5002", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7052;http://localhost:5002", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WebApi/WeatherForecast.cs b/WebApi/WeatherForecast.cs new file mode 100644 index 0000000..74fbd83 --- /dev/null +++ b/WebApi/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace WebApi; + +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/WebApi/WebApi.csproj b/WebApi/WebApi.csproj new file mode 100644 index 0000000..9daa180 --- /dev/null +++ b/WebApi/WebApi.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/WebApi/WebApi.http b/WebApi/WebApi.http new file mode 100644 index 0000000..840c1df --- /dev/null +++ b/WebApi/WebApi.http @@ -0,0 +1,6 @@ +@WebApi_HostAddress = http://localhost:5002 + +GET {{WebApi_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/WebApi/appsettings.Development.json b/WebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/WebApi/appsettings.json b/WebApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/WebApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}