48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using IM.ASPNETCore;
|
|
using MessageService.Infrastructure;
|
|
using MessageService.WebApi.Application.Message;
|
|
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<IActionResult> 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<IActionResult> WithDraw([FromQuery] Guid msgId)
|
|
{
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
return Ok(await service.WithDrawMsgAsync(msgId, Guid.Parse(userId)));
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetMessages([FromQuery]Guid conversationId, long? cursor, int direction, int limit)
|
|
{
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var command = new GetMessageCommand(conversationId, Guid.Parse(userId), cursor, direction, limit);
|
|
return Ok(await service.GetMessagesAsync(command));
|
|
}
|
|
}
|
|
}
|