chore: init project
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using FluentValidation;
|
||||
using InboxIntel.Application.DTOs;
|
||||
using InboxIntel.Domain.Enums;
|
||||
|
||||
namespace InboxIntel.Application.Validation;
|
||||
|
||||
public class SearchRequestValidator : AbstractValidator<SearchRequestDto>
|
||||
{
|
||||
public SearchRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Page).GreaterThan(0);
|
||||
RuleFor(x => x.PageSize).InclusiveBetween(1, 200);
|
||||
RuleFor(x => x)
|
||||
.Must(x => x.From is null || x.To is null || x.From <= x.To)
|
||||
.WithMessage("'From' date must be on or before 'To' date.");
|
||||
}
|
||||
}
|
||||
|
||||
public class CleanupRequestValidator : AbstractValidator<CleanupRequestDto>
|
||||
{
|
||||
public CleanupRequestValidator()
|
||||
{
|
||||
RuleFor(x => x)
|
||||
.Must(x => (x.EmailIds is { Count: > 0 }) || !string.IsNullOrWhiteSpace(x.Query))
|
||||
.WithMessage("Provide either EmailIds or a Query to target emails.");
|
||||
|
||||
// Safety rule: destructive actions must be explicitly confirmed.
|
||||
RuleFor(x => x.Confirmed)
|
||||
.Equal(true)
|
||||
.When(x => x.Action is CleanupActionType.Trash or CleanupActionType.HardDelete)
|
||||
.WithMessage("Destructive actions require explicit confirmation.");
|
||||
|
||||
RuleFor(x => x.LabelId)
|
||||
.NotEmpty()
|
||||
.When(x => x.Action is CleanupActionType.AddLabel or CleanupActionType.RemoveLabel)
|
||||
.WithMessage("A LabelId is required for label actions.");
|
||||
}
|
||||
}
|
||||
|
||||
public class UnsubscribeRequestValidator : AbstractValidator<UnsubscribeRequestDto>
|
||||
{
|
||||
public UnsubscribeRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.ItemIds).NotEmpty();
|
||||
RuleFor(x => x.Confirmed).Equal(true)
|
||||
.WithMessage("Unsubscribe actions require explicit confirmation.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user