Files
CMS/src/CMSMicroservice.Application/ClubMembershipCQ/Queries/GetAllClubMemberships/GetAllClubMembershipsQueryValidator.cs
masoodafar-web fe66d478ee feat: Add ClubMembershipCQ - Phase 3 Application Layer
- Implemented 3 Commands with handlers and validators:
  * ActivateClubMembership: Create/reactivate membership
  * DeactivateClubMembership: Deactivate existing membership
  * AssignClubFeature: Assign features to club members

- Implemented 3 Queries with handlers, validators, and DTOs:
  * GetClubMembership: Retrieve single membership by UserId
  * GetAllClubMemberships: List with filtering and pagination
  * GetClubMembershipHistory: Audit trail with full history

- All operations include history tracking via ClubMembershipHistory
- Property names aligned with Domain entity definitions
- 21 new files, ~600 lines of code
- Build successful with 0 errors
2025-11-29 04:13:27 +03:30

31 lines
1.2 KiB
C#

namespace CMSMicroservice.Application.ClubMembershipCQ.Queries.GetAllClubMemberships;
public class GetAllClubMembershipsQueryValidator : AbstractValidator<GetAllClubMembershipsQuery>
{
public GetAllClubMembershipsQueryValidator()
{
RuleFor(x => x.Filter.UserId)
.GreaterThan(0)
.WithMessage("شناسه کاربر معتبر نیست")
.When(x => x.Filter?.UserId != null);
RuleFor(x => x.Filter.ActivationDateTo)
.GreaterThanOrEqualTo(x => x.Filter.ActivationDateFrom)
.WithMessage("تاریخ پایان باید بعد از تاریخ شروع باشد")
.When(x => x.Filter?.ActivationDateFrom != null && x.Filter?.ActivationDateTo != null);
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(
ValidationContext<GetAllClubMembershipsQuery>.CreateWithOptions(
(GetAllClubMembershipsQuery)model,
x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}