This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 00:03:24 +03:00
parent 2ccec617a5
commit b48d5ee19e
168 changed files with 2877 additions and 1146 deletions
@@ -1,5 +1,4 @@
using Application.Endpoints.Doctors.Login;
using Application.Services.Database;
using Application.Services.Database;
using FluentValidation;
namespace Application.Endpoints.Doctors.Registration;
@@ -13,20 +12,24 @@ public class DoctorRegistrationValidation : AbstractValidator<DoctorRegistration
_doctorRepository = doctorRepository;
RuleFor(x => x.Email)
.NotEmpty().WithMessage("Email is required.")
.EmailAddress().WithMessage("Invalid email format.")
.MustAsync(BeUniqueEmail).WithMessage("Email already exists.");
.NotEmpty().WithMessage("Email is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.EmailAddress().WithMessage("Invalid email format.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.MustAsync(BeUniqueEmail).WithMessage("Email already exists.")
.WithErrorCode(HttpStatusCodes.Conflict.ToString());
RuleFor(x => x.Password)
.NotEmpty().WithMessage("Password is required.")
.MinimumLength(8).WithMessage("Password must be at least 8 characters long.");
.NotEmpty().WithMessage("Password is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.MinimumLength(8).WithMessage("Password must be at least 8 characters long.")
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Name is required.")
.MinimumLength(3).WithMessage("Name must be at least 3 characters long.");
.NotEmpty().WithMessage("Name is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.MinimumLength(3).WithMessage("Name must be at least 3 characters long.")
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
RuleFor(x => x.Description)
.MaximumLength(3000).WithMessage("Description must not exceed 3000 characters.");
.MaximumLength(3000).WithMessage("Description must not exceed 3000 characters.")
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
}
private async Task<bool> BeUniqueEmail(string email, CancellationToken cancellationToken)
@@ -34,4 +37,4 @@ public class DoctorRegistrationValidation : AbstractValidator<DoctorRegistration
var doctor = await _doctorRepository.FindByEmailAsync(email);
return doctor == null;
}
}
}