Fixed error in message DTO and hub

This commit is contained in:
2026-05-13 22:49:41 +01:00
parent c3eed1f45e
commit 727494aab4
4 changed files with 7 additions and 8 deletions
@@ -4,5 +4,4 @@ public class CreateMessageDto
{
public int GroupId { get; set; }
public string? Libelle { get; set; }
public DateTime SendDate { get; set; }
}
@@ -4,6 +4,7 @@ using BeReadyBackend.Models;
using BeReadyBackend.Repositories;
using BeReadyBackend.Services;
using BeReadyBackend.Specifications.Groups;
using BeReadyBackend.Specifications.Messages;
using FastEndpoints;
using Microsoft.AspNetCore.SignalR;
using Group = System.Text.RegularExpressions.Group;
@@ -34,10 +35,12 @@ public class SendMessageEndpoint(
Message message = new();
mapper.Map(req, message);
message.SendDate = DateTime.Now;
message.UserId = userService.GetUserIdFromToken();
await messagesRepository.AddAsync(message, ct);
await hubContext.Clients.Group($"group-{req.GroupId}").SendAsync("ReceiveMessage", message, cancellationToken: ct);
GetMessageDto messageDto = await messagesRepository.ProjectToSingleAsync<GetMessageDto>(new GetMessageByIdSpec(message.Id), ct);
await hubContext.Clients.Group($"group-{req.GroupId}").SendAsync("ReceiveMessage", messageDto, cancellationToken: ct);
await Send.NoContentAsync(ct);
}
}
+3 -2
View File
@@ -1,11 +1,12 @@
using Microsoft.AspNetCore.SignalR;
using BeReadyBackend.DTO.Messages;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Primitives;
namespace BeReadyBackend.Hubs;
public class GroupHub : Hub
{
public async Task SendMessageToGroup(int groupId, string message)
public async Task SendMessageToGroup(int groupId, CreateMessageDto message)
{
await Clients.Group($"group-{groupId}").SendAsync("ReceiveMessage", message);
}
@@ -16,10 +16,6 @@ public class CreateMessageDtoValidator : Validator<CreateMessageDto>
.MinimumLength(2)
.WithMessage("Libelle must exceed 2 characters");
RuleFor(x => x.SendDate)
.NotEmpty()
.WithMessage("SendDate is required");
RuleFor(x => x.GroupId)
.NotEmpty()
.WithMessage("GroupId is required")