sledgemapper/Sledgemapper.Api/Controllers/SessionController.cs

106 lines
No EOL
3.5 KiB
C#

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;
namespace Sledgemapper.Api.Controllers
{
[Authorize]
[Route("[controller]/{sessionName}")]
public class SessionController : ControllerBase
{
private readonly IMediator _mediator;
private int UserId => int.Parse(HttpContext.User.Identity.Name);
public SessionController(IMediator mediator) => _mediator = mediator;
[HttpPost]
public async Task<bool> Post(string sessionName)
{
var result = await _mediator.Send(new NewSessionCommand(sessionName, UserId));
return result;
}
[HttpGet]
public async Task<Session> Get(string sessionName)
{
var result = await _mediator.Send(new GetMapSnapshotCommand(sessionName));
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)
{
await _mediator.Send(new NewSnapshotCommand(sessionName, session, UserId));
}
[HttpPost("tile")]
public async Task Post(string sessionName, [FromBody] Tile tile)
{
await _mediator.Send(new NewTileCommand(sessionName, tile, UserId));
}
[HttpPost("overlay")]
public async Task Post(string sessionName, [FromBody] Overlay overlay)
{
await _mediator.Send(new NewOverlayCommand(sessionName, overlay, UserId));
}
[HttpPost("wall")]
public async Task Post(string sessionName, [FromBody] Wall wall)
{
await _mediator.Send(new NewWallCommand(sessionName, wall, UserId));
}
[HttpPost("note")]
public async Task Post(string sessionName, [FromBody] Note note)
{
await _mediator.Send(new NewNoteCommand(sessionName, note, UserId));
}
[HttpPost("room")]
public async Task Post(string sessionName, [FromBody] Room room)
{
await _mediator.Send(new NewRoomCommand(sessionName, room, UserId));
}
[HttpPost("line")]
public async Task Post(string sessionName, [FromBody] Line line)
{
await _mediator.Send(new NewLineCommand(sessionName, line, UserId));
}
[HttpDelete("tile")]
public async Task Delete(string sessionName, [FromBody] Tile tile)
{
await _mediator.Send(new DeleteTileCommand(sessionName, tile, UserId));
}
[HttpDelete("overlay")]
public async Task Delete(string sessionName, [FromBody] Overlay overlay)
{
await _mediator.Send(new DeleteOverlayCommand(sessionName, overlay, UserId));
}
[HttpDelete("wall")]
public async Task Delete(string sessionName, [FromBody] Wall wall)
{
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));
}
}
}