finalizare 1.0

This commit is contained in:
andrei-mihnea-cerbu
2024-05-21 12:10:53 +03:00
parent f7795f7519
commit 1cc1d34003
11268 changed files with 2102399 additions and 10909 deletions
@@ -0,0 +1,40 @@
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Chats.SendMessage;
public class SendMessageValidator : AbstractValidator<SendMessageCommand>
{
private readonly IDoctorRepository _doctorRepository;
private readonly IPatientRepository _patientRepository;
public SendMessageValidator(IDoctorRepository doctorRepository, IPatientRepository patientRepository)
{
RuleFor(x => x.Sender)
.NotEmpty().WithMessage("Sender Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
RuleFor(x => x.Receiver)
.NotEmpty().WithMessage("Receiver Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
RuleFor(x => x.Message)
.NotEmpty().WithMessage("Message is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
RuleFor(x => x)
.MustAsync(CheckForUsersExistence).WithMessage("One of the users is not existing.")
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
_patientRepository = patientRepository;
_doctorRepository = doctorRepository;
}
private async Task<bool> CheckForUsersExistence(SendMessageCommand request, CancellationToken token)
{
var firstCheck = await _patientRepository.GetByIdAsync(request.Sender, token) != null &&
await _doctorRepository.GetByIdAsync(request.Receiver, token) != null;
var secondCheck = await _patientRepository.GetByIdAsync(request.Receiver, token) != null &&
await _doctorRepository.GetByIdAsync(request.Sender, token) != null;
return firstCheck || secondCheck;
}
}