添加项目文件。
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user