Cleaned code

This commit is contained in:
2026-03-24 18:02:10 +01:00
parent ae8a33b7b6
commit c8cd5d9257
24 changed files with 66 additions and 67 deletions
@@ -20,7 +20,7 @@ public class GetAllProofsEndpoint(UserGroupsRepository userGroupsRepository, Gro
public override async Task HandleAsync(GroupProofRequest req, CancellationToken ct) public override async Task HandleAsync(GroupProofRequest req, CancellationToken ct)
{ {
Group? group = await groupsRepository.SingleOrDefaultAsync(new GetGroupByIdSpec(req.Id), ct); Group? group = await groupsRepository.SingleOrDefaultAsync(new GetGroupByIdSpec(req.Id), ct);
if (group is null) if (group is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
@@ -32,7 +32,7 @@ public class GetAllProofsEndpoint(UserGroupsRepository userGroupsRepository, Gro
await Send.StringAsync("Les votes ne sont pas fini", 400, cancellation: ct); await Send.StringAsync("Les votes ne sont pas fini", 400, cancellation: ct);
return; return;
} }
List<GetProofDto> usersGroup = await userGroupsRepository.ProjectToListAsync<GetProofDto>(new GetUserGroupDetailsByIdSpec(req.Id), ct); List<GetProofDto> usersGroup = await userGroupsRepository.ProjectToListAsync<GetProofDto>(new GetUserGroupDetailsByIdSpec(req.Id), ct);
await Send.OkAsync(usersGroup, ct); await Send.OkAsync(usersGroup, ct);
} }
@@ -41,7 +41,7 @@ public class PatchVoteEndpoint(UserGroupsRepository userGroupsRepository, UserSe
await Send.StringAsync("Le vote est terminé", 400, cancellation: ct); await Send.StringAsync("Le vote est terminé", 400, cancellation: ct);
return; return;
} }
if (member.Group!.StartedVote is null) if (member.Group!.StartedVote is null)
{ {
await Send.StringAsync("Le vote n'a pas commencé", 400, cancellation: ct); await Send.StringAsync("Le vote n'a pas commencé", 400, cancellation: ct);
@@ -31,7 +31,7 @@ public class StartVoteEndpoint(UserGroupsRepository userGroupsRepository, Groups
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
if (group.IsFinished) if (group.IsFinished)
{ {
await Send.StringAsync("Le défi est terminé", 400, cancellation: ct); await Send.StringAsync("Le défi est terminé", 400, cancellation: ct);
@@ -43,7 +43,7 @@ public class StartVoteEndpoint(UserGroupsRepository userGroupsRepository, Groups
await Send.StringAsync("Le défi n'est pas encore terminé", 400, cancellation: ct); await Send.StringAsync("Le défi n'est pas encore terminé", 400, cancellation: ct);
return; return;
} }
group.StartedVote = DateTime.Now; group.StartedVote = DateTime.Now;
await groupsRepository.SaveChangesAsync(ct); await groupsRepository.SaveChangesAsync(ct);
@@ -11,10 +11,10 @@ using Group = System.Text.RegularExpressions.Group;
namespace BeReadyBackend.Endpoints.Messages; namespace BeReadyBackend.Endpoints.Messages;
public class SendMessageEndpoint( public class SendMessageEndpoint(
UserService userService, UserService userService,
GroupsRepository groupsRepository, GroupsRepository groupsRepository,
AutoMapper.IMapper mapper, AutoMapper.IMapper mapper,
MessagesRepository messagesRepository, MessagesRepository messagesRepository,
IHubContext<GroupHub> hubContext) IHubContext<GroupHub> hubContext)
: Endpoint<CreateMessageDto> : Endpoint<CreateMessageDto>
{ {
@@ -37,7 +37,7 @@ public class SendMessageEndpoint(
await Send.StringAsync("Le groupe est fermé", 400, cancellation: ct); await Send.StringAsync("Le groupe est fermé", 400, cancellation: ct);
return; return;
} }
Message message = new(); Message message = new();
mapper.Map(req, message); mapper.Map(req, message);
message.UserId = userService.GetUserIdFromToken(); message.UserId = userService.GetUserIdFromToken();
@@ -28,7 +28,7 @@ public class PatchProofEndpoint(
public override async Task HandleAsync(RandomChallengeProofRequest req, CancellationToken ct) public override async Task HandleAsync(RandomChallengeProofRequest req, CancellationToken ct)
{ {
int userId = userService.GetUserIdFromToken(); int userId = userService.GetUserIdFromToken();
RandomChallenge? randomChallenge = await randomChallengesRepository.SingleOrDefaultAsync(new GetRandomChallengeByIdSpec(req.RandomChallengeId), ct); RandomChallenge? randomChallenge = await randomChallengesRepository.SingleOrDefaultAsync(new GetRandomChallengeByIdSpec(req.RandomChallengeId), ct);
if (randomChallenge is null) if (randomChallenge is null)
{ {
@@ -38,10 +38,10 @@ public class PatchProofEndpoint(
if (randomChallenge.GeneratedAt != null && DateTime.Now > randomChallenge.GeneratedAt.Value.AddHours(randomChallenge.Duration)) if (randomChallenge.GeneratedAt != null && DateTime.Now > randomChallenge.GeneratedAt.Value.AddHours(randomChallenge.Duration))
{ {
await Send.StringAsync("Le défi est terminé", 400, cancellation: ct); await Send.StringAsync("Le défi est terminé", 400, cancellation: ct);
return; return;
} }
UserRandomChallenge? userRandomChallenge = UserRandomChallenge? userRandomChallenge =
await userRandomChallengesRepository.SingleOrDefaultAsync(new GetRandomChallengeByCriteriaSpec(req.RandomChallengeId, userId), ct); await userRandomChallengesRepository.SingleOrDefaultAsync(new GetRandomChallengeByCriteriaSpec(req.RandomChallengeId, userId), ct);
if (userRandomChallenge is null) if (userRandomChallenge is null)
+1 -1
View File
@@ -8,7 +8,7 @@ public class RandomChallenge
[Required, Length(2, 200)] public string? Libelle { get; set; } [Required, Length(2, 200)] public string? Libelle { get; set; }
[Required] public int Duration { get; set; } [Required] public int Duration { get; set; }
[Required] public bool IsAlreadyPast { get; set; } [Required] public bool IsAlreadyPast { get; set; }
[Required] public DateTime? GeneratedAt { get; set; } [Required] public DateTime? GeneratedAt { get; set; }
public List<UserRandomChallenge>? UserRandomChallenges { get; set; } public List<UserRandomChallenge>? UserRandomChallenges { get; set; }
@@ -19,7 +19,7 @@ public class GetAchievementDtoValidator : Validator<GetAchievementDto>
.WithMessage("Description must contain more than 2 characters") .WithMessage("Description must contain more than 2 characters")
.MaximumLength(200) .MaximumLength(200)
.WithMessage("Description cannot contain more than 200 characters"); .WithMessage("Description cannot contain more than 200 characters");
RuleFor(x => x.Label) RuleFor(x => x.Label)
.NotEmpty() .NotEmpty()
.WithMessage("Label must be specified") .WithMessage("Label must be specified")
@@ -13,6 +13,5 @@ public class UnlockAchievementDtoValidator : Validator<UnlockAchievementDto>
.WithMessage("AchievementId cannot be empty") .WithMessage("AchievementId cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("AchievementId must be greater than 0"); .WithMessage("AchievementId must be greater than 0");
} }
} }
@@ -4,7 +4,7 @@ using FluentValidation;
namespace BeReadyBackend.Validators.Auth; namespace BeReadyBackend.Validators.Auth;
public class LoginDtoValidator: Validator<LoginDto> public class LoginDtoValidator : Validator<LoginDto>
{ {
public LoginDtoValidator() public LoginDtoValidator()
{ {
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Friends;
public class GetFriendDtoValidator : Validator<GetFriendDto> public class GetFriendDtoValidator : Validator<GetFriendDto>
{ {
public GetFriendDtoValidator() public GetFriendDtoValidator()
{ {
RuleFor(x => x.Username) RuleFor(x => x.Username)
.NotEmpty() .NotEmpty()
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Friends;
public class GetFriendRequestDtoValidator : Validator<GetFriendDto> public class GetFriendRequestDtoValidator : Validator<GetFriendDto>
{ {
public GetFriendRequestDtoValidator() public GetFriendRequestDtoValidator()
{ {
RuleFor(x => x.Username) RuleFor(x => x.Username)
.NotEmpty() .NotEmpty()
@@ -31,7 +31,7 @@ public class CreateGroupDtoValidator : Validator<CreateGroupDto>
.WithMessage("Description cannot exceed 200 characters") .WithMessage("Description cannot exceed 200 characters")
.MinimumLength(2) .MinimumLength(2)
.WithMessage("Description must exceed 2 characters"); .WithMessage("Description must exceed 2 characters");
RuleFor(x => x.Duration) RuleFor(x => x.Duration)
.NotEmpty() .NotEmpty()
.WithMessage("Duration cannot be empty") .WithMessage("Duration cannot be empty")
@@ -13,7 +13,7 @@ public class GetGroupDetailsDtoValidator : Validator<GetGroupDetailsDto>
.WithMessage("Id cannot be empty") .WithMessage("Id cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Id must be greater than zero"); .WithMessage("Id must be greater than zero");
RuleFor(x => x.Label) RuleFor(x => x.Label)
.NotEmpty() .NotEmpty()
.WithMessage("Label cannot be empty") .WithMessage("Label cannot be empty")
@@ -41,7 +41,7 @@ public class GetGroupDetailsDtoValidator : Validator<GetGroupDetailsDto>
.WithMessage("Description cannot exceed 50 characters") .WithMessage("Description cannot exceed 50 characters")
.MinimumLength(2) .MinimumLength(2)
.WithMessage("Description must exceed 2 characters"); .WithMessage("Description must exceed 2 characters");
RuleFor(x => x.Duration) RuleFor(x => x.Duration)
.NotEmpty() .NotEmpty()
.WithMessage("Duration cannot be empty") .WithMessage("Duration cannot be empty")
@@ -13,7 +13,7 @@ public class GetGroupDtoValidator : Validator<GetGroupDto>
.WithMessage("Id cannot be empty") .WithMessage("Id cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Id must be greater than zero"); .WithMessage("Id must be greater than zero");
RuleFor(x => x.Label) RuleFor(x => x.Label)
.NotEmpty() .NotEmpty()
.WithMessage("Label cannot be empty") .WithMessage("Label cannot be empty")
@@ -13,7 +13,7 @@ public class GetProofDtoValidator : Validator<GetProofDto>
.WithMessage("Id cannot be empty") .WithMessage("Id cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Id must be greater than 0"); .WithMessage("Id must be greater than 0");
RuleFor(x => x.Username) RuleFor(x => x.Username)
.NotEmpty() .NotEmpty()
.WithMessage("Username cannot be empty") .WithMessage("Username cannot be empty")
@@ -25,7 +25,7 @@ public class GetProofDtoValidator : Validator<GetProofDto>
RuleFor(x => x.Proof) RuleFor(x => x.Proof)
.NotEmpty() .NotEmpty()
.WithMessage("Proof cannot be empty"); .WithMessage("Proof cannot be empty");
RuleFor(x => x.Score) RuleFor(x => x.Score)
.NotEmpty() .NotEmpty()
.WithMessage("Score cannot be empty"); .WithMessage("Score cannot be empty");
@@ -13,7 +13,7 @@ public class GetUserGroupDtoValidator : Validator<GetUserGroupDto>
.WithMessage("Id cannot be empty") .WithMessage("Id cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Id must be greater than 0"); .WithMessage("Id must be greater than 0");
RuleFor(x => x.Username) RuleFor(x => x.Username)
.NotEmpty() .NotEmpty()
.WithMessage("Username cannot be empty") .WithMessage("Username cannot be empty")
@@ -25,7 +25,7 @@ public class GetUserGroupDtoValidator : Validator<GetUserGroupDto>
RuleFor(x => x.Grade) RuleFor(x => x.Grade)
.NotEmpty() .NotEmpty()
.WithMessage("Grade cannot be empty"); .WithMessage("Grade cannot be empty");
RuleFor(x => x.Score) RuleFor(x => x.Score)
.NotEmpty() .NotEmpty()
.WithMessage("Score cannot be empty"); .WithMessage("Score cannot be empty");
@@ -15,7 +15,7 @@ public class GetRandomChallengeDtoValidator : Validator<GetRandomChallengeDto>
.WithMessage("Libelle cannot exceed 200 characters") .WithMessage("Libelle cannot exceed 200 characters")
.MinimumLength(2) .MinimumLength(2)
.WithMessage("Libelle must exceed 2 characters"); .WithMessage("Libelle must exceed 2 characters");
RuleFor(x => x.Duration) RuleFor(x => x.Duration)
.NotEmpty() .NotEmpty()
.WithMessage("Duration cannot be empty") .WithMessage("Duration cannot be empty")
@@ -44,7 +44,7 @@ public class CreateUserDtoValidator : Validator<CreateUserDto>
.NotEmpty() .NotEmpty()
.WithMessage("Password is required") .WithMessage("Password is required")
.MaximumLength(60) .MaximumLength(60)
.WithMessage("Password cannot exceed 60 characters") .WithMessage("Password cannot exceed 60 characters")
.MinimumLength(12) .MinimumLength(12)
.WithMessage("Password must exceed 12 characters"); .WithMessage("Password must exceed 12 characters");
} }
@@ -6,14 +6,14 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserChallengeDtoValidator : Validator<GetUserChallengeDto> public class GetUserChallengeDtoValidator : Validator<GetUserChallengeDto>
{ {
public GetUserChallengeDtoValidator() public GetUserChallengeDtoValidator()
{ {
RuleFor(x => x.ChallengeTitle) RuleFor(x => x.ChallengeTitle)
.NotEmpty() .NotEmpty()
.WithMessage("Challenge Title is required") .WithMessage("Challenge Title is required")
.MaximumLength(200) .MaximumLength(200)
.WithMessage("Challenge Title cannot exceed 200 characters"); .WithMessage("Challenge Title cannot exceed 200 characters");
RuleFor(x => x.ChallengeDescription) RuleFor(x => x.ChallengeDescription)
.NotEmpty() .NotEmpty()
.WithMessage("Challenge Description is required") .WithMessage("Challenge Description is required")
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto> public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
{ {
public GetUserDetailsDtoValidator() public GetUserDetailsDtoValidator()
{ {
RuleFor(x => x.FirstName) RuleFor(x => x.FirstName)
.NotEmpty() .NotEmpty()
@@ -15,7 +15,7 @@ public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
.WithMessage("First name cannot not exceed 50 characters") .WithMessage("First name cannot not exceed 50 characters")
.MinimumLength(50) .MinimumLength(50)
.WithMessage("First name must not exceed 50 characters"); .WithMessage("First name must not exceed 50 characters");
RuleFor(x => x.Name) RuleFor(x => x.Name)
.NotEmpty() .NotEmpty()
.WithMessage("Name is required") .WithMessage("Name is required")
@@ -43,7 +43,7 @@ public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
RuleFor(x => x.CreationDate) RuleFor(x => x.CreationDate)
.NotEmpty() .NotEmpty()
.WithMessage("CreationDate is required"); .WithMessage("CreationDate is required");
When(x => x.DesignationId is not null, () => When(x => x.DesignationId is not null, () =>
{ {
RuleFor(x => x.DesignationId) RuleFor(x => x.DesignationId)
@@ -6,14 +6,14 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserDtoValidator : Validator<GetUserDto> public class GetUserDtoValidator : Validator<GetUserDto>
{ {
public GetUserDtoValidator() { public GetUserDtoValidator()
{
RuleFor(x => x.Id) RuleFor(x => x.Id)
.NotEmpty() .NotEmpty()
.WithMessage("Id cannot be empty") .WithMessage("Id cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Id must be greater than 0"); .WithMessage("Id must be greater than 0");
RuleFor(x => x.FirstName) RuleFor(x => x.FirstName)
.NotEmpty() .NotEmpty()
.WithMessage("First name is required") .WithMessage("First name is required")
@@ -37,7 +37,7 @@ public class GetUserDtoValidator : Validator<GetUserDto>
.WithMessage("Username cannot exceed 50 characters") .WithMessage("Username cannot exceed 50 characters")
.MinimumLength(2) .MinimumLength(2)
.WithMessage("Username must exceed 2 characters"); .WithMessage("Username must exceed 2 characters");
When(x => x.DesignationId is not null, () => When(x => x.DesignationId is not null, () =>
{ {
RuleFor(x => x.DesignationId) RuleFor(x => x.DesignationId)
@@ -13,7 +13,7 @@ public class GetUserProofDtoValidator : Validator<GetUserProofDto>
.WithMessage("Id cannot be empty") .WithMessage("Id cannot be empty")
.GreaterThan(0) .GreaterThan(0)
.WithMessage("Id must be greater than 0"); .WithMessage("Id must be greater than 0");
RuleFor(x => x.Proof) RuleFor(x => x.Proof)
.NotEmpty() .NotEmpty()
.WithMessage("Proof cannot be empty"); .WithMessage("Proof cannot be empty");
@@ -6,30 +6,30 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserStatsDtoValidator : Validator<GetUserStatsDto> public class GetUserStatsDtoValidator : Validator<GetUserStatsDto>
{ {
public GetUserStatsDtoValidator() public GetUserStatsDtoValidator()
{ {
RuleFor(x => x.Score) RuleFor(x => x.Score)
.NotEmpty() .NotEmpty()
.WithMessage("Score is required"); .WithMessage("Score is required");
RuleFor(x => x.TotalWin) RuleFor(x => x.TotalWin)
.NotEmpty() .NotEmpty()
.WithMessage("Total win is required"); .WithMessage("Total win is required");
RuleFor(x=> x.TotalChallenge) RuleFor(x => x.TotalChallenge)
.NotEmpty() .NotEmpty()
.WithMessage("Total challenge is required"); .WithMessage("Total challenge is required");
RuleFor(x => x.TotalPodium) RuleFor(x => x.TotalPodium)
.NotEmpty() .NotEmpty()
.WithMessage("Total podium is required"); .WithMessage("Total podium is required");
RuleFor(x => x.TotalBonusChallenge) RuleFor(x => x.TotalBonusChallenge)
.NotEmpty() .NotEmpty()
.WithMessage("Total bonus is required"); .WithMessage("Total bonus is required");
RuleFor(x => x.Series) RuleFor(x => x.Series)
.NotEmpty() .NotEmpty()
.WithMessage("Series is required"); .WithMessage("Series is required");
} }
} }
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Users;
public class UpdateUserDtoValidator : Validator<UpdateUserDto> public class UpdateUserDtoValidator : Validator<UpdateUserDto>
{ {
public UpdateUserDtoValidator() public UpdateUserDtoValidator()
{ {
RuleFor(x => x.FirstName) RuleFor(x => x.FirstName)
.NotEmpty() .NotEmpty()
@@ -23,7 +23,7 @@ public class UpdateUserDtoValidator : Validator<UpdateUserDto>
.WithMessage("Name cannot exceed 50 characters") .WithMessage("Name cannot exceed 50 characters")
.MinimumLength(2) .MinimumLength(2)
.WithMessage("Name must exceed 2 characters"); .WithMessage("Name must exceed 2 characters");
RuleFor(x => x.Username) RuleFor(x => x.Username)
.NotEmpty() .NotEmpty()
.WithMessage("Username is required") .WithMessage("Username is required")