This commit is contained in:
2020-02-25 22:39:40 +01:00
commit de3da55bac
16 changed files with 436 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using System;
using System.Threading.Tasks;
using EstusShots.Server.Services;
using EstusShots.Shared.Models;
using Microsoft.AspNetCore.Mvc;
namespace EstusShots.Server.Controllers
{
[ApiController]
[Route("/api/[controller]")]
public class SeasonsController : ControllerBase
{
private readonly EstusShotsContext _context;
public SeasonsController(EstusShotsContext context)
{
_context = context;
}
[HttpGet("{id}")]
public async Task<ActionResult<Season>> GetSeason(Guid id)
{
var season = await _context.Seasons.FindAsync(id);
if (season == null) return NotFound();
return season;
}
[HttpPost]
public async Task<ActionResult<Season>> CreateSeason(Season season)
{
_context.Seasons.Add(season);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(GetSeason), new {id = season.SeasonId}, season);
}
}
}

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<WarningsAsErrors>NU1605;CS8618</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<WarningsAsErrors>NU1605;CS8618</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EstusShots.Shared\EstusShots.Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace EstusShots.Server
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}

View File

@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:26850",
"sslPort": 44318
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"EstusShots.Server": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,14 @@
using EstusShots.Shared.Models;
using Microsoft.EntityFrameworkCore;
namespace EstusShots.Server.Services
{
public class EstusShotsContext : DbContext
{
public EstusShotsContext(DbContextOptions options) : base(options)
{
}
public DbSet<Season> Seasons { get; set; } = default!;
}
}

View File

@@ -0,0 +1,47 @@
using EstusShots.Server.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace EstusShots.Server
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<EstusShotsContext>(
opt => opt.UseInMemoryDatabase("debug.db"));
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
if (!env.IsDevelopment())
{
app.UseHttpsRedirection();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}