This commit is contained in:
ntr committed 2023-08-29 11:45:08 +10:00
1 parent b2bfb72863
commit 9f857aeeda
5 files changed
+104 -10

No files matched your search

@@ -25,15 +25,6 @@ public class LapController : ControllerBase {
});
}
// with ranked as (
// select *, rank() over (order by "Time" asc) as "Position", count("Id") over ()
// from "Laps"
// where "Map" = 'surf_kitsune2_go'
// )
// select * from ranked
// where "UserId" = '116bf9a6-b618-48ef-ac78-d294abb500b2';
// [HttpGet()]
// public LapStorageDTO UserLaps(Guid userId, string mapName) {
// List<Lap> laps = _db.Laps
@@ -12,7 +12,7 @@ using Server;
namespace Server.Migrations
{
[DbContext(typeof(SpaceRaceDbContext))]
[Migration("20230828112623_Beginninging")]
[Migration("20230829014321_Beginninging")]
partial class Beginninging
{
/// <inheritdoc />
@@ -52,6 +52,32 @@ namespace Server.Migrations
.IsUnique();
b.ToTable("Laps");
b.HasData(
new
{
Id = new Guid("c3a3f8d9-01a7-4420-bb57-a8f26baabc4d"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5704), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack",
Time = 128.0,
UserId = new Guid("9d2c95b9-5ba6-4ff5-afc5-f20f34620d82")
},
new
{
Id = new Guid("6cb7876e-3059-44ea-af56-1968d653f001"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5742), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack",
Time = 132.0,
UserId = new Guid("157a119a-e3e2-4623-ac6c-2dda797dd301")
},
new
{
Id = new Guid("2b649610-1da8-450a-ad24-021626d80c60"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5750), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack",
Time = 148.0,
UserId = new Guid("7ca95bb5-0145-4c59-86cc-a499b01ba036")
});
});
#pragma warning restore 612, 618
}
@@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Server.Migrations
{
/// <inheritdoc />
@@ -26,6 +28,16 @@ namespace Server.Migrations
table.PrimaryKey("PK_Laps", x => x.Id);
});
migrationBuilder.InsertData(
table: "Laps",
columns: new[] { "Id", "Created", "Map", "Time", "UserId" },
values: new object[,]
{
{ new Guid("2b649610-1da8-450a-ad24-021626d80c60"), new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5750), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", 148.0, new Guid("7ca95bb5-0145-4c59-86cc-a499b01ba036") },
{ new Guid("6cb7876e-3059-44ea-af56-1968d653f001"), new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5742), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", 132.0, new Guid("157a119a-e3e2-4623-ac6c-2dda797dd301") },
{ new Guid("c3a3f8d9-01a7-4420-bb57-a8f26baabc4d"), new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5704), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", 128.0, new Guid("9d2c95b9-5ba6-4ff5-afc5-f20f34620d82") }
});
migrationBuilder.CreateIndex(
name: "IX_Laps_Map",
table: "Laps",
@@ -49,6 +49,32 @@ namespace Server.Migrations
.IsUnique();
b.ToTable("Laps");
b.HasData(
new
{
Id = new Guid("c3a3f8d9-01a7-4420-bb57-a8f26baabc4d"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5704), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack",
Time = 128.0,
UserId = new Guid("9d2c95b9-5ba6-4ff5-afc5-f20f34620d82")
},
new
{
Id = new Guid("6cb7876e-3059-44ea-af56-1968d653f001"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5742), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack",
Time = 132.0,
UserId = new Guid("157a119a-e3e2-4623-ac6c-2dda797dd301")
},
new
{
Id = new Guid("2b649610-1da8-450a-ad24-021626d80c60"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 1, 43, 21, 914, DateTimeKind.Unspecified).AddTicks(5750), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack",
Time = 148.0,
UserId = new Guid("7ca95bb5-0145-4c59-86cc-a499b01ba036")
});
});
#pragma warning restore 612, 618
}
+39
View File
@@ -6,6 +6,11 @@ namespace Server;
public class SpaceRaceDbContext : DbContext {
public DbSet<Lap> Laps { get; set; }
public SpaceRaceDbContext(DbContextOptions<SpaceRaceDbContext> options) : base(options) {}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
new SpaceRaceInitialiser(modelBuilder).Seed();
}
}
[Index(nameof(UserId), nameof(Map), IsUnique = true)]
@@ -17,3 +22,37 @@ public class Lap {
public double Time { get; set; }
[Required] public string Map { get; set; }
}
class SpaceRaceInitialiser {
private readonly ModelBuilder modelBuilder;
public SpaceRaceInitialiser(ModelBuilder modelBuilder) {
this.modelBuilder = modelBuilder;
}
public void Seed() {
modelBuilder.Entity<Lap>().HasData(
new Lap {
Created = DateTimeOffset.UtcNow,
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Time = 128f,
Map = "sr_TestTrack",
},
new Lap {
Created = DateTimeOffset.UtcNow,
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Time = 132f,
Map = "sr_TestTrack",
},
new Lap {
Created = DateTimeOffset.UtcNow,
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Time = 148f,
Map = "sr_TestTrack",
}
);
}
}