87 lines
No EOL
2.7 KiB
C#
87 lines
No EOL
2.7 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]/{mapName}")]
|
|
public class MapController : ControllerBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
private int UserId => int.Parse(HttpContext.User.Identity.Name);
|
|
|
|
public MapController(IMediator mediator) => _mediator = mediator;
|
|
|
|
[HttpPost]
|
|
public async Task<bool> Post(string mapName)
|
|
{
|
|
var result = await _mediator.Send(new NewSessionCommand(mapName, UserId));
|
|
return result;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<Session> Get(string mapName)
|
|
{
|
|
var result = await _mediator.Send(new GetMapSnapshotCommand(mapName));
|
|
return result;
|
|
}
|
|
|
|
[HttpPost("snapshot")]
|
|
public async Task Post(string mapName, [FromBody] Session session)
|
|
{
|
|
await _mediator.Send(new NewSnapshotCommand(mapName, session, UserId));
|
|
}
|
|
|
|
[HttpPost("overlay")]
|
|
public async Task Post(string mapName, [FromBody] Overlay overlay)
|
|
{
|
|
await _mediator.Send(new NewOverlayCommand(mapName, overlay, UserId));
|
|
}
|
|
|
|
[HttpPost("wall")]
|
|
public async Task Post(string mapName, [FromBody] Wall wall)
|
|
{
|
|
await _mediator.Send(new NewWallCommand(mapName, wall, UserId));
|
|
}
|
|
|
|
[HttpPost("note")]
|
|
public async Task Post(string mapName, [FromBody] Note note)
|
|
{
|
|
await _mediator.Send(new NewNoteCommand(mapName, note, UserId));
|
|
}
|
|
|
|
[HttpPost("room")]
|
|
public async Task Post(string mapName, [FromBody] Room room)
|
|
{
|
|
await _mediator.Send(new NewRoomCommand(mapName, room, UserId));
|
|
}
|
|
|
|
[HttpPost("line")]
|
|
public async Task Post(string mapName, [FromBody] Line line)
|
|
{
|
|
await _mediator.Send(new NewLineCommand(mapName, line, UserId));
|
|
}
|
|
|
|
[HttpDelete("overlay")]
|
|
public async Task Delete(string mapName, [FromBody] Overlay overlay)
|
|
{
|
|
await _mediator.Send(new DeleteOverlayCommand(mapName, overlay, UserId));
|
|
}
|
|
|
|
[HttpDelete("wall")]
|
|
public async Task Delete(string mapName, [FromBody] Wall wall)
|
|
{
|
|
await _mediator.Send(new DeleteWallCommand(mapName, wall, UserId));
|
|
}
|
|
|
|
[HttpDelete("note")]
|
|
public async Task Delete(string mapName, [FromBody] Note note)
|
|
{
|
|
await _mediator.Send(new DeleteNoteCommand(mapName, note, UserId));
|
|
}
|
|
}
|
|
} |