Fixed error in message DTO and hub
This commit is contained in:
@@ -4,5 +4,4 @@ public class CreateMessageDto
|
|||||||
{
|
{
|
||||||
public int GroupId { get; set; }
|
public int GroupId { get; set; }
|
||||||
public string? Libelle { get; set; }
|
public string? Libelle { get; set; }
|
||||||
public DateTime SendDate { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ using BeReadyBackend.Models;
|
|||||||
using BeReadyBackend.Repositories;
|
using BeReadyBackend.Repositories;
|
||||||
using BeReadyBackend.Services;
|
using BeReadyBackend.Services;
|
||||||
using BeReadyBackend.Specifications.Groups;
|
using BeReadyBackend.Specifications.Groups;
|
||||||
|
using BeReadyBackend.Specifications.Messages;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Group = System.Text.RegularExpressions.Group;
|
using Group = System.Text.RegularExpressions.Group;
|
||||||
@@ -34,10 +35,12 @@ public class SendMessageEndpoint(
|
|||||||
|
|
||||||
Message message = new();
|
Message message = new();
|
||||||
mapper.Map(req, message);
|
mapper.Map(req, message);
|
||||||
|
message.SendDate = DateTime.Now;
|
||||||
message.UserId = userService.GetUserIdFromToken();
|
message.UserId = userService.GetUserIdFromToken();
|
||||||
|
|
||||||
await messagesRepository.AddAsync(message, ct);
|
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);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
using Microsoft.AspNetCore.SignalR;
|
using BeReadyBackend.DTO.Messages;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
namespace BeReadyBackend.Hubs;
|
namespace BeReadyBackend.Hubs;
|
||||||
|
|
||||||
public class GroupHub : Hub
|
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);
|
await Clients.Group($"group-{groupId}").SendAsync("ReceiveMessage", message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ public class CreateMessageDtoValidator : Validator<CreateMessageDto>
|
|||||||
.MinimumLength(2)
|
.MinimumLength(2)
|
||||||
.WithMessage("Libelle must exceed 2 characters");
|
.WithMessage("Libelle must exceed 2 characters");
|
||||||
|
|
||||||
RuleFor(x => x.SendDate)
|
|
||||||
.NotEmpty()
|
|
||||||
.WithMessage("SendDate is required");
|
|
||||||
|
|
||||||
RuleFor(x => x.GroupId)
|
RuleFor(x => x.GroupId)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.WithMessage("GroupId is required")
|
.WithMessage("GroupId is required")
|
||||||
|
|||||||
Reference in New Issue
Block a user