using IM.ASPNETCore; using MessageService.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; namespace MessageService.WebApi.Controllers.Message { [Route("api/[controller]/[action]")] [Authorize] [ApiController] public class MessageController : ControllerBase { private readonly Application.Message.MessageService service; public MessageController(Application.Message.MessageService service) { this.service = service; } [HttpPost] [UnitOfWork(typeof(MessageDbContext))] public async Task Send(MessageSendRequest request) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var command = request.ToCommand(Guid.Parse(userId)); return Ok(await service.SendMsgAsync(command)); } [HttpPost] [UnitOfWork(typeof(MessageDbContext))] public async Task WithDraw([FromRoute] Guid msgId) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); return Ok(await service.WithDrawMsgAsync(msgId, Guid.Parse(userId))); } } }