sledgemapper/Sledgemapper.Api/Controllers/SessionController.cs
Michele Scandura 77832db39d more cleanup
2020-11-18 11:22:46 +00:00

85 lines
No EOL
2.9 KiB
C#

using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Sledgemapper.Api.Commands;
using Sledgemapper.Shared.Entities;
using System.Threading.Tasks;
namespace Sledgemapper.Api.Controllers
{
[Authorize]
[Route("[controller]/{sessionName}")]
public class SessionController : ControllerBase
{
private readonly IMediator _mediator;
public SessionController(IMediator mediator) { _mediator = mediator; }
[HttpPost]
public async Task<bool> Post(string sessionName)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
var result = await _mediator.Send(new NewSessionCommand(sessionName, userId));
return result;
}
[HttpGet]
public async Task<Session> Get(string sessionName)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
var result = await _mediator.Send(new GetMapSnapshotCommand(sessionName));
return result;
}
[HttpPost("snapshot")]
public async Task Post(string sessionName, [FromBody] Session session)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Send(new NewSnapshotCommand(sessionName, session, userId));
}
[HttpPost("tile")]
public async Task Post(string sessionName, [FromBody] Tile tile)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Send(new NewTileCommand(sessionName, tile, userId));
}
[HttpPost("overlay")]
public async Task Post(string sessionName, [FromBody] Overlay overlay)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new NewOverlayCommand(sessionName, overlay, userId));
}
[HttpPost("wall")]
public async Task Post(string sessionName, [FromBody] Wall wall)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new NewWallCommand(sessionName, wall, userId));
}
[HttpDelete("tile")]
public async Task Delete(string sessionName, [FromBody] Tile tile)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new DeleteTileCommand(sessionName, tile, userId));
}
[HttpDelete("overlay")]
public async Task Delete(string sessionName, [FromBody] Overlay overlay)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new DeleteOverlayCommand(sessionName, overlay, userId));
}
[HttpDelete("wall")]
public async Task Delete(string sessionName, [FromBody] Wall wall)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new DeleteWallCommand(sessionName, wall, userId));
}
}
}