From 6a8e5b9a8f4b1d7e8de383ab4595ed1f7f5a5f02 Mon Sep 17 00:00:00 2001 From: Enzo Norguet Date: Sat, 14 Mar 2026 13:29:20 +0100 Subject: [PATCH] Add Users, Messages, Friends and RandomChallenge Validators --- BeReadyBackend/DTO/Users/GetUserDetailsDto.cs | 2 +- BeReadyBackend/DTO/Users/GetUserDto.cs | 2 +- .../DTO/Users/PatchUserDesignationDto.cs | 2 +- .../Friends/GetFriendDtoValidator.cs | 23 ++++++++ .../Friends/GetFriendRequestDtoValidator.cs | 23 ++++++++ .../Messages/CreateMessageDtoValidator.cs | 27 ++++++++++ .../GetRandomChallengeDtoValidator.cs | 29 ++++++++++ .../Users/CreateUserDtoValidator.cs | 51 ++++++++++++++++++ .../Users/GetUserChallengeDtoValidator.cs | 27 ++++++++++ .../Users/GetUserDetailsDtoValidator.cs | 54 +++++++++++++++++++ .../Validators/Users/GetUserDtoValidator.cs | 48 +++++++++++++++++ .../Users/GetUserProofDtoValidator.cs | 21 ++++++++ .../Users/GetUserStatsDtoValidator.cs | 35 ++++++++++++ .../Users/PatchUserDesignationDtoValidator.cs | 18 +++++++ .../Users/PatchUserPasswordDtoValidator.cs | 19 +++++++ .../Users/UpdateUserDtoValidator.cs | 43 +++++++++++++++ 16 files changed, 421 insertions(+), 3 deletions(-) create mode 100644 BeReadyBackend/Validators/Friends/GetFriendDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Friends/GetFriendRequestDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Messages/CreateMessageDtoValidator.cs create mode 100644 BeReadyBackend/Validators/RandomChallenges/GetRandomChallengeDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/CreateUserDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/GetUserChallengeDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/GetUserDetailsDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/GetUserDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/GetUserProofDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/GetUserStatsDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/PatchUserDesignationDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/PatchUserPasswordDtoValidator.cs create mode 100644 BeReadyBackend/Validators/Users/UpdateUserDtoValidator.cs diff --git a/BeReadyBackend/DTO/Users/GetUserDetailsDto.cs b/BeReadyBackend/DTO/Users/GetUserDetailsDto.cs index c51b67e..43f749b 100644 --- a/BeReadyBackend/DTO/Users/GetUserDetailsDto.cs +++ b/BeReadyBackend/DTO/Users/GetUserDetailsDto.cs @@ -7,7 +7,7 @@ public class GetUserDetailsDto public string? Name { get; set; } public string? Username { get; set; } public string? Email { get; set; } - public int DesignationId { get; set; } + public int? DesignationId { get; set; } public DateTime CreationDate { get; set; } public GetUserStatsDto? GetUserStatsDto { get; set; } } \ No newline at end of file diff --git a/BeReadyBackend/DTO/Users/GetUserDto.cs b/BeReadyBackend/DTO/Users/GetUserDto.cs index 393a4ac..4345b58 100644 --- a/BeReadyBackend/DTO/Users/GetUserDto.cs +++ b/BeReadyBackend/DTO/Users/GetUserDto.cs @@ -6,6 +6,6 @@ public class GetUserDto public string? FirstName { get; set; } public string? Name { get; set; } public string? Username { get; set; } - public int DesignationId { get; set; } + public int? DesignationId { get; set; } public GetUserStatsDto? GetUserStatsDto { get; set; } } \ No newline at end of file diff --git a/BeReadyBackend/DTO/Users/PatchUserDesignationDto.cs b/BeReadyBackend/DTO/Users/PatchUserDesignationDto.cs index fbe6a71..f996e90 100644 --- a/BeReadyBackend/DTO/Users/PatchUserDesignationDto.cs +++ b/BeReadyBackend/DTO/Users/PatchUserDesignationDto.cs @@ -2,5 +2,5 @@ public class PatchUserDesignationDto { - public int DesignationId { get; set; } + public int? DesignationId { get; set; } } \ No newline at end of file diff --git a/BeReadyBackend/Validators/Friends/GetFriendDtoValidator.cs b/BeReadyBackend/Validators/Friends/GetFriendDtoValidator.cs new file mode 100644 index 0000000..9074d15 --- /dev/null +++ b/BeReadyBackend/Validators/Friends/GetFriendDtoValidator.cs @@ -0,0 +1,23 @@ +using BeReadyBackend.DTO.Friends; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Friends; + +public class GetFriendDtoValidator : Validator +{ + public GetFriendDtoValidator() + { + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username is required") + .MaximumLength(50) + .WithMessage("Username cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Username must exceed 2 characters"); + + RuleFor(x => x.Score) + .NotEmpty() + .WithMessage("Score is required"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Friends/GetFriendRequestDtoValidator.cs b/BeReadyBackend/Validators/Friends/GetFriendRequestDtoValidator.cs new file mode 100644 index 0000000..8e3dbb6 --- /dev/null +++ b/BeReadyBackend/Validators/Friends/GetFriendRequestDtoValidator.cs @@ -0,0 +1,23 @@ +using BeReadyBackend.DTO.Friends; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Friends; + +public class GetFriendRequestDtoValidator : Validator +{ + public GetFriendRequestDtoValidator() + { + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username is required") + .MaximumLength(50) + .WithMessage("Username cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Username must exceed 2 characters"); + + RuleFor(x => x.Score) + .NotEmpty() + .WithMessage("Score is required"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Messages/CreateMessageDtoValidator.cs b/BeReadyBackend/Validators/Messages/CreateMessageDtoValidator.cs new file mode 100644 index 0000000..3b95c60 --- /dev/null +++ b/BeReadyBackend/Validators/Messages/CreateMessageDtoValidator.cs @@ -0,0 +1,27 @@ +using BeReadyBackend.DTO.Messages; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Messages; + +public class CreateMessageDtoValidator : Validator +{ + public CreateMessageDtoValidator() + { + RuleFor(x => x.Libelle) + .NotEmpty() + .WithMessage("Libelle is required") + .MaximumLength(200) //Add BDD + .WithMessage("Libelle cannot exceed 200 characters") + .MinimumLength(2) + .WithMessage("Libelle must exceed 2 characters"); + + RuleFor(x => x.SendDate) //Edit BDD + .NotEmpty() + .WithMessage("SendDate is required"); + + RuleFor(x => x.GroupId) + .NotEmpty() + .WithMessage("GroupId is required"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/RandomChallenges/GetRandomChallengeDtoValidator.cs b/BeReadyBackend/Validators/RandomChallenges/GetRandomChallengeDtoValidator.cs new file mode 100644 index 0000000..b6b145d --- /dev/null +++ b/BeReadyBackend/Validators/RandomChallenges/GetRandomChallengeDtoValidator.cs @@ -0,0 +1,29 @@ +using BeReadyBackend.DTO.RandomChallenges; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.RandomChallenges; + +public class GetRandomChallengeDtoValidator : Validator +{ + public GetRandomChallengeDtoValidator() + { + RuleFor(x => x.Libelle) + .NotEmpty() + .WithMessage("Libelle is required") + .MaximumLength(200) //Add BDD + .WithMessage("Libelle cannot exceed 200 characters") + .MinimumLength(2) + .WithMessage("Libelle must exceed 2 characters"); + + RuleFor(x => x.Duration) + .NotEmpty() + .WithMessage("Duration cannot be empty") + .GreaterThan(0) + .WithMessage("Duration must exceed 1 hour"); + + RuleFor(x => x.IsAlreadyPast) + .NotEmpty() + .WithMessage("Isalready past is required"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/CreateUserDtoValidator.cs b/BeReadyBackend/Validators/Users/CreateUserDtoValidator.cs new file mode 100644 index 0000000..bcf4d83 --- /dev/null +++ b/BeReadyBackend/Validators/Users/CreateUserDtoValidator.cs @@ -0,0 +1,51 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class CreateUserDtoValidator : Validator +{ + public CreateUserDtoValidator() + { + RuleFor(x => x.FirstName) + .NotEmpty() + .WithMessage("First name is required") + .MaximumLength(50) + .WithMessage("First name cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("First name must exceed 2 characters"); + + RuleFor(x => x.Name) + .NotEmpty() + .WithMessage("Name is required") + .MaximumLength(50) + .WithMessage("Name cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Name must exceed 2 characters"); + + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username is required") + .MaximumLength(50) + .WithMessage("Username cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Username must exceed 2 characters"); + + RuleFor(x => x.Email) + .NotEmpty() + .WithMessage("Email is required") + .MaximumLength(100) + .WithMessage("Email cannot exceed 100 characters") + .EmailAddress() + .WithMessage("Invalid email address"); + + RuleFor(x => x.Password) + .NotEmpty() + .WithMessage("Password is required") + .MaximumLength(60) + .WithMessage("Password cannot exceed 60 characters") + .MinimumLength(12) + .WithMessage("Password must exceed 12 characters"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/GetUserChallengeDtoValidator.cs b/BeReadyBackend/Validators/Users/GetUserChallengeDtoValidator.cs new file mode 100644 index 0000000..c31a0d8 --- /dev/null +++ b/BeReadyBackend/Validators/Users/GetUserChallengeDtoValidator.cs @@ -0,0 +1,27 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class GetUserChallengeDtoValidator : Validator +{ + public GetUserChallengeDtoValidator() + { + RuleFor(x => x.ChallengeTitle) + .NotEmpty() + .WithMessage("Challenge Title is required") + .MaximumLength(100) + .WithMessage("Challenge Title cannot exceed 100 characters"); + + RuleFor(x => x.ChallengeDescription) + .NotEmpty() + .WithMessage("Challenge Description is required") + .MaximumLength(200) + .WithMessage("Challenge Description cannot exceed 200 characters"); + + RuleFor(x => x.ChallengeDuration) + .NotEmpty() + .WithMessage("Challenge Duration is required"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/GetUserDetailsDtoValidator.cs b/BeReadyBackend/Validators/Users/GetUserDetailsDtoValidator.cs new file mode 100644 index 0000000..0a85e24 --- /dev/null +++ b/BeReadyBackend/Validators/Users/GetUserDetailsDtoValidator.cs @@ -0,0 +1,54 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class GetUserDetailsDtoValidator : Validator +{ + public GetUserDetailsDtoValidator() + { + RuleFor(x => x.FirstName) + .NotEmpty() + .WithMessage("First name is required") + .MaximumLength(50) + .WithMessage("First name cannot not exceed 50 characters") + .MinimumLength(50) + .WithMessage("First name must not exceed 50 characters"); + + RuleFor(x => x.Name) + .NotEmpty() + .WithMessage("Name is required") + .MaximumLength(50) + .WithMessage("Name cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Name must exceed 2 characters"); + + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username is required") + .MaximumLength(50) + .WithMessage("Username cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Username must exceed 2 characters"); + + RuleFor(x => x.Email) + .NotEmpty() + .WithMessage("Email is required") + .MaximumLength(100) + .WithMessage("Email cannot exceed 100 characters") + .EmailAddress() + .WithMessage("Invalid email address"); + + RuleFor(x => x.CreationDate) + .NotEmpty() + .WithMessage("CreationDate is required"); + + When(x => x.DesignationId is not null, () => + { + RuleFor(x => x.DesignationId) + .NotEmpty() + .WithMessage("DesignationId is required"); + }); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/GetUserDtoValidator.cs b/BeReadyBackend/Validators/Users/GetUserDtoValidator.cs new file mode 100644 index 0000000..2970da7 --- /dev/null +++ b/BeReadyBackend/Validators/Users/GetUserDtoValidator.cs @@ -0,0 +1,48 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class GetUserDtoValidator : Validator +{ + public GetUserDtoValidator() { + + RuleFor(x => x.Id) + .NotEmpty() + .WithMessage("Id cannot be empty") + .GreaterThan(0) + .WithMessage("Id must be greater than 0"); + + RuleFor(x => x.FirstName) + .NotEmpty() + .WithMessage("First name is required") + .MaximumLength(50) + .WithMessage("First name cannot not exceed 50 characters") + .MinimumLength(50) + .WithMessage("First name must not exceed 50 characters"); + + RuleFor(x => x.Name) + .NotEmpty() + .WithMessage("Name is required") + .MaximumLength(50) + .WithMessage("Name cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Name must exceed 2 characters"); + + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username is required") + .MaximumLength(50) + .WithMessage("Username cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Username must exceed 2 characters"); + + When(x => x.DesignationId is not null, () => + { + RuleFor(x => x.DesignationId) + .NotEmpty() + .WithMessage("DesignationId is required"); + }); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/GetUserProofDtoValidator.cs b/BeReadyBackend/Validators/Users/GetUserProofDtoValidator.cs new file mode 100644 index 0000000..61acaa6 --- /dev/null +++ b/BeReadyBackend/Validators/Users/GetUserProofDtoValidator.cs @@ -0,0 +1,21 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class GetUserProofDtoValidator : Validator +{ + public GetUserProofDtoValidator() + { + RuleFor(x => x.Id) + .NotEmpty() + .WithMessage("Id cannot be empty") + .GreaterThan(0) + .WithMessage("Id must be greater than 0"); + + RuleFor(x => x.Proof) + .NotEmpty() + .WithMessage("Proof cannot be empty"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/GetUserStatsDtoValidator.cs b/BeReadyBackend/Validators/Users/GetUserStatsDtoValidator.cs new file mode 100644 index 0000000..3954bf9 --- /dev/null +++ b/BeReadyBackend/Validators/Users/GetUserStatsDtoValidator.cs @@ -0,0 +1,35 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class GetUserStatsDtoValidator : Validator +{ + public GetUserStatsDtoValidator() + { + RuleFor(x => x.Score) + .NotEmpty() + .WithMessage("Score is required"); + + RuleFor(x => x.TotalWin) + .NotEmpty() + .WithMessage("Total win is required"); + + RuleFor(x=> x.TotalChallenge) + .NotEmpty() + .WithMessage("Total challenge is required"); + + RuleFor(x => x.TotalPodium) + .NotEmpty() + .WithMessage("Total podium is required"); + + RuleFor(x => x.TotalBonusChallenge) + .NotEmpty() + .WithMessage("Total bonus is required"); + + RuleFor(x => x.Series) + .NotEmpty() + .WithMessage("Series is required"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/PatchUserDesignationDtoValidator.cs b/BeReadyBackend/Validators/Users/PatchUserDesignationDtoValidator.cs new file mode 100644 index 0000000..461618d --- /dev/null +++ b/BeReadyBackend/Validators/Users/PatchUserDesignationDtoValidator.cs @@ -0,0 +1,18 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class PatchUserDesignationDtoValidator : Validator +{ + public PatchUserDesignationDtoValidator() + { + When(x => x.DesignationId is not null, () => + { + RuleFor(x => x.DesignationId) + .NotEmpty() + .WithMessage("DesignationId is required"); + }); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/PatchUserPasswordDtoValidator.cs b/BeReadyBackend/Validators/Users/PatchUserPasswordDtoValidator.cs new file mode 100644 index 0000000..d124d65 --- /dev/null +++ b/BeReadyBackend/Validators/Users/PatchUserPasswordDtoValidator.cs @@ -0,0 +1,19 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class PatchUserPasswordDtoValidator : Validator +{ + public PatchUserPasswordDtoValidator() + { + RuleFor(x => x.Password) + .NotEmpty() + .WithMessage("Password is required") + .MaximumLength(60) + .WithMessage("Password cannot exceed 60 characters") + .MinimumLength(12) + .WithMessage("Password must exceed 12 characters"); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Validators/Users/UpdateUserDtoValidator.cs b/BeReadyBackend/Validators/Users/UpdateUserDtoValidator.cs new file mode 100644 index 0000000..fdb6c9a --- /dev/null +++ b/BeReadyBackend/Validators/Users/UpdateUserDtoValidator.cs @@ -0,0 +1,43 @@ +using BeReadyBackend.DTO.Users; +using FastEndpoints; +using FluentValidation; + +namespace BeReadyBackend.Validators.Users; + +public class UpdateUserDtoValidator : Validator +{ + public UpdateUserDtoValidator() + { + RuleFor(x => x.FirstName) + .NotEmpty() + .WithMessage("First name is required") + .MaximumLength(50) + .WithMessage("First name cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("First name must exceed 2 characters"); + + RuleFor(x => x.Name) + .NotEmpty() + .WithMessage("Name is required") + .MaximumLength(50) + .WithMessage("Name cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Name must exceed 2 characters"); + + RuleFor(x => x.Username) + .NotEmpty() + .WithMessage("Username is required") + .MaximumLength(50) + .WithMessage("Username cannot exceed 50 characters") + .MinimumLength(2) + .WithMessage("Username must exceed 2 characters"); + + RuleFor(x => x.Email) + .NotEmpty() + .WithMessage("Email is required") + .MaximumLength(100) + .WithMessage("Email cannot exceed 100 characters") + .EmailAddress() + .WithMessage("Invalid email address"); + } +} \ No newline at end of file