working base entities creation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Michele Scandura 2021-09-20 15:16:43 +01:00
parent 454c507b2f
commit 4fd77a1f17
22 changed files with 260 additions and 356 deletions

View File

@ -1,4 +1,5 @@
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper.Api.Commands
{
@ -6,7 +7,7 @@ namespace Sledgemapper.Api.Commands
{
public Line Line { get; private set; }
public NewLineCommand(string sessionName, Line line, string userId) : base(sessionName, userId)
public NewLineCommand(Guid campaign, Guid mapName, Line line, string userId) : base(campaign, mapName, userId)
{
Line = line;
}

View File

@ -1,4 +1,5 @@
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper.Api.Commands
{
@ -6,7 +7,7 @@ namespace Sledgemapper.Api.Commands
{
public Note Note { get; private set; }
public NewNoteCommand(string sessionName, Note note, string userId) : base(sessionName, userId)
public NewNoteCommand(Guid campaignId, Guid mapId, Note note, string userId) : base(campaignId, mapId, userId)
{
Note = note;
}

View File

@ -1,4 +1,5 @@
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper.Api.Commands
{
@ -6,7 +7,7 @@ namespace Sledgemapper.Api.Commands
{
public Room Room { get; private set; }
public NewRoomCommand(string sessionName, Room room, string userId) : base(sessionName, userId)
public NewRoomCommand(Guid campaignId, Guid mapId, Room room, string userId) : base(campaignId, mapId, userId)
{
Room = room;
}

View File

@ -1,4 +1,5 @@
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper.Api.Commands
{
@ -6,7 +7,7 @@ namespace Sledgemapper.Api.Commands
{
public Wall Wall { get; private set; }
public NewWallCommand(string sessionName, Wall wall, string userId) : base(sessionName, userId)
public NewWallCommand(Guid campaignId, Guid mapId, Wall wall, string userId) : base(campaignId, mapId, userId)
{
Wall = wall;
}

View File

@ -45,27 +45,27 @@ namespace Sledgemapper.Api.Controllers
}
[HttpPost("wall")]
public async Task Post(string campaign, string mapName, [FromBody] Wall wall)
public async Task Post(Guid campaign, Guid mapName, [FromBody] Wall wall)
{
await _mediator.Send(new NewWallCommand(mapName, wall, UserId));
await _mediator.Send(new NewWallCommand(campaign, mapName, wall, UserId));
}
[HttpPost("note")]
public async Task Post(string campaign, string mapName, [FromBody] Note note)
public async Task Post(Guid campaign, Guid mapName, [FromBody] Note note)
{
await _mediator.Send(new NewNoteCommand(mapName, note, UserId));
await _mediator.Send(new NewNoteCommand(campaign, mapName, note, UserId));
}
[HttpPost("room")]
public async Task Post(string campaign, string mapName, [FromBody] Room room)
public async Task Post(Guid campaign, Guid mapName, [FromBody] Room room)
{
await _mediator.Send(new NewRoomCommand(mapName, room, UserId));
await _mediator.Send(new NewRoomCommand(campaign, mapName, room, UserId));
}
[HttpPost("line")]
public async Task Post(string campaign, string mapName, [FromBody] Line line)
public async Task Post(Guid campaign, Guid mapName, [FromBody] Line line)
{
await _mediator.Send(new NewLineCommand(mapName, line, UserId));
await _mediator.Send(new NewLineCommand(campaign, mapName, line, UserId));
}
[HttpDelete("overlay")]

View File

@ -0,0 +1,68 @@
using MediatR;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System;
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Models;
namespace Sledgemapper.Api.Handlers
{
public abstract class BaseCommandHandler<TRequest, TResponse> : IRequestHandler<TRequest, TResponse> where TRequest : BaseCommand<TResponse>
{
protected SledgemapperDbContext Dbcontext { get; }
protected IMediator Mediator { get; }
public abstract Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
public BaseCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext)
{
Dbcontext = dbcontext;
Mediator = mediator;
}
protected async Task CheckAuthorization(TRequest command)
{
var user = await Dbcontext.Users.FindAsync(command.UserId);
Dbcontext.Attach(user);
var campaign = await Dbcontext
.Campaigns
.Where(campaign => campaign.CampaignId == command.Campaign)
.Include(c => c.InvitedUsers)
.Include(c => c.Maps)
.Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
var maps = campaign.Maps.Any(s => s.SessionId == command.SessionId);
if (!maps)
{
throw new Exception("Unauthorized");
}
}
protected async Task<Session> SaveLog(TRequest command, string operation, string type, string data, CancellationToken cancellationToken)
{
var session = Dbcontext.Sessions.First(m => m.SessionId == command.SessionId);
Dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = operation,
SessionId = session.SessionId,
Type = type,
Timestamp = command.Timestamp,
Object = data,
UserId = command.UserId,
});
await Dbcontext.SaveChangesAsync(cancellationToken);
return session;
}
}
}

View File

@ -2,41 +2,24 @@ using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class DeleteNoteCommandHandler : IRequestHandler<DeleteNoteCommand, bool>
public class DeleteNoteCommandHandler : BaseCommandHandler<DeleteNoteCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public DeleteNoteCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteNoteCommand notification, CancellationToken cancellationToken)
public DeleteNoteCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Note);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "D",
SessionId = session.SessionId,
Type = "N",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new DeleteNoteNotification(session, notification.Note, notification.UserId));
}
public override async Task<bool> Handle(DeleteNoteCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Note);
var session = await SaveLog(command, "D", "N", jsonString, cancellationToken);
await Mediator.Publish(new DeleteNoteNotification(session, command.Note, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,40 +1,25 @@
using MediatR;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Notifications;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class DeleteOverlayCommandHandler : IRequestHandler<DeleteOverlayCommand, bool>
public class DeleteOverlayCommandHandler : BaseCommandHandler<DeleteOverlayCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public DeleteOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteOverlayCommand notification, CancellationToken cancellationToken)
public DeleteOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Overlay);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
}
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "D",
SessionId = session.SessionId,
Type = "O",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId=notification.UserId
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new DeleteOverlayNotification(session, notification.Overlay, notification.UserId));
public override async Task<bool> Handle(DeleteOverlayCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Overlay);
var session = await SaveLog(command, "D", "O", jsonString, cancellationToken);
await Mediator.Publish(new DeleteOverlayNotification(session, command.Overlay, command.UserId), cancellationToken);
return true;
}
}

View File

@ -2,38 +2,24 @@ using MediatR;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class DeleteTileCommandHandler : IRequestHandler<DeleteTileCommand,bool>
public class DeleteTileCommandHandler : BaseCommandHandler<DeleteTileCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public DeleteTileCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteTileCommand notification, CancellationToken cancellationToken)
public DeleteTileCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Tile);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
}
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "D",
SessionId = session.SessionId,
Type = "T",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new DeleteTileNotification(session, notification.Tile, notification.UserId));
public override async Task<bool> Handle(DeleteTileCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Tile);
var session = await SaveLog(command, "D", "T", jsonString, cancellationToken);
await Mediator.Publish(new DeleteTileNotification(session, command.Tile, command.UserId), cancellationToken);
return true;
}
}

View File

@ -2,41 +2,24 @@ using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class DeleteWallCommandHandler : IRequestHandler<DeleteWallCommand, bool>
public class DeleteWallCommandHandler : BaseCommandHandler<DeleteWallCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public DeleteWallCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteWallCommand notification, CancellationToken cancellationToken)
public DeleteWallCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Wall);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "D",
SessionId = session.SessionId,
Type = "W",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new DeleteWallNotification(session, notification.Wall, notification.UserId));
}
public override async Task<bool> Handle(DeleteWallCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Wall);
var session = await SaveLog(command, "D", "W", jsonString, cancellationToken);
await Mediator.Publish(new DeleteWallNotification(session, command.Wall, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,8 +1,6 @@
using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -10,29 +8,18 @@ using Sledgemapper.Api.Notifications;
namespace Sledgemapper.Api.Handlers
{
public class NewLineCommandHandler : IRequestHandler<NewLineCommand, bool>
public class NewLineCommandHandler : BaseCommandHandler<NewLineCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public NewLineCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewLineCommand notification, CancellationToken cancellationToken)
public NewLineCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Line);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "L",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId,
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewLineNotification(session, notification.Line, notification.UserId));
}
public override async Task<bool> Handle(NewLineCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Line);
var session = await SaveLog(command, "N", "L", jsonString, cancellationToken);
await Mediator.Publish(new NewLineNotification(session, command.Line, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,38 +1,25 @@
using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class NewNoteCommandHandler : IRequestHandler<NewNoteCommand, bool>
public class NewNoteCommandHandler : BaseCommandHandler<NewNoteCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public NewNoteCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewNoteCommand notification, CancellationToken cancellationToken)
public NewNoteCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Note);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "N",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId,
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewNoteNotification(session, notification.Note, notification.UserId));
}
public override async Task<bool> Handle(NewNoteCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Note);
var session = await SaveLog(command, "N", "W", jsonString, cancellationToken);
await Mediator.Publish(new NewNoteNotification(session, command.Note, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,59 +1,26 @@
using MediatR;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using System.Linq;
using Sledgemapper.Api.Notifications;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System;
using Microsoft.EntityFrameworkCore;
namespace Sledgemapper.Api.Handlers
{
public class NewOverlayCommandHandler : IRequestHandler<NewOverlayCommand, bool>
public class NewOverlayCommandHandler : BaseCommandHandler<NewOverlayCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public NewOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewOverlayCommand command, CancellationToken cancellationToken)
public NewOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var user = await _dbcontext.Users.FindAsync(command.UserId);
_dbcontext.Attach(user);
var campaign = await _dbcontext
.Campaigns
.Where(campaign => campaign.CampaignId == command.Campaign)
.Include(c => c.InvitedUsers)
.Include(c => c.Maps)
.Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
var maps = campaign.Maps.Any(s => s.SessionId == command.SessionId);
if (!maps)
{
throw new Exception("Unauthorized");
}
}
public override async Task<bool> Handle(NewOverlayCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Overlay);
var session = _dbcontext.Sessions.First(m => m.SessionId == command.SessionId);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "O",
Timestamp = command.Timestamp,
Object = jsonString,
UserId = command.UserId,
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewOverlayNotification(session, command.Overlay, command.UserId));
var session = await SaveLog(command, "N", "O", jsonString, cancellationToken);
await Mediator.Publish(new NewOverlayNotification(session, command.Overlay, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,8 +1,6 @@
using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -10,29 +8,17 @@ using Sledgemapper.Api.Notifications;
namespace Sledgemapper.Api.Handlers
{
public class NewRoomCommandHandler : IRequestHandler<NewRoomCommand, bool>
public class NewRoomCommandHandler : BaseCommandHandler<NewRoomCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
public NewRoomCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{ }
private readonly IMediator _mediator;
public NewRoomCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewRoomCommand notification, CancellationToken cancellationToken)
public override async Task<bool> Handle(NewRoomCommand command, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize(notification.Room);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "R",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId,
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewRoomNotification(session, notification.Room, notification.UserId));
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Room);
var session = await SaveLog(command, "N", "R", jsonString, cancellationToken);
await Mediator.Publish(new NewRoomNotification(session, command.Room, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,38 +1,25 @@
using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Api.Notifications;
using System.Linq;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Handlers;
namespace Sledgemapper.Api.Commands
{
public class NewTileCommandHandler : IRequestHandler<NewTileCommand, bool>
public class NewTileCommandHandler : BaseCommandHandler<NewTileCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public NewTileCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewTileCommand notification, CancellationToken cancellationToken)
public NewTileCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Tile);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
}
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "T",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewTileNotification(session, notification.Tile, notification.UserId));
public override async Task<bool> Handle(NewTileCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Tile);
var session = await SaveLog(command, "N", "T", jsonString, cancellationToken);
await Mediator.Publish(new NewTileNotification(session, command.Tile, command.UserId), cancellationToken);
return true;
}
}

View File

@ -1,38 +1,25 @@
using MediatR;
using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class NewWallCommandHandler : IRequestHandler<NewWallCommand, bool>
public class NewWallCommandHandler : BaseCommandHandler<NewWallCommand, bool>
{
private readonly SledgemapperDbContext _dbcontext;
private readonly IMediator _mediator;
public NewWallCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(NewWallCommand notification, CancellationToken cancellationToken)
public NewWallCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
{
var jsonString = JsonSerializer.Serialize(notification.Wall);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "W",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId,
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewWallNotification(session, notification.Wall, notification.UserId));
}
public override async Task<bool> Handle(NewWallCommand command, CancellationToken cancellationToken)
{
await CheckAuthorization(command);
var jsonString = JsonSerializer.Serialize(command.Wall);
var session = await SaveLog(command, "N", "W", jsonString, cancellationToken);
await Mediator.Publish(new NewWallNotification(session, command.Wall, command.UserId), cancellationToken);
return true;
}
}

View File

@ -198,22 +198,22 @@ namespace Sledgemapper
switch (entity)
{
case Tile tile:
Queue.Enqueue(async () => await Execute(async () => await Api.NewTile(tile, State.Instance.MapId).ConfigureAwait(false)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewTile(tile, State.Instance.CampaignId, State.Instance.MapId).ConfigureAwait(false)));
break;
case Overlay overlay:
Queue.Enqueue(async () => await Execute(async () => await Api.NewOverlay(overlay,State.Instance.CampaignId, State.Instance.MapId).ConfigureAwait(false)));
break;
case Wall wall:
Queue.Enqueue(async () => await Execute(async () => await Api.NewWall(wall, State.Instance.MapId).ConfigureAwait(false)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewWall(wall, State.Instance.CampaignId, State.Instance.MapId).ConfigureAwait(false)));
break;
case Note note:
Queue.Enqueue(async () => await Execute(async () => await Api.NewNote(note, State.Instance.MapId).ConfigureAwait(false)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewNote(note, State.Instance.CampaignId, State.Instance.MapId).ConfigureAwait(false)));
break;
case Room room:
Queue.Enqueue(async () => await Execute(async () => await Api.NewRoom(room, State.Instance.MapId).ConfigureAwait(false)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewRoom(room, State.Instance.CampaignId, State.Instance.MapId).ConfigureAwait(false)));
break;
case Line line:
Queue.Enqueue(async () => await Execute(async () => await Api.NewLine(line, State.Instance.MapId).ConfigureAwait(false)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewLine(line, State.Instance.CampaignId, State.Instance.MapId).ConfigureAwait(false)));
break;
}
break;

View File

@ -9,6 +9,51 @@ namespace Sledgemapper
[Headers("Authorization: Bearer")]
public interface IMapApi
{
[Headers("Authorization")]
[Post("/authmanagement/register")]
Task<AuthResult> Register([Body] RegisterModel registerModel);
[Headers("Authorization")]
[Post("/authmanagement/login")]
Task<AuthenticateResponse> Authenticate([Body] AuthenticateModel registerModel);
[Post("/map/{campaignId}/{mapId}/overlay")]
Task NewOverlay([Body] Overlay overlay, Guid campaignId, Guid mapId);
[Post("/map/{campaignId}/{mapId}/note")]
Task NewNote([Body] Note note, Guid campaignId, Guid mapId);
[Post("/map/{campaignId}/{mapId}/wall")]
Task NewWall([Body] Wall overlay, Guid campaignId, Guid mapId);
[Post("/map/{campaignId}/{mapId}/room")]
Task NewRoom(Room room, Guid campaignId, Guid mapId);
[Post("/map/{campaignId}/{mapId}/line")]
Task NewLine(Line line, Guid campaignId, Guid mapId);
[Post("/campaign/{campaignName}")]
Task NewCampaign(string campaignName);
[Get("/campaign/")]
Task<List<Campaign>> GetCampaigns();
[Get("/campaign/{campaignName}/players")]
Task<List<Player>> GetPlayers(string campaignName);
[Get("/campaign/{campaignName}/maps")]
Task<List<Session>> GetMaps(Guid campaignName);
[Get("/map/{campaignName}/{mapName}")]
Task<Session> GetMap(Guid campaignName, Guid mapName);
[Post("/campaign/{campaignName}/players/{email}")]
Task InvitePlayer(string campaignName, string email);
[Get("/session/{sessionName}")]
Task<Session> Session(string sessionName);
@ -18,17 +63,12 @@ namespace Sledgemapper
[Post("/session/{sessionName}/snapshot")]
Task SaveSnapshot([Body] Session session, Guid sessionName);
[Post("/session/{sessionName}/tile")]
Task NewTile([Body] Tile tile, Guid sessionName);
[Post("/map/{campaignId}/{mapId}/tile")]
Task NewTile([Body] Tile tile, Guid campaignId, Guid mapId);
[Post("/map/{campaignId}/{mapId}/overlay")]
Task NewOverlay([Body] Overlay overlay, Guid campaignId, Guid mapId);
[Post("/session/{sessionName}/note")]
Task NewNote([Body] Note note, Guid sessionName);
[Post("/session/{sessionName}/wall")]
Task NewWall([Body] Wall overlay, Guid sessionName);
[Delete("/session/{sessionName}/wall")]
Task DeleteWall([Body] Wall wall, Guid sessionName);
@ -50,38 +90,9 @@ namespace Sledgemapper
public List<string> Errors { get; set; }
}
[Headers("Authorization")]
[Post("/authmanagement/register")]
Task<AuthResult> Register([Body] RegisterModel registerModel);
[Headers("Authorization")]
[Post("/authmanagement/login")]
Task<AuthenticateResponse> Authenticate([Body] AuthenticateModel registerModel);
[Post("/session/{sessionName}/room")]
Task NewRoom(Room room, Guid sessionName);
[Post("/session/{sessionName}/line")]
Task NewLine(Line line, Guid sessionName);
[Post("/campaign/{campaignName}")]
Task NewCampaign(string campaignName);
[Get("/campaign/")]
Task<List<Campaign>> GetCampaigns();
[Get("/campaign/{campaignName}/players")]
Task<List<Player>> GetPlayers(string campaignName);
[Get("/campaign/{campaignName}/maps")]
Task<List<Session>> GetMaps(Guid campaignName);
[Get("/map/{campaignName}/{mapName}")]
Task<Session> GetMap(Guid campaignName, Guid mapName);
[Post("/campaign/{campaignName}/players/{email}")]
Task InvitePlayer(string campaignName, string email);
}
}

View File

@ -9,7 +9,10 @@ namespace Sledgemapper
{
using(Sentry.SentrySdk.Init("https://973ac1606651454ba7a19f642d0a9bc1@glitchtip.michelescandura.com/1"))
using (var game = new Sledgemapper())
{
Sentry.SentrySdk.CaptureEvent(new Sentry.SentryEvent() { Message = "App starting" });
game.Run();
}
}
}
}

View File

@ -50,8 +50,8 @@ namespace Sledgemapper.UI
MenuMapOpen.Selected += OnMenuMapOpen;
MenuMapNew.Selected += OnMenuMapNew;
MenuConnectNew.Enabled = false;
MenuConnectJoin.Enabled = false;
//MenuConnectNew.Enabled = false;
//MenuConnectJoin.Enabled = false;
MenuConnectSync.Enabled = false;
MenuConnectUpload.Enabled = false;
MenuCampaignOpen.Enabled = false;
@ -119,8 +119,8 @@ namespace Sledgemapper.UI
private void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
{
MenuConnectNew.Enabled = true;
MenuConnectJoin.Enabled = true;
//MenuConnectNew.Enabled = true;
//MenuConnectJoin.Enabled = true;
MenuCampaignOpen.Enabled = true;
MenuCampaingNew.Enabled = true;

View File

@ -1,4 +1,4 @@
/* Generated by MyraPad at 16/09/2021 14:53:34 */
/* Generated by MyraPad at 20/09/2021 14:15:54 */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
@ -61,36 +61,9 @@ namespace Sledgemapper.UI
MenuConnectLogin.ShortcutText = "Ctrl+O";
MenuConnectLogin.Id = "MenuConnectLogin";
var menuSeparator3 = new MenuSeparator();
MenuConnectNew = new MenuItem();
MenuConnectNew.Text = "&New";
MenuConnectNew.ShortcutText = "Ctrl+N";
MenuConnectNew.Id = "MenuConnectNew";
MenuConnectJoin = new MenuItem();
MenuConnectJoin.Text = "&Join";
MenuConnectJoin.ShortcutText = "Ctrl+J";
MenuConnectJoin.Id = "MenuConnectJoin";
MenuConnectSync = new MenuItem();
MenuConnectSync.Text = "S&ync";
MenuConnectSync.ShortcutText = "Ctrl+Y";
MenuConnectSync.Id = "MenuConnectSync";
MenuConnectUpload = new MenuItem();
MenuConnectUpload.Text = "&Upload";
MenuConnectUpload.ShortcutText = "Ctrl+U";
MenuConnectUpload.Id = "MenuConnectUpload";
var menuItem1 = new MenuItem();
menuItem1.Text = "&Connect";
menuItem1.Items.Add(MenuConnectLogin);
menuItem1.Items.Add(menuSeparator3);
menuItem1.Items.Add(MenuConnectNew);
menuItem1.Items.Add(MenuConnectJoin);
menuItem1.Items.Add(MenuConnectSync);
menuItem1.Items.Add(MenuConnectUpload);
MenuCampaingNew = new MenuItem();
MenuCampaingNew.Text = "&New";
@ -102,7 +75,7 @@ namespace Sledgemapper.UI
MenuCampaignOpen.ShortcutText = "Ctrl+O";
MenuCampaignOpen.Id = "MenuCampaignOpen";
var menuSeparator4 = new MenuSeparator();
var menuSeparator3 = new MenuSeparator();
MenuCampaignPlayers = new MenuItem();
MenuCampaignPlayers.Text = "&Players";
@ -113,7 +86,7 @@ namespace Sledgemapper.UI
menuItem2.Text = "C&ampaign";
menuItem2.Items.Add(MenuCampaingNew);
menuItem2.Items.Add(MenuCampaignOpen);
menuItem2.Items.Add(menuSeparator4);
menuItem2.Items.Add(menuSeparator3);
menuItem2.Items.Add(MenuCampaignPlayers);
MenuMapNew = new MenuItem();
@ -126,11 +99,23 @@ namespace Sledgemapper.UI
MenuMapOpen.ShortcutText = "Ctrl+O";
MenuMapOpen.Id = "MenuMapOpen";
MenuConnectSync = new MenuItem();
MenuConnectSync.Text = "S&ync";
MenuConnectSync.ShortcutText = "Ctrl+Y";
MenuConnectSync.Id = "MenuConnectSync";
MenuConnectUpload = new MenuItem();
MenuConnectUpload.Text = "&Upload";
MenuConnectUpload.ShortcutText = "Ctrl+U";
MenuConnectUpload.Id = "MenuConnectUpload";
var menuItem3 = new MenuItem();
menuItem3.Text = "&Map";
menuItem3.ShortcutText = "Ctrl+M";
menuItem3.Items.Add(MenuMapNew);
menuItem3.Items.Add(MenuMapOpen);
menuItem3.Items.Add(MenuConnectSync);
menuItem3.Items.Add(MenuConnectUpload);
MenuViewShowNotes = new MenuItem();
MenuViewShowNotes.Text = "N&otes";
@ -357,15 +342,13 @@ namespace Sledgemapper.UI
public MenuItem MenuFileQuit;
public MenuItem MenuFile;
public MenuItem MenuConnectLogin;
public MenuItem MenuConnectNew;
public MenuItem MenuConnectJoin;
public MenuItem MenuConnectSync;
public MenuItem MenuConnectUpload;
public MenuItem MenuCampaingNew;
public MenuItem MenuCampaignOpen;
public MenuItem MenuCampaignPlayers;
public MenuItem MenuMapNew;
public MenuItem MenuMapOpen;
public MenuItem MenuConnectSync;
public MenuItem MenuConnectUpload;
public MenuItem MenuViewShowNotes;
public MenuItem MenuViewShowCellNUmbers;
public MenuItem MenuViewCenterOnSelection;

View File

@ -17,11 +17,6 @@
</MenuItem>
<MenuItem Text="&amp;Connect">
<MenuItem Text="L&amp;ogin" ShortcutText="Ctrl+O" Id="MenuConnectLogin" />
<MenuSeparator />
<MenuItem Text="&amp;New" ShortcutText="Ctrl+N" Id="MenuConnectNew" />
<MenuItem Text="&amp;Join" ShortcutText="Ctrl+J" Id="MenuConnectJoin" />
<MenuItem Text="S&amp;ync" ShortcutText="Ctrl+Y" Id="MenuConnectSync" />
<MenuItem Text="&amp;Upload" ShortcutText="Ctrl+U" Id="MenuConnectUpload" />
</MenuItem>
<MenuItem Text="C&amp;ampaign">
<MenuItem Text="&amp;New" ShortcutText="Ctrl+N" Id="MenuCampaingNew" />
@ -32,6 +27,8 @@
<MenuItem Text="&amp;Map" ShortcutText="Ctrl+M">
<MenuItem Text="&amp;New" ShortcutText="Ctrl+N" Id="MenuMapNew" />
<MenuItem Text="&amp;Open" ShortcutText="Ctrl+O" Id="MenuMapOpen" />
<MenuItem Text="S&amp;ync" ShortcutText="Ctrl+Y" Id="MenuConnectSync" />
<MenuItem Text="&amp;Upload" ShortcutText="Ctrl+U" Id="MenuConnectUpload" />
</MenuItem>
<MenuItem Text="&amp;View">
<MenuItem Text="N&amp;otes" ShortcutText="Ctrl+O" Id="MenuViewShowNotes" />