diff --git a/Assets/Src/LapService.cs b/Assets/Src/LapService.cs index 81ed3d6..b708d8f 100644 --- a/Assets/Src/LapService.cs +++ b/Assets/Src/LapService.cs @@ -21,6 +21,7 @@ public class LapService { string _mapName; PlayerData _player; PbDTO _pb; + PbDTO _lr; public Lap PB; @@ -50,13 +51,14 @@ public class LapService { } } - PbDTO SetPb(string json) { - PbDTO dto = JsonConvert.DeserializeObject(json); - _pb = dto; + LapTimesDTO SetPb(string json) { + LapTimesDTO dto = JsonConvert.DeserializeObject(json); + _pb = dto.Pb; + _lr = dto.LapRecord; PB = new Lap { Map = _pb.Map, - Sectors = dto.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), + Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), }; return dto; diff --git a/Server/Controllers/PbController.cs b/Server/Controllers/PbController.cs index 9390223..27dafab 100644 --- a/Server/Controllers/PbController.cs +++ b/Server/Controllers/PbController.cs @@ -17,12 +17,22 @@ public class PbController : ControllerBase { } [HttpGet()] - public PbDTO Pb(Guid userId, string mapName) { + public LapTimesDTO Pb(Guid userId, string mapName) { _logger.LogInformation($"{userId} {mapName}"); - return _db.PbDTO + PbDTO pb = _db.PbDTO .Where(pb => pb.UserId == userId) .Where(pb => pb.Map == mapName) - .Single(); + .SingleOrDefault(); + + PbDTO lapRecord = _db.PbDTO + .Where(pb => pb.Map == mapName) + .OrderBy(pb => pb.Position) + .FirstOrDefault(); + + return new LapTimesDTO { + Pb = pb, + LapRecord = lapRecord, + }; } } diff --git a/Server/Models/SpaceRaceShared.cs b/Server/Models/SpaceRaceShared.cs index 4ad9432..d34a7b4 100644 --- a/Server/Models/SpaceRaceShared.cs +++ b/Server/Models/SpaceRaceShared.cs @@ -22,4 +22,9 @@ namespace SpaceRace.Shared { public int Completions { get; set; } public int Position { get; set; } } + + public class LapTimesDTO { + public PbDTO Pb { get; set; } + public PbDTO LapRecord { get; set; } + } }