fixes and cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-21 11:09:26 +01:00
parent 17d6cd28d6
commit 7e3e645fc9
48 changed files with 1530 additions and 1538 deletions

View file

@ -6,31 +6,32 @@ using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using Sledgemapper.Api.Models;
using Sledgemapper.Api.Commands;
namespace Sledgemapper.Api.Commands
namespace Sledgemapper.Api.Handlers
{
public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Shared.Entities.Session>
public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Session>
{
private readonly SledgemapperDbContext _dbcontext;
public GetMapSnapshotCommandHandler(SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; }
public async Task<Shared.Entities.Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken)
public async Task<Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken)
{
Snapshot snapshot;
double timestamp;
Shared.Entities.Session mapSession;
Session mapSession;
var session = _dbcontext.Sessions.First(m => m.SessionId == notification.MapId);
snapshot = _dbcontext.Snapshots.OrderByDescending(s => s.Timestamp).FirstOrDefault(m => m.SessionId == session.SessionId);
if (snapshot is null)
{
timestamp = 0;
mapSession = new Shared.Entities.Session();
mapSession = new Session();
}
else
{
mapSession = JsonSerializer.Deserialize<Shared.Entities.Session>(snapshot.Object);
mapSession = JsonSerializer.Deserialize<Session>(snapshot.Object);
timestamp = snapshot.Timestamp;
}
@ -57,7 +58,7 @@ namespace Sledgemapper.Api.Commands
var note = JsonSerializer.Deserialize<Note>(mapUpdate.Object);
mapSession.NewNote(note);
break;
case "L":
case "L":
var line = JsonSerializer.Deserialize<Line>(mapUpdate.Object);
mapSession.NewLine(line);
break;
@ -65,9 +66,9 @@ namespace Sledgemapper.Api.Commands
var room = JsonSerializer.Deserialize<Room>(mapUpdate.Object);
mapSession.NewRoom(room);
break;
}