添加项目文件。

This commit is contained in:
2026-04-30 21:08:28 +08:00
parent c60f5fe117
commit cc017b6495
327 changed files with 12860 additions and 0 deletions
@@ -0,0 +1,34 @@
using MessageService.WebApi.Application.Conversation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace MessageService.WebApi.Controllers.Conversation
{
[Route("api/[controller]/[action]")]
[Authorize]
[ApiController]
public class ConversationController : ControllerBase
{
private readonly ConversationService service;
public ConversationController(ConversationService service)
{
this.service = service;
}
[HttpGet]
public async Task<IActionResult> List()
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
return Ok(await service.GetByOwnerIdAsync(Guid.Parse(userId)));
}
[HttpGet]
public async Task<IActionResult> Get([FromRoute] Guid id)
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
return Ok(await service.GetByIdAsync(id, Guid.Parse(userId)));
}
}
}
@@ -0,0 +1,38 @@
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<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([FromRoute] Guid msgId)
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
return Ok(await service.WithDrawMsgAsync(msgId, Guid.Parse(userId)));
}
}
}
@@ -0,0 +1,59 @@
using FluentValidation;
using MessageService.Domain.Enums;
using MessageService.WebApi.Application.Message;
namespace MessageService.WebApi.Controllers.Message
{
public class MessageSendRequest
{
// 基础元数据
public Guid ClientMsgId { get; init; }
public Guid TargetId { get; init; }
public ChatType ChatType { get; init; }
public MessageType MsgType { get; init; }
// 业务属性
public Guid? QuoteMessageId { get; init; }
public Dictionary<string, string>? Ext { get; init; }
// 载荷数据(根据 MsgType 选择性填充)
public string? Text { get; init; }
public string? Url { get; init; }
public int? Width { get; init; }
public int? Height { get; init; }
public string? Thumb { get; init; }
public int? Duration { get; init; }
public SendMsgCommand ToCommand(Guid senderId)
{
return new SendMsgCommand(
senderId,
TargetId,
ChatType,
MsgType,
ClientMsgId,
QuoteMessageId,
Ext,
Text,
Url,
Width,
Height,
Thumb,
Duration
);
}
}
public class MessageSendRequestValidator : AbstractValidator<MessageSendRequest>
{
public MessageSendRequestValidator()
{
RuleFor(r => r.ClientMsgId)
.NotNull()
.NotEmpty();
RuleFor(r => r.TargetId)
.NotEmpty()
.NotNull();
}
}
}