mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 18:11:10 +00:00
Implements tests for commit dfd979ec1e
This commit is contained in:
1 parent
d8adf3c1b6
commit
968061e89a
111 files changed
+19955
-292
No files matched your search
+8
-1
@@ -27,6 +27,13 @@ public static class GetMostConsumedRequestMapping
|
||||
PerPage = request.PerPage ?? 50
|
||||
};
|
||||
|
||||
return new GetMostConsumedQuery(targetUserId, request.LibraryId, request.MediaKind, request.FromUtc, request.ToUtc, paginationData);
|
||||
return new GetMostConsumedQuery(
|
||||
targetUserId,
|
||||
request.LibraryId,
|
||||
request.MediaKind,
|
||||
request.FromUtc,
|
||||
request.ToUtc,
|
||||
paginationData
|
||||
);
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -27,6 +27,13 @@ public static class GetRecentlyConsumedRequestMapping
|
||||
PerPage = request.PerPage ?? 50
|
||||
};
|
||||
|
||||
return new GetRecentlyConsumedQuery(targetUserId, request.LibraryId, request.MediaKind, request.FromUtc, request.ToUtc, paginationData);
|
||||
return new GetRecentlyConsumedQuery(
|
||||
targetUserId,
|
||||
request.LibraryId,
|
||||
request.MediaKind,
|
||||
request.FromUtc,
|
||||
request.ToUtc,
|
||||
paginationData
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
#endregion
|
||||
|
||||
@@ -258,6 +259,23 @@ public static class ValidatorUtilities
|
||||
return ruleBuilder.Must(value => value.HasValue && Enum.IsDefined(value.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a validation rule that ensures a textual enum value is either <see langword="null"/> or the name of a defined member of the specified
|
||||
/// enumeration type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only the member names of the enumeration are accepted, so a numeric value is rejected even when it is a defined member. A
|
||||
/// <see langword="null"/> value represents an omitted optional filter and passes.
|
||||
/// </remarks>
|
||||
/// <typeparam name="TRequest">The type of the request being validated.</typeparam>
|
||||
/// <typeparam name="TEnum">The type of the enumeration.</typeparam>
|
||||
/// <param name="ruleBuilder">The rule builder instance.</param>
|
||||
/// <returns>The current <see cref="IRuleBuilder{TRequest, TProperty}"/> instance for method chaining.</returns>
|
||||
public static IRuleBuilder<TRequest, string?> IsInEnum<TRequest, TEnum>(this IRuleBuilder<TRequest, string?> ruleBuilder) where TEnum : struct, Enum
|
||||
{
|
||||
return ruleBuilder.Must(value => value is null || Enum.GetNames<TEnum>().Contains(value, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a validation rule that ensures the string property does not exceed the specified maximum length.
|
||||
/// </summary>
|
||||
|
||||
+6
-8
@@ -1,7 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -11,13 +9,13 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetAllUsersConsumptio
|
||||
/// Query for getting the consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, or <see langword="null"/> when the range has no end.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}")]
|
||||
public record GetAllUsersConsumptionStatisticsQuery(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
) : IQuery;
|
||||
+5
-1
@@ -14,6 +14,7 @@ using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.V
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -78,10 +79,13 @@ public class GetAllUsersConsumptionStatisticsQueryHandler : IQueryHandler<GetAll
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
MediaKind? mediaKind = query.MediaKind is null ? null : Enum.Parse<MediaKind>(query.MediaKind, ignoreCase: true);
|
||||
DateTime? fromUtc = query.FromUtc is null ? null : DateTime.Parse(query.FromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
DateTime? toUtc = query.ToUtc is null ? null : DateTime.Parse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
|
||||
// This is the only statistics query that loads the records of every user, and it is reachable only through the admin check above.
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForAllUsersAsync(libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
.GetForAllUsersAsync(libraryId, mediaKind, fromUtc, toUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+33
-8
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetAllUsersConsumptionStatistics;
|
||||
@@ -23,18 +24,42 @@ public class GetAllUsersConsumptionStatisticsQueryValidator : AbstractValidator<
|
||||
(Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty))
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Only the member names of the media kind enumeration are accepted, so a numeric value that happens to parse as a kind is rejected.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind)
|
||||
.When(query => query.MediaKind is not null);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.IsInEnum<GetAllUsersConsumptionStatisticsQuery, MediaKind>()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null ||
|
||||
!string.Equals(mediaKind, nameof(MediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// A malformed bound, or an inverted range, would silently return no records, so both are rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.Must(fromUtc => fromUtc is null || DateTime.TryParse(
|
||||
fromUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.ToUtc)
|
||||
.Must(toUtc => toUtc is null || DateTime.TryParse(
|
||||
toUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) =>
|
||||
{
|
||||
if (fromUtc is null || query.ToUtc is null ||
|
||||
!DateTime.TryParse(fromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedFromUtc) ||
|
||||
!DateTime.TryParse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedToUtc))
|
||||
return true;
|
||||
return parsedFromUtc <= parsedToUtc;
|
||||
})
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,7 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -12,14 +10,14 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetConsumptionStatist
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user whose statistics are retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, or <see langword="null"/> when the range has no end.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetConsumptionStatisticsQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
) : IQuery;
|
||||
+5
-1
@@ -15,6 +15,7 @@ using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.V
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -81,10 +82,13 @@ public class GetConsumptionStatisticsQueryHandler : IQueryHandler<GetConsumption
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
MediaKind? mediaKind = query.MediaKind is null ? null : Enum.Parse<MediaKind>(query.MediaKind, ignoreCase: true);
|
||||
DateTime? fromUtc = query.FromUtc is null ? null : DateTime.Parse(query.FromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
DateTime? toUtc = query.ToUtc is null ? null : DateTime.Parse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
|
||||
// The handlers aggregate the records themselves; the repository only binds the filters and returns the records without tracking.
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
.GetForUserAsync(targetUserId, libraryId, mediaKind, fromUtc, toUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+33
-8
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetConsumptionStatistics;
|
||||
@@ -29,18 +30,42 @@ public class GetConsumptionStatisticsQueryValidator : AbstractValidator<GetConsu
|
||||
(Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty))
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Only the member names of the media kind enumeration are accepted, so a numeric value that happens to parse as a kind is rejected.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind)
|
||||
.When(query => query.MediaKind is not null);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.IsInEnum<GetConsumptionStatisticsQuery, MediaKind>()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null ||
|
||||
!string.Equals(mediaKind, nameof(MediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// A malformed bound, or an inverted range, would silently return no records, so both are rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.Must(fromUtc => fromUtc is null || DateTime.TryParse(
|
||||
fromUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.ToUtc)
|
||||
.Must(toUtc => toUtc is null || DateTime.TryParse(
|
||||
toUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) =>
|
||||
{
|
||||
if (fromUtc is null || query.ToUtc is null ||
|
||||
!DateTime.TryParse(fromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedFromUtc) ||
|
||||
!DateTime.TryParse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedToUtc))
|
||||
return true;
|
||||
return parsedFromUtc <= parsedToUtc;
|
||||
})
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,8 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -13,16 +11,16 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetMostConsumed;
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user whose history is retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the history to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data. When <see langword="null"/>, every matching item is returned; when present, its requested page is returned.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetMostConsumedQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc,
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc,
|
||||
PaginationDataDto? PaginationData
|
||||
) : IQuery;
|
||||
+5
-1
@@ -25,6 +25,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -91,9 +92,12 @@ public class GetMostConsumedQueryHandler : IQueryHandler<GetMostConsumedQuery, R
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
MediaKind? mediaKind = query.MediaKind is null ? null : Enum.Parse<MediaKind>(query.MediaKind, ignoreCase: true);
|
||||
DateTime? fromUtc = query.FromUtc is null ? null : DateTime.Parse(query.FromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
DateTime? toUtc = query.ToUtc is null ? null : DateTime.Parse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
.GetForUserAsync(targetUserId, libraryId, mediaKind, fromUtc, toUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+33
-8
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetMostConsumed;
|
||||
@@ -29,18 +30,42 @@ public class GetMostConsumedQueryValidator : AbstractValidator<GetMostConsumedQu
|
||||
(Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty))
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Only the member names of the media kind enumeration are accepted, so a numeric value that happens to parse as a kind is rejected.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind)
|
||||
.When(query => query.MediaKind is not null);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.IsInEnum<GetMostConsumedQuery, MediaKind>()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null ||
|
||||
!string.Equals(mediaKind, nameof(MediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// A malformed bound, or an inverted range, would silently return no records, so both are rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.Must(fromUtc => fromUtc is null || DateTime.TryParse(
|
||||
fromUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.ToUtc)
|
||||
.Must(toUtc => toUtc is null || DateTime.TryParse(
|
||||
toUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) =>
|
||||
{
|
||||
if (fromUtc is null || query.ToUtc is null ||
|
||||
!DateTime.TryParse(fromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedFromUtc) ||
|
||||
!DateTime.TryParse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedToUtc))
|
||||
return true;
|
||||
return parsedFromUtc <= parsedToUtc;
|
||||
})
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,8 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -13,16 +11,16 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetRecentlyConsumed;
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user whose history is retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the history to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data. When <see langword="null"/>, every matching item is returned; when present, its requested page is returned.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetRecentlyConsumedQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc,
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc,
|
||||
PaginationDataDto? PaginationData
|
||||
) : IQuery;
|
||||
+5
-1
@@ -25,6 +25,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -91,9 +92,12 @@ public class GetRecentlyConsumedQueryHandler : IQueryHandler<GetRecentlyConsumed
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
MediaKind? mediaKind = query.MediaKind is null ? null : Enum.Parse<MediaKind>(query.MediaKind, ignoreCase: true);
|
||||
DateTime? fromUtc = query.FromUtc is null ? null : DateTime.Parse(query.FromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
DateTime? toUtc = query.ToUtc is null ? null : DateTime.Parse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
.GetForUserAsync(targetUserId, libraryId, mediaKind, fromUtc, toUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+33
-8
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetRecentlyConsumed;
|
||||
@@ -29,18 +30,42 @@ public class GetRecentlyConsumedQueryValidator : AbstractValidator<GetRecentlyCo
|
||||
(Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty))
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Only the member names of the media kind enumeration are accepted, so a numeric value that happens to parse as a kind is rejected.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind)
|
||||
.When(query => query.MediaKind is not null);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.IsInEnum<GetRecentlyConsumedQuery, MediaKind>()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null ||
|
||||
!string.Equals(mediaKind, nameof(MediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// A malformed bound, or an inverted range, would silently return no records, so both are rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.Must(fromUtc => fromUtc is null || DateTime.TryParse(
|
||||
fromUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.ToUtc)
|
||||
.Must(toUtc => toUtc is null || DateTime.TryParse(
|
||||
toUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) =>
|
||||
{
|
||||
if (fromUtc is null || query.ToUtc is null ||
|
||||
!DateTime.TryParse(fromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedFromUtc) ||
|
||||
!DateTime.TryParse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedToUtc))
|
||||
return true;
|
||||
return parsedFromUtc <= parsedToUtc;
|
||||
})
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,7 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -12,14 +10,14 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetTagConsumption;
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user whose statistics are retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, or <see langword="null"/> when the range has no end.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetTagConsumptionQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
) : IQuery;
|
||||
+5
-1
@@ -17,6 +17,7 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -83,9 +84,12 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
MediaKind? mediaKind = query.MediaKind is null ? null : Enum.Parse<MediaKind>(query.MediaKind, ignoreCase: true);
|
||||
DateTime? fromUtc = query.FromUtc is null ? null : DateTime.Parse(query.FromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
DateTime? toUtc = query.ToUtc is null ? null : DateTime.Parse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
|
||||
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
.GetForUserAsync(targetUserId, libraryId, mediaKind, fromUtc, toUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+33
-8
@@ -4,6 +4,7 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetTagConsumption;
|
||||
@@ -29,18 +30,42 @@ public class GetTagConsumptionQueryValidator : AbstractValidator<GetTagConsumpti
|
||||
(Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty))
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Only the member names of the media kind enumeration are accepted, so a numeric value that happens to parse as a kind is rejected.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind)
|
||||
.When(query => query.MediaKind is not null);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.IsInEnum<GetTagConsumptionQuery, MediaKind>()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null ||
|
||||
!string.Equals(mediaKind, nameof(MediaKind.None), StringComparison.OrdinalIgnoreCase))
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// A malformed bound, or an inverted range, would silently return no records, so both are rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.Must(fromUtc => fromUtc is null || DateTime.TryParse(
|
||||
fromUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.ToUtc)
|
||||
.Must(toUtc => toUtc is null || DateTime.TryParse(
|
||||
toUtc,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out _))
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) =>
|
||||
{
|
||||
if (fromUtc is null || query.ToUtc is null ||
|
||||
!DateTime.TryParse(fromUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedFromUtc) ||
|
||||
!DateTime.TryParse(query.ToUtc, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime parsedToUtc))
|
||||
return true;
|
||||
return parsedFromUtc <= parsedToUtc;
|
||||
})
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -10,13 +8,13 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// Represents a request for getting the consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, as a text value. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, as a text value. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
public sealed record GetAllUsersConsumptionStatisticsRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
);
|
||||
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -10,13 +8,13 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// Represents a request for getting the consumption statistics of a user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, as a text value. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, as a text value. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
public sealed record GetConsumptionStatisticsRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
);
|
||||
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -10,17 +8,17 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// Represents a request for getting a window of the most consumed media items of a user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="CurrentPage">The one based page of media items to return. Optional.</param>
|
||||
/// <param name="PerPage">The number of media items per page. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, as a text value. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, as a text value. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
|
||||
public sealed record GetMostConsumedRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
string? MediaKind,
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
);
|
||||
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -10,17 +8,17 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// Represents a request for getting a window of the recently consumed media items of a user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="CurrentPage">The one based page of media items to return. Optional.</param>
|
||||
/// <param name="PerPage">The number of media items per page. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, as a text value. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, as a text value. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
|
||||
public sealed record GetRecentlyConsumedRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
string? MediaKind,
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
);
|
||||
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -10,13 +8,13 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// Represents a request for getting the consumption statistics of the tags of a user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="MediaKind">The name of the kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, in UTC, as a text value. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, in UTC, as a text value. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
public sealed record GetTagConsumptionRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
string? MediaKind,
|
||||
string? FromUtc,
|
||||
string? ToUtc
|
||||
);
|
||||
+3
-3
@@ -27,12 +27,12 @@ public class GetAllUsersConsumptionStatisticsEndpointSummary : Summary<GetAllUse
|
||||
ExampleRequest = new GetAllUsersConsumptionStatisticsRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: null,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the statistics to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
|
||||
|
||||
+3
-3
@@ -27,12 +27,12 @@ public class GetConsumptionStatisticsEndpointSummary : Summary<GetConsumptionSta
|
||||
ExampleRequest = new GetConsumptionStatisticsRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: null,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the statistics to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
|
||||
|
||||
+3
-3
@@ -27,13 +27,13 @@ public class GetUserConsumptionStatisticsEndpointSummary : Summary<GetUserConsum
|
||||
ExampleRequest = new GetConsumptionStatisticsRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: null,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
Params["userId"] = "The Id of the user whose statistics are retrieved. An Admin can name any user; a regular user can only name themselves.";
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the statistics to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
|
||||
|
||||
+4
-4
@@ -27,15 +27,15 @@ public class GetMostConsumedEndpointSummary : Summary<GetMostConsumedEndpoint, G
|
||||
|
||||
ExampleRequest = new GetMostConsumedRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
MediaKind: nameof(MediaKind.MusicTrack),
|
||||
CurrentPage: 1,
|
||||
PerPage: 50,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the history to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
|
||||
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
|
||||
+4
-4
@@ -27,16 +27,16 @@ public class GetUserMostConsumedEndpointSummary : Summary<GetUserMostConsumedEnd
|
||||
|
||||
ExampleRequest = new GetMostConsumedRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
MediaKind: nameof(MediaKind.MusicTrack),
|
||||
CurrentPage: 1,
|
||||
PerPage: 50,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
Params["userId"] = "The Id of the user whose history is retrieved. An Admin can name any user; a regular user can only name themselves.";
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the history to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
|
||||
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
|
||||
+4
-4
@@ -27,15 +27,15 @@ public class GetRecentlyConsumedEndpointSummary : Summary<GetRecentlyConsumedEnd
|
||||
|
||||
ExampleRequest = new GetRecentlyConsumedRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
MediaKind: nameof(MediaKind.MusicTrack),
|
||||
CurrentPage: 1,
|
||||
PerPage: 50,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the history to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
|
||||
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
|
||||
+4
-4
@@ -27,16 +27,16 @@ public class GetUserRecentlyConsumedEndpointSummary : Summary<GetUserRecentlyCon
|
||||
|
||||
ExampleRequest = new GetRecentlyConsumedRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
MediaKind: nameof(MediaKind.MusicTrack),
|
||||
CurrentPage: 1,
|
||||
PerPage: 50,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
Params["userId"] = "The Id of the user whose history is retrieved. An Admin can name any user; a regular user can only name themselves.";
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the history to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
|
||||
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
|
||||
+3
-3
@@ -26,12 +26,12 @@ public class GetTagConsumptionEndpointSummary : Summary<GetTagConsumptionEndpoin
|
||||
ExampleRequest = new GetTagConsumptionRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: null,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the statistics to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
|
||||
|
||||
+3
-3
@@ -26,13 +26,13 @@ public class GetUserTagConsumptionEndpointSummary : Summary<GetUserTagConsumptio
|
||||
ExampleRequest = new GetTagConsumptionRequest(
|
||||
LibraryId: null,
|
||||
MediaKind: null,
|
||||
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
|
||||
FromUtc: "2026-10-01T00:00:00Z",
|
||||
ToUtc: "2026-10-31T23:59:59Z"
|
||||
);
|
||||
|
||||
Params["userId"] = "The Id of the user whose statistics are retrieved. An Admin can name any user; a regular user can only name themselves.";
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
|
||||
RequestParam(request => request.MediaKind, "The name of the kind of media to restrict the statistics to. Optional. Only the member names of the media kind enumeration are accepted.");
|
||||
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
|
||||
|
||||
Reference in new issue
Block a user