fix: align backend APIs and upload flow
This commit is contained in:
@@ -37,11 +37,24 @@ namespace MessageService.WebApi.Controllers.Message
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetMessages([FromQuery]Guid conversationId, long? cursor, int direction, int limit)
|
||||
public async Task<IActionResult> GetMessages([FromQuery]Guid conversationId, long? cursor, int direction, int limit, CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var command = new GetMessageCommand(conversationId, Guid.Parse(userId), cursor, direction, limit);
|
||||
return Ok(await service.GetMessagesAsync(command));
|
||||
return Ok(await service.GetMessagesAsync(command, cancellationToken));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Search(
|
||||
[FromQuery] Guid conversationId,
|
||||
[FromQuery] string keyword,
|
||||
long? cursor,
|
||||
int limit = 30,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var command = new SearchMessageCommand(conversationId, Guid.Parse(userId!), keyword, cursor, limit);
|
||||
return Ok(await service.SearchMessagesAsync(command, cancellationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ namespace MessageService.WebApi.Controllers.Message
|
||||
public int? Height { get; init; }
|
||||
public string? Thumb { get; init; }
|
||||
public int? Duration { get; init; }
|
||||
public Guid? FileId { get; init; }
|
||||
public string? FileName { get; init; }
|
||||
public long? FileSize { get; init; }
|
||||
public string? FileFormat { get; init; }
|
||||
|
||||
public SendMsgCommand ToCommand(Guid senderId)
|
||||
{
|
||||
@@ -39,7 +43,11 @@ namespace MessageService.WebApi.Controllers.Message
|
||||
Width,
|
||||
Height,
|
||||
Thumb,
|
||||
Duration
|
||||
Duration,
|
||||
FileId,
|
||||
FileName,
|
||||
FileSize,
|
||||
FileFormat
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -63,9 +71,19 @@ namespace MessageService.WebApi.Controllers.Message
|
||||
|
||||
// 图片/视频/语音消息:url 必填
|
||||
When(r => r.MsgType == MessageType.Image || r.MsgType == MessageType.Video
|
||||
|| r.MsgType == MessageType.Voice || r.MsgType == MessageType.File, () =>
|
||||
|| r.MsgType == MessageType.Voice, () =>
|
||||
{
|
||||
RuleFor(r => r.Url).NotEmpty().WithMessage("媒体消息的 url 字段不能为空");
|
||||
RuleFor(r => r)
|
||||
.Must(request => !string.IsNullOrWhiteSpace(request.Url) || request.FileId.HasValue)
|
||||
.WithMessage("媒体消息必须提供 url 或 fileId");
|
||||
});
|
||||
|
||||
When(r => r.MsgType == MessageType.File, () =>
|
||||
{
|
||||
RuleFor(r => r.FileId).NotNull().NotEmpty().WithMessage("文件消息的 fileId 字段不能为空");
|
||||
RuleFor(r => r.FileName).NotEmpty().WithMessage("文件消息的 fileName 字段不能为空");
|
||||
RuleFor(r => r.FileSize).NotNull().GreaterThanOrEqualTo(0).WithMessage("文件消息的 fileSize 字段不合法");
|
||||
RuleFor(r => r.FileFormat).NotEmpty().WithMessage("文件消息的 fileFormat 字段不能为空");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user