Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more DTO classes extensible. #11165

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,62 @@ public virtual IEnumerable<ValidationResult> Validate(ValidationContext validati

yield return new ValidationResult(
localizer[
"MaxResultCountExceededExceptionMessage",
"MaxResultCountExceededExceptionMessage",
nameof(MaxResultCount),
MaxMaxResultCount,
typeof(LimitedResultRequestDto).FullName,
MaxMaxResultCount,
typeof(LimitedResultRequestDto).FullName,
nameof(MaxMaxResultCount)
],
new[] { nameof(MaxResultCount) });
}
}
}
}

/// <summary>
/// Simply implements <see cref="ILimitedResultRequest"/>.
/// </summary>
[Serializable]
public class ExtensibleLimitedResultRequestDto : ExtensibleEntityDto, ILimitedResultRequest, IValidatableObject
{
/// <summary>
/// Default value: 10.
/// </summary>
public static int DefaultMaxResultCount { get; set; } = 10;

/// <summary>
/// Maximum possible value of the <see cref="MaxResultCount"/>.
/// Default value: 1,000.
/// </summary>
public static int MaxMaxResultCount { get; set; } = 1000;

/// <summary>
/// Maximum result count should be returned.
/// This is generally used to limit result count on paging.
/// </summary>
[Range(1, int.MaxValue)]
public virtual int MaxResultCount { get; set; } = DefaultMaxResultCount;

public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
foreach(var result in base.Validate(validationContext))
{
yield return result;
}

if (MaxResultCount > MaxMaxResultCount)
{
var localizer = validationContext.GetRequiredService<IStringLocalizer<AbpDddApplicationContractsResource>>();

yield return new ValidationResult(
localizer[
"MaxResultCountExceededExceptionMessage",
nameof(MaxResultCount),
MaxMaxResultCount,
typeof(ExtensibleLimitedResultRequestDto).FullName,
nameof(MaxMaxResultCount)
],
new[] { nameof(MaxResultCount) });
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Volo.Abp.ObjectExtending;

namespace Volo.Abp.Application.Dtos
{
Expand All @@ -19,7 +20,7 @@ public IReadOnlyList<T> Items
/// </summary>
public ListResultDto()
{

}

/// <summary>
Expand All @@ -31,4 +32,33 @@ public ListResultDto(IReadOnlyList<T> items)
Items = items;
}
}
}

[Serializable]
public class ExtensibleListResultDto<T> : ExtensibleObject, IListResult<T>
{
/// <inheritdoc />
public IReadOnlyList<T> Items
{
get { return _items ?? (_items = new List<T>()); }
set { _items = value; }
}
private IReadOnlyList<T> _items;

/// <summary>
/// Creates a new <see cref="ListResultDto{T}"/> object.
/// </summary>
public ExtensibleListResultDto()
{

}

/// <summary>
/// Creates a new <see cref="ListResultDto{T}"/> object.
/// </summary>
/// <param name="items">List of items</param>
public ExtensibleListResultDto(IReadOnlyList<T> items)
{
Items = items;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ public class PagedAndSortedResultRequestDto : PagedResultRequestDto, IPagedAndSo
{
public virtual string Sorting { get; set; }
}
}

/// <summary>
/// Simply implements <see cref="IPagedAndSortedResultRequest"/>.
/// </summary>
[Serializable]
public class ExtensiblePagedAndSortedResultRequestDto : ExtensiblePagedResultRequestDto, IPagedAndSortedResultRequest
{
public virtual string Sorting { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,34 @@ public PagedResultDto(long totalCount, IReadOnlyList<T> items)
TotalCount = totalCount;
}
}
}

/// <summary>
/// Implements <see cref="IPagedResult{T}"/>.
/// </summary>
/// <typeparam name="T">Type of the items in the <see cref="ListResultDto{T}.Items"/> list</typeparam>
[Serializable]
public class ExtensiblePagedResultDto<T> : ExtensibleListResultDto<T>, IPagedResult<T>
{
/// <inheritdoc />
public long TotalCount { get; set; } //TODO: Can be a long value..?

/// <summary>
/// Creates a new <see cref="PagedResultDto{T}"/> object.
/// </summary>
public ExtensiblePagedResultDto()
{

}

/// <summary>
/// Creates a new <see cref="PagedResultDto{T}"/> object.
/// </summary>
/// <param name="totalCount">Total count of Items</param>
/// <param name="items">List of items in current page</param>
public ExtensiblePagedResultDto(long totalCount, IReadOnlyList<T> items)
: base(items)
{
TotalCount = totalCount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ public class PagedResultRequestDto : LimitedResultRequestDto, IPagedResultReques
[Range(0, int.MaxValue)]
public virtual int SkipCount { get; set; }
}
}

/// <summary>
/// Simply implements <see cref="IPagedResultRequest"/>.
/// </summary>
[Serializable]
public class ExtensiblePagedResultRequestDto : ExtensibleLimitedResultRequestDto, IPagedResultRequest
{
[Range(0, int.MaxValue)]
public virtual int SkipCount { get; set; }
}
}