parent
38399bd863
commit
3c97c27c94
@ -0,0 +1,33 @@ |
||||
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<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 = DateTime.Now.AddDays(index), |
||||
TemperatureC = Random.Shared.Next(-20, 55), |
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] |
||||
}) |
||||
.ToArray(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
using Microsoft.EntityFrameworkCore; |
||||
using WebAPI.Data; |
||||
|
||||
namespace WebAPI |
||||
{ |
||||
public class Program |
||||
{ |
||||
public static void Main(string[] args) |
||||
{ |
||||
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 connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); |
||||
builder.Services.AddDbContext<ApplicationDbContext>(options => |
||||
options.UseSqlServer(connectionString)); |
||||
|
||||
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(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
namespace WebAPI |
||||
{ |
||||
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; } |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
||||
<PropertyGroup> |
||||
<TargetFramework>net6.0</TargetFramework> |
||||
<Nullable>enable</Nullable> |
||||
<ImplicitUsings>enable</ImplicitUsings> |
||||
</PropertyGroup> |
||||
|
||||
<ItemGroup> |
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" /> |
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10"> |
||||
<PrivateAssets>all</PrivateAssets> |
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
||||
</PackageReference> |
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" /> |
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> |
||||
</ItemGroup> |
||||
|
||||
<ItemGroup> |
||||
<ProjectReference Include="..\SharedData\SharedData.csproj" /> |
||||
</ItemGroup> |
||||
|
||||
<ItemGroup> |
||||
<Folder Include="Migrations\" /> |
||||
</ItemGroup> |
||||
|
||||
</Project> |
@ -0,0 +1,8 @@ |
||||
{ |
||||
"Logging": { |
||||
"LogLevel": { |
||||
"Default": "Information", |
||||
"Microsoft.AspNetCore": "Warning" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
{ |
||||
"ConnectionStrings": { |
||||
"DefaultConnection": "Data Source=peacecloud.synology.me,21433;Initial Catalog=RankingAPI;User ID=study;Password=Study1234;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" |
||||
}, |
||||
"Logging": { |
||||
"LogLevel": { |
||||
"Default": "Information", |
||||
"Microsoft.AspNetCore": "Warning" |
||||
} |
||||
}, |
||||
"AllowedHosts": "*" |
||||
} |
Loading…
Reference in new issue