Created all validators

This commit is contained in:
2026-03-10 10:43:28 +01:00
parent 9f858df5f8
commit 5c3419abc0
19 changed files with 54 additions and 34 deletions

View File

@@ -63,7 +63,4 @@ app.UseAuthentication()
// app.UseCors();
app.Services.GetRequiredService<BookHiveDbContext>().Database.EnsureDeleted();
app.Services.GetRequiredService<BookHiveDbContext>().Database.EnsureCreated();
app.Run();

View File

@@ -8,6 +8,7 @@ public class GetBookByIdSpec : SingleResultSpecification<Book>
public GetBookByIdSpec(int bookId)
{
Query
.Include(x => x.Author)
.Where(x => x.Id == bookId);
}
}

View File

@@ -14,9 +14,9 @@ public class CreateBookDtoValidator : Validator<CreateBookDto>
.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.");
.NotEmpty()
.WithMessage("LISBN est obligatoire.")!
.IsValidIsbn13();
RuleFor(x => x.PageCount)
.GreaterThan(0)

View File

@@ -26,6 +26,17 @@ public class CreateLoanDtoValidator : Validator<CreateLoanDto>
.GreaterThan(d => d.LoanDate)
.WithMessage("Due date must be in the future.")
.Must((loan, dueDate) => dueDate <= loan.LoanDate.AddDays(30))
.WithMessage("Due date must be in the future.");;
.WithMessage("Due date must be in the future.");
RuleFor(x => x.DueDate)
.Must((dto, dueDate) =>
{
var dayOfWeek = dto.LoanDate.DayOfWeek;
var isWeekend = dayOfWeek == DayOfWeek.Saturday
|| dayOfWeek == DayOfWeek.Sunday;
var maxDays = isWeekend ? 14 : 30;
return dueDate <= dto.LoanDate.AddDays(maxDays);
})
.WithMessage("La durée max est de 14j (week-end) ou 30j (semaine).");
}
}

View File

@@ -18,7 +18,7 @@ public class CreateReviewDtoValidator : Validator<CreateReviewDto>
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage("Rating must be between 1 and 5.");
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");
When(x => x.Comment is not null, () =>
{

View File

@@ -22,7 +22,7 @@ public class UpdateReviewDtoValidator : Validator<UpdateReviewDto>
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage("Rating must be between 1 and 5.");
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");
When(x => x.Comment is not null, () =>
{

View File

@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("BookHive")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ecdabab5a1a621c003643d8f0f2e492d314951f9")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9f858df5f8559ef4eece66d288194275a0509245")]
[assembly: System.Reflection.AssemblyProductAttribute("BookHive")]
[assembly: System.Reflection.AssemblyTitleAttribute("BookHive")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
38e3040d9641db39778141a07f9c125f563b85c555e95be9b8385c95c14acd96
24c20bc00ebed273ed8d88d70e9db8fba99e16f4c11f44fa290911d9e2a0ca7d

View File

@@ -1 +1 @@
41fc3b734d4bc6835927453b9f4d7cdd11e742d0714a8d542d23004e43ece95a
83126e6bfb83bdfd52cfec65d256c75a3ab035c366b329c9b517e33f5e1849d1

View File

@@ -1 +1 @@
{"GlobalPropertiesHash":"GuRprL5mC7hc0CG8FgEPpIWKx/Dfl1Jhxvhk8sWxBEQ=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["kIO\u002BgVQX72rEP/AM8N4erO8boVd0NQ5bkxTtUbSKS9I=","Uf8MX/\u002BVloY39fAvymRXdZ4qt/FRES4KRvClr57fYDU=","lfZuIjVBvtBmrqX0WvkpZ3DYOYwGL3QDuIUtKarpEII=","cKn2pHge4p72bHZX6RcPkCSMotE3yKol468IJfCIBSs=","ns1MuHuvJ97vk/1G9RavyVW40bQqScr\u002BntDnZSwZUHA="],"CachedAssets":{},"CachedCopyCandidates":{}}
{"GlobalPropertiesHash":"GuRprL5mC7hc0CG8FgEPpIWKx/Dfl1Jhxvhk8sWxBEQ=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["kIO\u002BgVQX72rEP/AM8N4erO8boVd0NQ5bkxTtUbSKS9I=","Uf8MX/\u002BVloY39fAvymRXdZ4qt/FRES4KRvClr57fYDU=","lfZuIjVBvtBmrqX0WvkpZ3DYOYwGL3QDuIUtKarpEII=","cKn2pHge4p72bHZX6RcPkCSMotE3yKol468IJfCIBSs=","YDM8gir9t/JobnY2IBraj9MVLPnhuLmU9uuLWanHPfo="],"CachedAssets":{},"CachedCopyCandidates":{}}

View File

@@ -1 +1 @@
{"GlobalPropertiesHash":"03RR8FZ+u5Ay9wTZirfGS5vS3BFumeGaLKPk0IyeRqs=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["kIO\u002BgVQX72rEP/AM8N4erO8boVd0NQ5bkxTtUbSKS9I=","Uf8MX/\u002BVloY39fAvymRXdZ4qt/FRES4KRvClr57fYDU=","lfZuIjVBvtBmrqX0WvkpZ3DYOYwGL3QDuIUtKarpEII=","cKn2pHge4p72bHZX6RcPkCSMotE3yKol468IJfCIBSs=","ns1MuHuvJ97vk/1G9RavyVW40bQqScr\u002BntDnZSwZUHA="],"CachedAssets":{},"CachedCopyCandidates":{}}
{"GlobalPropertiesHash":"03RR8FZ+u5Ay9wTZirfGS5vS3BFumeGaLKPk0IyeRqs=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["kIO\u002BgVQX72rEP/AM8N4erO8boVd0NQ5bkxTtUbSKS9I=","Uf8MX/\u002BVloY39fAvymRXdZ4qt/FRES4KRvClr57fYDU=","lfZuIjVBvtBmrqX0WvkpZ3DYOYwGL3QDuIUtKarpEII=","cKn2pHge4p72bHZX6RcPkCSMotE3yKol468IJfCIBSs=","YDM8gir9t/JobnY2IBraj9MVLPnhuLmU9uuLWanHPfo="],"CachedAssets":{},"CachedCopyCandidates":{}}

View File

@@ -1 +1 @@
17731267691332367
17731341506250102