ping on map feature complete
This commit is contained in:
parent
17cce56866
commit
bce97de302
19 changed files with 1002 additions and 233 deletions
13
Sledgemapper.Api/Commands/PingCommand.cs
Normal file
13
Sledgemapper.Api/Commands/PingCommand.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// using Sledgemapper.Shared.Entities;
|
||||
|
||||
// namespace Sledgemapper.Api.Commands
|
||||
// {
|
||||
// public class PingCommand : BaseCommand<bool>
|
||||
// {
|
||||
// public Ping Location { get; private set; }
|
||||
// public PingCommand(string sessionName, Ping location, int userId) : base(sessionName, userId)
|
||||
// {
|
||||
// Location = location;
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -2,6 +2,7 @@ using MediatR;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Notifications;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -30,6 +31,12 @@ namespace Sledgemapper.Api.Controllers
|
|||
return result;
|
||||
}
|
||||
|
||||
// [HttpPost("ping")]
|
||||
// public async Task Post(string sessionName, [FromBody] Ping pingLocation)
|
||||
// {
|
||||
// await _mediator.Send(new PingCommand(sessionName, pingLocation, UserId));
|
||||
// }
|
||||
|
||||
[HttpPost("snapshot")]
|
||||
public async Task Post(string sessionName, [FromBody] Session session)
|
||||
{
|
||||
|
@ -60,13 +67,13 @@ namespace Sledgemapper.Api.Controllers
|
|||
await _mediator.Send(new NewNoteCommand(sessionName, note, UserId));
|
||||
}
|
||||
|
||||
[HttpPost("room")]
|
||||
[HttpPost("room")]
|
||||
public async Task Post(string sessionName, [FromBody] Room room)
|
||||
{
|
||||
await _mediator.Send(new NewRoomCommand(sessionName, room, UserId));
|
||||
}
|
||||
|
||||
[HttpPost("line")]
|
||||
[HttpPost("line")]
|
||||
public async Task Post(string sessionName, [FromBody] Line line)
|
||||
{
|
||||
await _mediator.Send(new NewLineCommand(sessionName, line, UserId));
|
||||
|
|
|
@ -35,7 +35,5 @@ namespace Sledgemapper.Api.Commands
|
|||
await _mediator.Publish(new NewTileNotification(session, notification.Tile, notification.UserId));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
28
Sledgemapper.Api/Handlers/PingCommandHandler.cs
Normal file
28
Sledgemapper.Api/Handlers/PingCommandHandler.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
// using MediatR;
|
||||
// using Sledgemapper.Api.Data;
|
||||
// using System.Threading;
|
||||
// using System.Threading.Tasks;
|
||||
// using Sledgemapper.Api.Notifications;
|
||||
// using System.Linq;
|
||||
|
||||
// namespace Sledgemapper.Api.Commands
|
||||
// {
|
||||
// public class PingCommandHandler : IRequestHandler<PingCommand, bool>
|
||||
// {
|
||||
// private readonly MyDbContext _dbcontext;
|
||||
// private readonly IMediator _mediator;
|
||||
|
||||
// public PingCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
// public async Task<bool> Handle(PingCommand notification, CancellationToken cancellationToken)
|
||||
// {
|
||||
// var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
|
||||
|
||||
// await _mediator.Publish(new PingNotification(session, notification.Location, notification.UserId));
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
// }
|
23
Sledgemapper.Api/Handlers/SendPingMessage.cs
Normal file
23
Sledgemapper.Api/Handlers/SendPingMessage.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// using MediatR;
|
||||
// using Microsoft.AspNetCore.SignalR;
|
||||
// using Sledgemapper.Api.Notifications;
|
||||
// using Sledgemapper.Clients;
|
||||
// using System.Threading;
|
||||
// using System.Threading.Tasks;
|
||||
// using Sledgemapper.Api.Hubs;
|
||||
|
||||
// namespace Sledgemapper.Api.Handlers
|
||||
// {
|
||||
// public class SendPingMessage : INotificationHandler<PingNotification>
|
||||
// {
|
||||
// private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||
|
||||
// public SendPingMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||
|
||||
// public async Task Handle(PingNotification notification, CancellationToken cancellationToken)
|
||||
// {
|
||||
|
||||
// await _hub.Clients.Groups(notification.Session.SessionName).Ping(notification.Location, notification.UserId);
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -51,7 +51,7 @@ namespace Sledgemapper.Api.Hubs
|
|||
await Clients.Group(sessionName).NewRoom(room);
|
||||
}
|
||||
|
||||
public async Task NewLine(string sessionName, Line line)
|
||||
public async Task NewLine(string sessionName, Line line)
|
||||
{
|
||||
await Clients.Group(sessionName).NewLine(line);
|
||||
}
|
||||
|
@ -86,6 +86,15 @@ namespace Sledgemapper.Api.Hubs
|
|||
await Clients.Group(sessionName).DeleteOverlay(tile);
|
||||
}
|
||||
|
||||
public async Task Ping(string sessionName, Tile location)
|
||||
{
|
||||
var userId = int.Parse(Context.User.Identity.Name);
|
||||
var user = _datacontext.Users.First(u => u.Id == userId);
|
||||
|
||||
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] };
|
||||
await Clients.Group(sessionName).Ping(new Ping{X=location.X, Y=location.Y, Player=player});
|
||||
}
|
||||
|
||||
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName)
|
||||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(s => s.SessionName == sessionName);
|
||||
|
|
14
Sledgemapper.Api/Notifications/PingNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/PingNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// using Sledgemapper.Shared.Entities;
|
||||
|
||||
// namespace Sledgemapper.Api.Notifications
|
||||
// {
|
||||
// public class PingNotification : BaseNotification
|
||||
// {
|
||||
// public Ping Location { get; private set; }
|
||||
|
||||
// public PingNotification(Models.Session session, Ping location, int userId) : base(session, userId)
|
||||
// {
|
||||
// Location = location;
|
||||
// }
|
||||
// }
|
||||
// }
|
Loading…
Add table
Add a link
Reference in a new issue