cleanup, refactoring, usual stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-16 11:11:07 +01:00
parent b671c661a7
commit f15f1c8857
26 changed files with 183 additions and 209 deletions

View file

@ -9,17 +9,17 @@ using Sledgemapper.Api.Models;
namespace Sledgemapper.Api.Commands
{
public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Sledgemapper.Shared.Entities.Session>
public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Shared.Entities.Session>
{
private readonly SledgemapperDbContext _dbcontext;
public GetMapSnapshotCommandHandler(SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; }
public async Task<Sledgemapper.Shared.Entities.Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken)
public async Task<Shared.Entities.Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken)
{
Snapshot snapshot;
double timestamp;
Sledgemapper.Shared.Entities.Session mapSession;
Shared.Entities.Session mapSession;
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
snapshot = _dbcontext.Snapshots.OrderByDescending(s => s.Timestamp).FirstOrDefault(m => m.SessionId == session.SessionId);
if (snapshot is null)
@ -30,7 +30,7 @@ namespace Sledgemapper.Api.Commands
}
else
{
mapSession = JsonSerializer.Deserialize<Sledgemapper.Shared.Entities.Session>(snapshot.Object);
mapSession = JsonSerializer.Deserialize<Shared.Entities.Session>(snapshot.Object);
timestamp = snapshot.Timestamp;
}
@ -101,7 +101,7 @@ namespace Sledgemapper.Api.Commands
{
SessionId = session.SessionId,
Timestamp = mapUpdates.Max(mapSession => mapSession.Timestamp),
Object = JsonSerializer.Serialize<Sledgemapper.Shared.Entities.Session>(mapSession)
Object = JsonSerializer.Serialize(mapSession)
};
await _dbcontext.Snapshots.AddAsync(newSnapshot);
await _dbcontext.SaveChangesAsync();