1、会话列表、消息界面展示与后端打通 后端: 1、修复会话和消息服务现存问题 2、会话对象不再返回Message对象,而是使用MessageBaseDto替代 3、修改查询会话列表和会话信息的逻辑 4、新增消息列表查询 文档: 后端代码规范文档新增从数据库同步到模型的命令
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using IM_API.Dtos;
|
|
using IM_API.Interface.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Security.Claims;
|
|
|
|
namespace IM_API.Controllers
|
|
{
|
|
[Authorize]
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class MessageController : ControllerBase
|
|
{
|
|
private readonly IMessageSevice _messageService;
|
|
private readonly ILogger<MessageController> _logger;
|
|
public MessageController(IMessageSevice messageService, ILogger<MessageController> logger)
|
|
{
|
|
_messageService = messageService;
|
|
_logger = logger;
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> SendPrivateMessage(MessageBaseDto dto)
|
|
{
|
|
var userIdstr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
await _messageService.SendPrivateMessageAsync(int.Parse(userIdstr), dto.ReceiverId, dto);
|
|
return Ok(new BaseResponse<object?>());
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> SendGroupMessage(MessageBaseDto dto)
|
|
{
|
|
var userIdstr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
await _messageService.SendGroupMessageAsync(int.Parse(userIdstr), dto.ReceiverId, dto);
|
|
return Ok(new BaseResponse<object?>());
|
|
}
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetMessageList([Required]int conversationId, int? msgId, int? pageSize)
|
|
{
|
|
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var msgList = await _messageService.GetMessagesAsync(int.Parse(userIdStr), conversationId, msgId, pageSize, false);
|
|
var res = new BaseResponse<List<MessageBaseDto>>(msgList);
|
|
return Ok(res);
|
|
}
|
|
}
|
|
}
|