Skip to content

Commit

Permalink
CODE RUB: Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdutoit authored Oct 5, 2024
1 parent 39f6e48 commit aee1801
Showing 1 changed file with 55 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,38 @@ private async ValueTask ValidateContributionOnAddAsync(Contribution contribution
ValidateContributionIsNotNull(contribution);

Validate(
(Rule: await IsInvalidAsync(contribution.Id), Parameter: nameof(Contribution.Id)),
(Rule: await IsInvalidAsync(contribution.Id),
Parameter: nameof(Contribution.Id)),

(Rule: await IsInvalidAsync(contribution.RepositoryId), Parameter:
nameof(Contribution.RepositoryId)),
(Rule: await IsInvalidAsync(contribution.RepositoryId),
Parameter: nameof(Contribution.RepositoryId)),

(Rule: await IsInvalidAsync(contribution.ContributorId), Parameter:
nameof(Contribution.ContributorId)),
(Rule: await IsInvalidAsync(contribution.ContributorId),
Parameter: nameof(Contribution.ContributorId)),

(Rule: await IsInvalidAsync(contribution.ContributionTypeId),
Parameter: nameof(Contribution.ContributionTypeId)),

(Rule: await IsInvalidAsync(contribution.ExternalId), Parameter:
nameof(Contribution.ExternalId)),
(Rule: await IsInvalidAsync(contribution.ExternalId),
Parameter: nameof(Contribution.ExternalId)),

(Rule: await IsInvalidAsync(contribution.Title), Parameter:
nameof(Contribution.Title)),
(Rule: await IsInvalidAsync(contribution.Title),
Parameter: nameof(Contribution.Title)),

(Rule: await IsInvalidAsync(contribution.CreatedBy), Parameter:
nameof(Contribution.CreatedBy)),
(Rule: await IsInvalidAsync(contribution.CreatedBy),
Parameter: nameof(Contribution.CreatedBy)),

(Rule: await IsInvalidAsync(contribution.CreatedDate), Parameter:
nameof(Contribution.CreatedDate)),
(Rule: await IsInvalidAsync(contribution.CreatedDate),
Parameter: nameof(Contribution.CreatedDate)),

(Rule: await IsInvalidAsync(contribution.UpdatedBy), Parameter:
nameof(Contribution.UpdatedBy)),
(Rule: await IsInvalidAsync(contribution.UpdatedBy),
Parameter: nameof(Contribution.UpdatedBy)),

(Rule: await IsInvalidAsync(contribution.UpdatedDate), Parameter:
nameof(Contribution.UpdatedDate)),
(Rule: await IsInvalidAsync(contribution.UpdatedDate),
Parameter: nameof(Contribution.UpdatedDate)),

(Rule: await IsInvalidLengthAsync(contribution.Title, 255), Parameter:
nameof(Contribution.Title)),
(Rule: await IsInvalidLengthAsync(contribution.Title, 255),
Parameter: nameof(Contribution.Title)),

(Rule: await IsInvalidLengthAsync(contribution.ExternalId, 255),
Parameter: nameof(Contribution.ExternalId)),
Expand Down Expand Up @@ -76,35 +77,35 @@ private async ValueTask ValidateContributionOnModifyAsync(Contribution contribut
Validate(
(Rule: await IsInvalidAsync(contribution.Id), Parameter: nameof(Contribution.Id)),

(Rule: await IsInvalidAsync(contribution.RepositoryId), Parameter:
nameof(Contribution.RepositoryId)),
(Rule: await IsInvalidAsync(contribution.RepositoryId),
Parameter: nameof(Contribution.RepositoryId)),

(Rule: await IsInvalidAsync(contribution.ContributorId), Parameter:
nameof(Contribution.ContributorId)),
(Rule: await IsInvalidAsync(contribution.ContributorId),
Parameter: nameof(Contribution.ContributorId)),

(Rule: await IsInvalidAsync(contribution.ContributionTypeId),
Parameter: nameof(Contribution.ContributionTypeId)),

(Rule: await IsInvalidAsync(contribution.ExternalId), Parameter:
nameof(Contribution.ExternalId)),
(Rule: await IsInvalidAsync(contribution.ExternalId),
Parameter: nameof(Contribution.ExternalId)),

(Rule: await IsInvalidAsync(contribution.Title), Parameter:
nameof(Contribution.Title)),
(Rule: await IsInvalidAsync(contribution.Title),
Parameter: nameof(Contribution.Title)),

(Rule: await IsInvalidAsync(contribution.CreatedBy), Parameter:
nameof(Contribution.CreatedBy)),
(Rule: await IsInvalidAsync(contribution.CreatedBy),
Parameter: nameof(Contribution.CreatedBy)),

(Rule: await IsInvalidAsync(contribution.CreatedDate), Parameter:
nameof(Contribution.CreatedDate)),
(Rule: await IsInvalidAsync(contribution.CreatedDate),
Parameter: nameof(Contribution.CreatedDate)),

(Rule: await IsInvalidAsync(contribution.UpdatedBy), Parameter:
nameof(Contribution.UpdatedBy)),
(Rule: await IsInvalidAsync(contribution.UpdatedBy),
Parameter: nameof(Contribution.UpdatedBy)),

(Rule: await IsInvalidAsync(contribution.UpdatedDate), Parameter:
nameof(Contribution.UpdatedDate)),
(Rule: await IsInvalidAsync(contribution.UpdatedDate),
Parameter: nameof(Contribution.UpdatedDate)),

(Rule: await IsInvalidLengthAsync(contribution.Title, 255), Parameter:
nameof(Contribution.Title)),
(Rule: await IsInvalidLengthAsync(contribution.Title, 255),
Parameter: nameof(Contribution.Title)),

(Rule: await IsInvalidLengthAsync(contribution.ExternalId, 255),
Parameter: nameof(Contribution.ExternalId)),
Expand All @@ -116,7 +117,8 @@ private async ValueTask ValidateContributionOnModifyAsync(Contribution contribut

Parameter: nameof(Contribution.UpdatedDate)),

(Rule: await IsNotRecentAsync(contribution.UpdatedDate), Parameter: nameof(Contribution.UpdatedDate)));
(Rule: await IsNotRecentAsync(contribution.UpdatedDate),
Parameter: nameof(Contribution.UpdatedDate)));
}

private async ValueTask<dynamic> IsNotRecentAsync(DateTimeOffset date)
Expand Down Expand Up @@ -186,22 +188,22 @@ private static async ValueTask<bool> IsExceedingLengthAsync(string text, int max
(text ?? string.Empty).Length > maxLength;

private static async ValueTask<dynamic> IsSameAsync(
DateTimeOffset firstDate,
DateTimeOffset secondDate,
string secondDateName) => new
{
Condition = firstDate == secondDate,
Message = $"Date is the same as {secondDateName}"
};
DateTimeOffset firstDate,
DateTimeOffset secondDate,
string secondDateName) => new
{
Condition = firstDate == secondDate,
Message = $"Date is the same as {secondDateName}"
};

private static async ValueTask<dynamic> IsNotSameAsync(
DateTimeOffset firstDate,
DateTimeOffset secondDate,
string secondDateName) => new
{
Condition = firstDate != secondDate,
Message = $"Date is not the same as {secondDateName}"
};
DateTimeOffset firstDate,
DateTimeOffset secondDate,
string secondDateName) => new
{
Condition = firstDate != secondDate,
Message = $"Date is not the same as {secondDateName}"
};

private static async ValueTask<dynamic> IsNotSameAsync(
string first,
Expand All @@ -213,7 +215,7 @@ private static async ValueTask<dynamic> IsNotSameAsync(
};

private static async ValueTask ValidateContributionIdAsync(Guid contributionId) =>
Validate((Rule: await IsInvalidAsync(contributionId), Parameter: nameof(Contribution.Id)));
Validate((Rule: await IsInvalidAsync(contributionId), Parameter: nameof(Contribution.Id)));

private static async ValueTask ValidateStorageContributionAsync(Contribution maybeContribution, Guid id)
{
Expand Down

0 comments on commit aee1801

Please sign in to comment.