Cleaned code

This commit is contained in:
2026-03-17 10:27:53 +01:00
parent 15075eb051
commit d202d1541d
55 changed files with 306 additions and 264 deletions

View File

@@ -15,7 +15,7 @@ public class CreateAuthorDtoValidator : Validator<CreateAuthorDto>
.WithMessage("First name cannot exceed 100 characters.")
.MinimumLength(2)
.WithMessage("First name must exceed 2 characters.");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("Last name is required.")
@@ -23,19 +23,19 @@ public class CreateAuthorDtoValidator : Validator<CreateAuthorDto>
.WithMessage("Last name cannot exceed 100 characters.")
.MinimumLength(2)
.WithMessage("Last name must exceed 2 characters.");
RuleFor(x => x.Biography)
.MaximumLength(2000)
.WithMessage("Biography cannot exceed 2000 characters.")
.MinimumLength(2)
.WithMessage("Biography must exceed 2 characters.");
RuleFor(x => x.BirthDate)
.NotEmpty()
.WithMessage("Birth date is required.")
.LessThan(DateOnly.FromDateTime(DateTime.Now))
.WithMessage("Birth date cannot be in the future.");
RuleFor(x => x.Nationality)
.NotEmpty()
.WithMessage("Nationality is required.")

View File

@@ -15,7 +15,7 @@ public class GetAuthorDtoValidator : Validator<GetAuthorDto>
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("First name is required");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("Last name is required");

View File

@@ -11,7 +11,7 @@ public class UpdateAuthorDtoValidator : Validator<UpdateAuthorDto>
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("First name is required.")
@@ -19,7 +19,7 @@ public class UpdateAuthorDtoValidator : Validator<UpdateAuthorDto>
.WithMessage("First name cannot exceed 100 characters.")
.MinimumLength(2)
.WithMessage("First name must exceed 2 characters.");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("Last name is required.")
@@ -27,19 +27,19 @@ public class UpdateAuthorDtoValidator : Validator<UpdateAuthorDto>
.WithMessage("Last name cannot exceed 100 characters.")
.MinimumLength(2)
.WithMessage("Last name must exceed 2 characters.");
RuleFor(x => x.Biography)
.MaximumLength(2000)
.WithMessage("Biography cannot exceed 2000 characters.")
.MinimumLength(2)
.WithMessage("Biography must exceed 2 characters.");
RuleFor(x => x.BirthDate)
.NotEmpty()
.WithMessage("Birth date is required.")
.LessThan(DateOnly.FromDateTime(DateTime.Now))
.WithMessage("Birth date cannot be in the future.");
RuleFor(x => x.Nationality)
.NotEmpty()
.WithMessage("Nationality is required.")

View File

@@ -12,31 +12,31 @@ public class CreateBookDtoValidator : Validator<CreateBookDto>
.NotEmpty().WithMessage("Le titre est obligatoire.")
.MaximumLength(200)
.WithMessage("Le titre ne peut pas dépasser 200 caractères.");
RuleFor(x => x.Isbn)
.NotEmpty()
.WithMessage("LISBN est obligatoire.")!
.IsValidIsbn13();
RuleFor(x => x.PageCount)
.GreaterThan(0)
.WithMessage("Le nombre de pages doit être supérieur à 0.");
RuleFor(x => x.PublishedDate)
.NotEmpty().WithMessage("La date de publication est obligatoire.")
.Must(d => d <= DateOnly.FromDateTime(DateTime.Now))
.WithMessage("La date de publication ne peut pas être dans le futur.");
RuleFor(x => x.Genre)
.NotEmpty()
.WithMessage("Le genre est obligatoire.")
.MaximumLength(50)
.WithMessage("Le genre ne peut pas dépasser 50 caractères.");
RuleFor(x => x.AuthorId)
.GreaterThan(0)
.WithMessage("Lidentifiant de lauteur est invalide.");
When(x => x.Summary != null, () =>
{
RuleFor(x => x.Summary)

View File

@@ -15,12 +15,12 @@ public class GetBookDtoValidator : Validator<GetBookDto>
RuleFor(x => x.Title)
.NotEmpty()
.WithMessage("Title is required");
RuleFor(x => x.Isbn)
.NotEmpty().WithMessage("LISBN est obligatoire.")
.Matches(@"^\d{13}$")
.WithMessage("LISBN doit contenir exactement 13 chiffres.");
RuleFor(x => x.AuthorFullName)
.NotEmpty()
.WithMessage("AuthorFullName is required");

View File

@@ -11,36 +11,36 @@ public class UpdateBookDtoValidator : Validator<UpdateBookDto>
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.Title)
.NotEmpty().WithMessage("Le titre est obligatoire.")
.MaximumLength(200)
.WithMessage("Le titre ne peut pas dépasser 200 caractères.");
RuleFor(x => x.Isbn)
.NotEmpty().WithMessage("LISBN est obligatoire.")
.Matches(@"^\d{13}$")
.WithMessage("LISBN doit contenir exactement 13 chiffres.");
RuleFor(x => x.PageCount)
.GreaterThan(0)
.WithMessage("Le nombre de pages doit être supérieur à 0.");
RuleFor(x => x.PublishedDate)
.NotEmpty().WithMessage("La date de publication est obligatoire.")
.Must(d => d <= DateOnly.FromDateTime(DateTime.Now))
.WithMessage("La date de publication ne peut pas être dans le futur.");
RuleFor(x => x.Genre)
.NotEmpty()
.WithMessage("Le genre est obligatoire.")
.MaximumLength(50)
.WithMessage("Le genre ne peut pas dépasser 50 caractères.");
RuleFor(x => x.AuthorId)
.GreaterThan(0)
.WithMessage("Lidentifiant de lauteur est invalide.");
When(x => x.Summary != null, () =>
{
RuleFor(x => x.Summary)

View File

@@ -20,6 +20,7 @@ public static class CustomValidators
var digit = isbn[i] - '0';
sum += (i % 2 == 0) ? digit : digit * 3;
}
var checkDigit = (10 - (sum % 10)) % 10;
return checkDigit == (isbn[12] - '0');
})

View File

@@ -11,15 +11,15 @@ public class CreateLoanDtoValidator : Validator<CreateLoanDto>
RuleFor(x => x.BookId)
.GreaterThan(0)
.WithMessage("Invalid book id.");
RuleFor(x => x.MemberId)
.GreaterThan(0)
.WithMessage("Invalid member id.");
RuleFor(x => x.LoanDate)
.NotEmpty()
.WithMessage("Date is required.");
RuleFor(x => x.DueDate)
.NotEmpty()
.WithMessage("Due date is required.")
@@ -27,7 +27,7 @@ public class CreateLoanDtoValidator : Validator<CreateLoanDto>
.WithMessage("Due date must be in the future.")
.Must((loan, dueDate) => dueDate <= loan.LoanDate.AddDays(30))
.WithMessage("Due date must be in the future.");
RuleFor(x => x.DueDate)
.Must((dto, dueDate) =>
{

View File

@@ -11,19 +11,19 @@ public class UpdateLoanDtoValidator : Validator<UpdateLoanDto>
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.BookId)
.GreaterThan(0)
.WithMessage("Invalid book id.");
RuleFor(x => x.MemberId)
.GreaterThan(0)
.WithMessage("Invalid member id.");
RuleFor(x => x.LoanDate)
.NotEmpty()
.WithMessage("Date is required.");
RuleFor(x => x.DueDate)
.NotEmpty()
.WithMessage("Due date is required.")

View File

@@ -15,7 +15,7 @@ public class CreateMemberDtoValidator : Validator<CreateMemberDto>
.WithMessage("Email is invalid.")
.MaximumLength(255)
.WithMessage("Email cannot be longer than 255 characters.");
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("First name is required.")
@@ -23,7 +23,7 @@ public class CreateMemberDtoValidator : Validator<CreateMemberDto>
.WithMessage("First name cannot be longer than 100 characters.")
.MinimumLength(2)
.WithMessage("First name cannot be shorter than 2 characters.");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("Last name is required.")
@@ -31,7 +31,7 @@ public class CreateMemberDtoValidator : Validator<CreateMemberDto>
.WithMessage("Last name cannot be longer than 100 characters.")
.MinimumLength(2)
.WithMessage("Last name cannot be shorter than 2 characters.");
RuleFor(x => x.MembershipDate)
.NotEmpty()
.WithMessage("Membership date is required.")

View File

@@ -11,7 +11,7 @@ public class UpdateMemberDtoValidator : Validator<UpdateMemberDto>
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("Email is required.")
@@ -19,7 +19,7 @@ public class UpdateMemberDtoValidator : Validator<UpdateMemberDto>
.WithMessage("Email is invalid.")
.MaximumLength(255)
.WithMessage("Email cannot be longer than 255 characters.");
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("First name is required.")
@@ -27,7 +27,7 @@ public class UpdateMemberDtoValidator : Validator<UpdateMemberDto>
.WithMessage("First name cannot be longer than 100 characters.")
.MinimumLength(2)
.WithMessage("First name cannot be shorter than 2 characters.");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("Last name is required.")
@@ -35,7 +35,7 @@ public class UpdateMemberDtoValidator : Validator<UpdateMemberDto>
.WithMessage("Last name cannot be longer than 100 characters.")
.MinimumLength(2)
.WithMessage("Last name cannot be shorter than 2 characters.");
RuleFor(x => x.MembershipDate)
.NotEmpty()
.WithMessage("Membership date is required.")

View File

@@ -11,11 +11,11 @@ public class CreateReviewDtoValidator : Validator<CreateReviewDto>
RuleFor(x => x.MemberId)
.GreaterThan(0)
.WithMessage("Member id is invalid.");
RuleFor(x => x.BookId)
.GreaterThan(0)
.WithMessage("Book id is invalid.");
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");

View File

@@ -11,15 +11,15 @@ public class UpdateReviewDtoValidator : Validator<UpdateReviewDto>
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.BookId)
.GreaterThan(0)
.WithMessage("Book id is invalid.");
RuleFor(x => x.MemberId)
.GreaterThan(0)
.WithMessage("Member id is invalid.");
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");