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)
{
Group? group = await groupsRepository.SingleOrDefaultAsync(new GetGroupByIdSpec(req.Id), ct);
Group? group = await groupsRepository.SingleOrDefaultAsync(new GetGroupByIdSpec(req.Id), ct);
if (group is null)
{
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);
return;
}
List<GetProofDto> usersGroup = await userGroupsRepository.ProjectToListAsync<GetProofDto>(new GetUserGroupDetailsByIdSpec(req.Id), 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);
return;
}
if (member.Group!.StartedVote is null)
{
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);
return;
}
if (group.IsFinished)
{
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);
return;
}
group.StartedVote = DateTime.Now;
await groupsRepository.SaveChangesAsync(ct);
@@ -11,10 +11,10 @@ using Group = System.Text.RegularExpressions.Group;
namespace BeReadyBackend.Endpoints.Messages;
public class SendMessageEndpoint(
UserService userService,
GroupsRepository groupsRepository,
AutoMapper.IMapper mapper,
MessagesRepository messagesRepository,
UserService userService,
GroupsRepository groupsRepository,
AutoMapper.IMapper mapper,
MessagesRepository messagesRepository,
IHubContext<GroupHub> hubContext)
: Endpoint<CreateMessageDto>
{
@@ -37,7 +37,7 @@ public class SendMessageEndpoint(
await Send.StringAsync("Le groupe est fermé", 400, cancellation: ct);
return;
}
Message message = new();
mapper.Map(req, message);
message.UserId = userService.GetUserIdFromToken();
@@ -28,7 +28,7 @@ public class PatchProofEndpoint(
public override async Task HandleAsync(RandomChallengeProofRequest req, CancellationToken ct)
{
int userId = userService.GetUserIdFromToken();
RandomChallenge? randomChallenge = await randomChallengesRepository.SingleOrDefaultAsync(new GetRandomChallengeByIdSpec(req.RandomChallengeId), ct);
if (randomChallenge is null)
{
@@ -38,10 +38,10 @@ public class PatchProofEndpoint(
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;
}
UserRandomChallenge? userRandomChallenge =
await userRandomChallengesRepository.SingleOrDefaultAsync(new GetRandomChallengeByCriteriaSpec(req.RandomChallengeId, userId), ct);
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] public int Duration { get; set; }
[Required] public bool IsAlreadyPast { get; set; }
[Required] public DateTime? GeneratedAt { 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")
.MaximumLength(200)
.WithMessage("Description cannot contain more than 200 characters");
RuleFor(x => x.Label)
.NotEmpty()
.WithMessage("Label must be specified")
@@ -13,6 +13,5 @@ public class UnlockAchievementDtoValidator : Validator<UnlockAchievementDto>
.WithMessage("AchievementId cannot be empty")
.GreaterThan(0)
.WithMessage("AchievementId must be greater than 0");
}
}
@@ -4,7 +4,7 @@ using FluentValidation;
namespace BeReadyBackend.Validators.Auth;
public class LoginDtoValidator: Validator<LoginDto>
public class LoginDtoValidator : Validator<LoginDto>
{
public LoginDtoValidator()
{
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Friends;
public class GetFriendDtoValidator : Validator<GetFriendDto>
{
public GetFriendDtoValidator()
public GetFriendDtoValidator()
{
RuleFor(x => x.Username)
.NotEmpty()
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Friends;
public class GetFriendRequestDtoValidator : Validator<GetFriendDto>
{
public GetFriendRequestDtoValidator()
public GetFriendRequestDtoValidator()
{
RuleFor(x => x.Username)
.NotEmpty()
@@ -31,7 +31,7 @@ public class CreateGroupDtoValidator : Validator<CreateGroupDto>
.WithMessage("Description cannot exceed 200 characters")
.MinimumLength(2)
.WithMessage("Description must exceed 2 characters");
RuleFor(x => x.Duration)
.NotEmpty()
.WithMessage("Duration cannot be empty")
@@ -13,7 +13,7 @@ public class GetGroupDetailsDtoValidator : Validator<GetGroupDetailsDto>
.WithMessage("Id cannot be empty")
.GreaterThan(0)
.WithMessage("Id must be greater than zero");
RuleFor(x => x.Label)
.NotEmpty()
.WithMessage("Label cannot be empty")
@@ -41,7 +41,7 @@ public class GetGroupDetailsDtoValidator : Validator<GetGroupDetailsDto>
.WithMessage("Description cannot exceed 50 characters")
.MinimumLength(2)
.WithMessage("Description must exceed 2 characters");
RuleFor(x => x.Duration)
.NotEmpty()
.WithMessage("Duration cannot be empty")
@@ -13,7 +13,7 @@ public class GetGroupDtoValidator : Validator<GetGroupDto>
.WithMessage("Id cannot be empty")
.GreaterThan(0)
.WithMessage("Id must be greater than zero");
RuleFor(x => x.Label)
.NotEmpty()
.WithMessage("Label cannot be empty")
@@ -13,7 +13,7 @@ public class GetProofDtoValidator : Validator<GetProofDto>
.WithMessage("Id cannot be empty")
.GreaterThan(0)
.WithMessage("Id must be greater than 0");
RuleFor(x => x.Username)
.NotEmpty()
.WithMessage("Username cannot be empty")
@@ -25,7 +25,7 @@ public class GetProofDtoValidator : Validator<GetProofDto>
RuleFor(x => x.Proof)
.NotEmpty()
.WithMessage("Proof cannot be empty");
RuleFor(x => x.Score)
.NotEmpty()
.WithMessage("Score cannot be empty");
@@ -13,7 +13,7 @@ public class GetUserGroupDtoValidator : Validator<GetUserGroupDto>
.WithMessage("Id cannot be empty")
.GreaterThan(0)
.WithMessage("Id must be greater than 0");
RuleFor(x => x.Username)
.NotEmpty()
.WithMessage("Username cannot be empty")
@@ -25,7 +25,7 @@ public class GetUserGroupDtoValidator : Validator<GetUserGroupDto>
RuleFor(x => x.Grade)
.NotEmpty()
.WithMessage("Grade cannot be empty");
RuleFor(x => x.Score)
.NotEmpty()
.WithMessage("Score cannot be empty");
@@ -15,7 +15,7 @@ public class GetRandomChallengeDtoValidator : Validator<GetRandomChallengeDto>
.WithMessage("Libelle cannot exceed 200 characters")
.MinimumLength(2)
.WithMessage("Libelle must exceed 2 characters");
RuleFor(x => x.Duration)
.NotEmpty()
.WithMessage("Duration cannot be empty")
@@ -44,7 +44,7 @@ public class CreateUserDtoValidator : Validator<CreateUserDto>
.NotEmpty()
.WithMessage("Password is required")
.MaximumLength(60)
.WithMessage("Password cannot exceed 60 characters")
.WithMessage("Password cannot exceed 60 characters")
.MinimumLength(12)
.WithMessage("Password must exceed 12 characters");
}
@@ -6,14 +6,14 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserChallengeDtoValidator : Validator<GetUserChallengeDto>
{
public GetUserChallengeDtoValidator()
public GetUserChallengeDtoValidator()
{
RuleFor(x => x.ChallengeTitle)
.NotEmpty()
.WithMessage("Challenge Title is required")
.MaximumLength(200)
.WithMessage("Challenge Title cannot exceed 200 characters");
RuleFor(x => x.ChallengeDescription)
.NotEmpty()
.WithMessage("Challenge Description is required")
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
{
public GetUserDetailsDtoValidator()
public GetUserDetailsDtoValidator()
{
RuleFor(x => x.FirstName)
.NotEmpty()
@@ -15,7 +15,7 @@ public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
.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")
@@ -43,7 +43,7 @@ public class GetUserDetailsDtoValidator : Validator<GetUserDetailsDto>
RuleFor(x => x.CreationDate)
.NotEmpty()
.WithMessage("CreationDate is required");
When(x => x.DesignationId is not null, () =>
{
RuleFor(x => x.DesignationId)
@@ -6,14 +6,14 @@ namespace BeReadyBackend.Validators.Users;
public class GetUserDtoValidator : Validator<GetUserDto>
{
public GetUserDtoValidator() {
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")
@@ -37,7 +37,7 @@ public class GetUserDtoValidator : Validator<GetUserDto>
.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)
@@ -13,7 +13,7 @@ public class GetUserProofDtoValidator : Validator<GetUserProofDto>
.WithMessage("Id cannot be empty")
.GreaterThan(0)
.WithMessage("Id must be greater than 0");
RuleFor(x => x.Proof)
.NotEmpty()
.WithMessage("Proof cannot be empty");
@@ -6,30 +6,30 @@ 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");
}
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");
}
}
@@ -6,7 +6,7 @@ namespace BeReadyBackend.Validators.Users;
public class UpdateUserDtoValidator : Validator<UpdateUserDto>
{
public UpdateUserDtoValidator()
public UpdateUserDtoValidator()
{
RuleFor(x => x.FirstName)
.NotEmpty()
@@ -23,7 +23,7 @@ public class UpdateUserDtoValidator : Validator<UpdateUserDto>
.WithMessage("Name cannot exceed 50 characters")
.MinimumLength(2)
.WithMessage("Name must exceed 2 characters");
RuleFor(x => x.Username)
.NotEmpty()
.WithMessage("Username is required")