server post wip
This commit is contained in:
1 parent
ef95f63d14
commit
d6445332be
13 files changed
+239
-30
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Server.Models;
|
||||
|
||||
namespace Server.Controllers;
|
||||
@@ -22,18 +21,44 @@ public class LapController : ControllerBase {
|
||||
UserId = c.UserId,
|
||||
Map = c.Map,
|
||||
Time = c.Time,
|
||||
Date = c.Date,
|
||||
Created = c.Created,
|
||||
});
|
||||
}
|
||||
|
||||
// [HttpGet()]
|
||||
// public LapStorageDTO UserLaps(Guid userId, string mapName) {
|
||||
// List<Lap> laps = _db.Laps
|
||||
// .Where(l => l.Id == userId)
|
||||
// .Where(l => l.Map == mapName);
|
||||
|
||||
// int completions = _db.Laps
|
||||
// .Where(l => l.Map == mapName)
|
||||
// .Count();
|
||||
|
||||
// int position = _db.Database<Laps>.sql("""
|
||||
// SELECT
|
||||
// """);
|
||||
|
||||
// return new LapStorageDTO {
|
||||
// Map = mapName,
|
||||
// Laps = laps,
|
||||
// public int Completions { get; set; }
|
||||
// public int Position { get; set; }
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
[HttpPost()]
|
||||
public async Task<Lap> Post(LapDTO dto) {
|
||||
Lap existing = _db.Laps
|
||||
.SingleOrDefault(l => l.UserId == dto.UserId && l.Map == dto.Map);
|
||||
|
||||
Lap v = new Lap {
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
UserId = dto.UserId,
|
||||
Map = dto.Map,
|
||||
Time = dto.Time,
|
||||
Date = DateTimeOffset.UtcNow,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
_db.Laps.Add(v);
|
||||
|
||||
+4
-3
@@ -12,7 +12,7 @@ using Server;
|
||||
namespace Server.Migrations
|
||||
{
|
||||
[DbContext(typeof(SpaceRaceDbContext))]
|
||||
[Migration("20230823032740_Beginninging")]
|
||||
[Migration("20230828112623_Beginninging")]
|
||||
partial class Beginninging
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -31,7 +31,7 @@ namespace Server.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("Date")
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Map")
|
||||
@@ -48,7 +48,8 @@ namespace Server.Migrations
|
||||
|
||||
b.HasIndex("Map");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
b.HasIndex("UserId", "Map")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Laps");
|
||||
});
|
||||
+6
-5
@@ -16,10 +16,10 @@ namespace Server.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Map = table.Column<string>(type: "text", nullable: false),
|
||||
Time = table.Column<double>(type: "double precision", nullable: false)
|
||||
Time = table.Column<double>(type: "double precision", nullable: false),
|
||||
Map = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@@ -32,9 +32,10 @@ namespace Server.Migrations
|
||||
column: "Map");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Laps_UserId",
|
||||
name: "IX_Laps_UserId_Map",
|
||||
table: "Laps",
|
||||
column: "UserId");
|
||||
columns: new[] { "UserId", "Map" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -28,7 +28,7 @@ namespace Server.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("Date")
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Map")
|
||||
@@ -45,7 +45,8 @@ namespace Server.Migrations
|
||||
|
||||
b.HasIndex("Map");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
b.HasIndex("UserId", "Map")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Laps");
|
||||
});
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Server.Models;
|
||||
|
||||
public class LapDTO {
|
||||
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,9 @@
|
||||
namespace Server.Models;
|
||||
|
||||
public class LapDTO {
|
||||
public DateTimeOffset Created { 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,10 @@
|
||||
namespace Server.Models;
|
||||
|
||||
public class PbDTO {
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public double Time { get; set; }
|
||||
public string Map { get; set; }
|
||||
public int Completions { get; set; }
|
||||
public int Position { get; set; }
|
||||
}
|
||||
@@ -8,12 +8,12 @@ public class SpaceRaceDbContext : DbContext {
|
||||
public SpaceRaceDbContext(DbContextOptions<SpaceRaceDbContext> options) : base(options) {}
|
||||
}
|
||||
|
||||
[Index(nameof(UserId))]
|
||||
[Index(nameof(UserId), nameof(Map), IsUnique = true)]
|
||||
[Index(nameof(Map))]
|
||||
public class Lap {
|
||||
public DateTimeOffset Date { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
[Required] public string Map { get; set; }
|
||||
public double Time { get; set; }
|
||||
public DateTimeOffset Created { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public double Time { get; set; }
|
||||
[Required] public string Map { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user