bug fixes
This commit is contained in:
parent
2a796509c8
commit
1759f7cd8e
12 changed files with 151 additions and 48 deletions
14
Sledgemapper.Api/Commands/DeleteNoteCommand.cs
Normal file
14
Sledgemapper.Api/Commands/DeleteNoteCommand.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using Sledgemapper.Shared.Entities;
|
||||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public class DeleteNoteCommand : BaseCommand<bool>
|
||||
{
|
||||
public Note Note { get; private set; }
|
||||
|
||||
public DeleteNoteCommand(string sessionName, Note note, int userId) : base(sessionName, userId)
|
||||
{
|
||||
Note = note;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace Sledgemapper.Api.Controllers
|
|||
{
|
||||
private readonly IMediator _mediator;
|
||||
private int UserId => int.Parse(HttpContext.User.Identity.Name);
|
||||
|
||||
|
||||
public SessionController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
[HttpPost]
|
||||
|
@ -77,5 +77,11 @@ namespace Sledgemapper.Api.Controllers
|
|||
{
|
||||
await _mediator.Send(new DeleteWallCommand(sessionName, wall, UserId));
|
||||
}
|
||||
|
||||
[HttpDelete("note")]
|
||||
public async Task Delete(string sessionName, [FromBody] Note note)
|
||||
{
|
||||
await _mediator.Send(new DeleteNoteCommand(sessionName, note, UserId));
|
||||
}
|
||||
}
|
||||
}
|
43
Sledgemapper.Api/Handlers/DeleteNoteCommandHandler.cs
Normal file
43
Sledgemapper.Api/Handlers/DeleteNoteCommandHandler.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using MediatR;
|
||||
using Sledgemapper.Api.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>
|
||||
{
|
||||
private readonly MyDbContext _dbcontext;
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public DeleteNoteCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
|
||||
public async Task<bool> Handle(DeleteNoteCommand notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var jsonString = JsonSerializer.Serialize<Note>(notification.Note);
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
|
||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.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));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,6 +53,10 @@ namespace Sledgemapper.Api.Commands
|
|||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
mapSession.NewOverlay(overlay, overlay.ID);
|
||||
break;
|
||||
case "N":
|
||||
var note = JsonSerializer.Deserialize<Note>(mapUpdate.Object);
|
||||
mapSession.NewNote(note);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
@ -73,6 +77,10 @@ namespace Sledgemapper.Api.Commands
|
|||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
mapSession.DeleteOverlay(overlay);
|
||||
break;
|
||||
case "N":
|
||||
var note = JsonSerializer.Deserialize<Note>(mapUpdate.Object);
|
||||
mapSession.DeleteNote(note);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
Sledgemapper.Api/Handlers/SendDeleteNoteMessage.cs
Normal file
22
Sledgemapper.Api/Handlers/SendDeleteNoteMessage.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Sledgemapper.Clients;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Sledgemapper.Api.Hubs;
|
||||
using Sledgemapper.Api.Notifications;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class SendDeleteNoteMessage : INotificationHandler<DeleteNoteNotification>
|
||||
{
|
||||
private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||
|
||||
public SendDeleteNoteMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||
|
||||
public async Task Handle(DeleteNoteNotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
await _hub.Clients.Groups(notification.Session.SessionName).DeleteNote(notification.Note);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -142,7 +142,8 @@ namespace Sledgemapper.Api.Hubs
|
|||
foreach (var userSession in userSessions)
|
||||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionId == userSession.SessionId);
|
||||
await Clients.Group(session.SessionName).PlayerUpdate(null); //send remove player
|
||||
|
||||
await Clients.Group(session.SessionName).RemovePlayer(new Player{UserId=userId}); //send remove player
|
||||
_dbContext.SessionUsers.Remove(userSession);
|
||||
}
|
||||
}
|
||||
|
|
14
Sledgemapper.Api/Notifications/DeleteNoteNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/DeleteNoteNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using Sledgemapper.Shared.Entities;
|
||||
|
||||
namespace Sledgemapper.Api.Notifications
|
||||
{
|
||||
public class DeleteNoteNotification : BaseNotification
|
||||
{
|
||||
public Note Note { get; private set; }
|
||||
|
||||
public DeleteNoteNotification(Models.Session session, Note note, int userId) : base(session, userId)
|
||||
{
|
||||
Note = note;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue