server init
This commit is contained in:
1 parent
9e217e1a92
commit
b54c003244
14 files changed
+213
-6
No files matched your search
@@ -0,0 +1,3 @@
|
||||
POSTGRES_USER="spacerace"
|
||||
POSTGRES_DB="spacerace"
|
||||
POSTGRES_PASSWORD="zoomzoom"
|
||||
@@ -0,0 +1,47 @@
|
||||
db/
|
||||
|
||||
# -----------------
|
||||
|
||||
*.swp
|
||||
*.*~
|
||||
project.lock.json
|
||||
.DS_Store
|
||||
*.pyc
|
||||
nupkg/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
# Rider
|
||||
.idea/
|
||||
|
||||
# Visual Studio
|
||||
.vs/
|
||||
|
||||
# Fleet
|
||||
.fleet/
|
||||
|
||||
# Code Rush
|
||||
.cr/
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
build/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
msbuild.log
|
||||
msbuild.err
|
||||
msbuild.wrn
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Server.Models;
|
||||
|
||||
namespace Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class CompletionController : ControllerBase {
|
||||
private readonly ILogger<CompletionController> _logger;
|
||||
|
||||
public CompletionController(ILogger<CompletionController> logger) {
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetCompletion")]
|
||||
public IEnumerable<CompletionDTO> Get() {
|
||||
return Enumerable.Range(1, 5).Select(index => new CompletionDTO()).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
|
||||
WORKDIR /App
|
||||
|
||||
# stops restore during build
|
||||
COPY Server.csproj ./
|
||||
RUN dotnet restore
|
||||
|
||||
COPY . ./
|
||||
RUN dotnet publish -c Release -o out
|
||||
|
||||
# Build runtime image
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0
|
||||
WORKDIR /App
|
||||
COPY --from=build-env /App/out .
|
||||
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Server.Models;
|
||||
|
||||
public class CompletionDTO {
|
||||
public DateTimeOffset Date { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public string Map { get; set; }
|
||||
public double Time { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Server;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddDbContextPool<SpaceRaceDbContext>(options => {
|
||||
options.UseNpgsql(
|
||||
builder.Configuration.GetConnectionString("SpaceRace"),
|
||||
assembly => assembly.MigrationsAssembly(typeof(SpaceRaceDbContext).Assembly.FullName)
|
||||
);
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:58932",
|
||||
"sslPort": 44337
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5212",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7246;http://localhost:5212",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public class SpaceRaceDbContext : DbContext {
|
||||
public DbSet<Completion> Completions { get; set; }
|
||||
public SpaceRaceDbContext(DbContextOptions<SpaceRaceDbContext> options) : base(options) {}
|
||||
}
|
||||
|
||||
public class Completion {
|
||||
public DateTimeOffset Date { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public string Map { get; set; }
|
||||
public double Time { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"SpaceRace": "Server=pg;Port=5432;Database=spacerace;User Id=spacerace;Password=zoomzoom",
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
services:
|
||||
pg:
|
||||
image: postgres:latest
|
||||
environment:
|
||||
POSTGRES_USER: '${POSTGRES_USER}'
|
||||
POSTGRES_DB: '${POSTGRES_DB}'
|
||||
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
|
||||
ports:
|
||||
- '45432:5432'
|
||||
volumes:
|
||||
- "./db:/var/lib/postgresql/data"
|
||||
|
||||
server:
|
||||
environment:
|
||||
CONNECTIONSTRINGS__SPACERACE: "Server=pg;Port=5432;Database=${POSTGRES_DB};User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
Reference in new issue
Block a user