api v2.0
This commit is contained in:
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Doctors.Profile;
|
||||
|
||||
public class DoctorProfileValidation : AbstractValidator<DoctorProfileDTO>
|
||||
public class DoctorProfileValidation : AbstractValidator<DoctorProfileUpdateDto>
|
||||
{
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
|
||||
@@ -11,30 +11,41 @@ public class DoctorProfileValidation : AbstractValidator<DoctorProfileDTO>
|
||||
{
|
||||
_doctorRepository = doctorRepository;
|
||||
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is registered in system")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.NotEmpty().WithMessage("Email is required.")
|
||||
.EmailAddress().WithMessage("Invalid email format.")
|
||||
.MustAsync(BeUniqueEmail).WithMessage("Email in use by another doctor.");
|
||||
.NotEmpty().WithMessage("Email is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.EmailAddress().WithMessage("Invalid email format.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MustAsync(BeUniqueEmail).WithMessage("Email in use by another doctor.")
|
||||
.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> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var doctor = await _doctorRepository.GetByIdAsync(id);
|
||||
return doctor == null;
|
||||
}
|
||||
|
||||
private async Task<bool> BeUniqueEmail(string email, CancellationToken cancellationToken)
|
||||
{
|
||||
var doctor = await _doctorRepository.FindByEmailAsync(email);
|
||||
if (doctor != null)
|
||||
{
|
||||
return doctor.Email.Equals(email, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
return doctor == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user