server post wip

This commit is contained in:
ntr committed 2023-08-29 11:06:53 +10:00
1 parent ef95f63d14
commit d6445332be
13 files changed
+239 -30

No files matched your search

+29 -4
View File
@@ -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);