Add Users, Messages, Friends and RandomChallenge Validators
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
public class PatchUserDesignationDto
|
||||
{
|
||||
public int DesignationId { get; set; }
|
||||
public int? DesignationId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using BeReadyBackend.DTO.Friends;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Friends;
|
||||
|
||||
public class GetFriendDtoValidator : Validator<GetFriendDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using BeReadyBackend.DTO.Friends;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Friends;
|
||||
|
||||
public class GetFriendRequestDtoValidator : Validator<GetFriendDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using BeReadyBackend.DTO.Messages;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Messages;
|
||||
|
||||
public class CreateMessageDtoValidator : Validator<CreateMessageDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using BeReadyBackend.DTO.RandomChallenges;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.RandomChallenges;
|
||||
|
||||
public class GetRandomChallengeDtoValidator : Validator<GetRandomChallengeDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class CreateUserDtoValidator : Validator<CreateUserDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class GetUserChallengeDtoValidator : Validator<GetUserChallengeDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
|
||||
{
|
||||
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");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class GetUserDtoValidator : Validator<GetUserDto>
|
||||
{
|
||||
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");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class GetUserProofDtoValidator : Validator<GetUserProofDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class GetUserStatsDtoValidator : Validator<GetUserStatsDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class PatchUserDesignationDtoValidator : Validator<PatchUserDesignationDto>
|
||||
{
|
||||
public PatchUserDesignationDtoValidator()
|
||||
{
|
||||
When(x => x.DesignationId is not null, () =>
|
||||
{
|
||||
RuleFor(x => x.DesignationId)
|
||||
.NotEmpty()
|
||||
.WithMessage("DesignationId is required");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class PatchUserPasswordDtoValidator : Validator<PatchUserPasswordDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BeReadyBackend.Validators.Users;
|
||||
|
||||
public class UpdateUserDtoValidator : Validator<UpdateUserDto>
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user