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

Dev/issue 1645 #5

Merged
merged 6 commits into from
Jun 30, 2020
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 @@ -13,14 +13,14 @@ namespace Microsoft.AspNet.OData.Builder
/// - ~/.../Function?p1=value (only allowed if the Function is the last url path segment).
/// </remarks>
/// </summary>
public class NonbindingParameterConfiguration : ParameterConfiguration
public class NonBindingParameterConfiguration : ParameterConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="NonbindingParameterConfiguration"/> class.
/// Initializes a new instance of the <see cref="NonBindingParameterConfiguration"/> class.
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="parameterType">The EDM type of the parameter.</param>
public NonbindingParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
public NonBindingParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
: base(name, parameterType)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ internal void SetBindingParameterImplementation(string name, IEdmTypeConfigurati
/// </summary>
public ParameterConfiguration AddParameter(string name, IEdmTypeConfiguration parameterType)
{
ParameterConfiguration parameter = new NonbindingParameterConfiguration(name, parameterType);
ParameterConfiguration parameter = new NonBindingParameterConfiguration(name, parameterType);
_parameters.Add(parameter);
return parameter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Builder\DynamicPropertyDictionaryAnnotation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\Expressions\AggregationBinder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\Expressions\ComputeBinder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\Expressions\TransformationBinderBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\Expressions\TransformationBinderBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\ApplyQueryOption.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\Expressions\DynamicTypeWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Query\Expressions\ExpressionBinderBase.cs" />
Expand Down Expand Up @@ -357,7 +357,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Builder\EntityTypeConfigurationOfTEntityType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\NavigationPropertyBindingConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\NavigationPropertyConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\NonbindingParameterConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\NonBindingParameterConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\ODataConventionModelBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\ODataModelBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Builder\ParameterConfiguration.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Microsoft.AspNet.OData.Query
[ODataQueryParameterBinding]
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Relies on many ODataLib classes.")]
public partial class ODataQueryOptions
: IODataQueryOptions
{
private static readonly MethodInfo _limitResultsGenericMethod = typeof(ODataQueryOptions).GetMethods(BindingFlags.Public | BindingFlags.Static)
.Single(mi => mi.Name == "LimitResults" && mi.ContainsGenericParameters && mi.GetParameters().Length == 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Http.Headers;
using Microsoft.AspNet.OData.Common;
using Microsoft.AspNet.OData.Formatter;
using Microsoft.AspNet.OData.Interfaces;

namespace Microsoft.AspNet.OData.Query
{
Expand All @@ -13,7 +14,9 @@ namespace Microsoft.AspNet.OData.Query
/// Currently this only supports $filter, $orderby, $top, $skip.
/// </summary>
[ODataQueryParameterBinding]
public partial class ODataQueryOptions<TEntity> : ODataQueryOptions
public partial class ODataQueryOptions<TEntity>
: ODataQueryOptions
, IODataQueryOptions<TEntity>
{
/// <summary>
/// Gets the <see cref="ETag{TEntity}"/> from IfMatch header.
Expand Down
149 changes: 149 additions & 0 deletions src/Microsoft.AspNetCore.OData/Interfaces/IODataQueryOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using Microsoft.AspNet.OData.Formatter;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNet.OData.Query.Validators;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Microsoft.AspNet.OData.Interfaces
{
/// <summary>
/// This defines a composite OData query options that can be used to perform query composition.
/// Currently this only supports $filter, $orderby, $top, $skip, and $count.
/// </summary>
public interface IODataQueryOptions
{
/// <summary>
/// Gets the given <see cref="ODataQueryContext"/>
/// </summary>
ODataQueryContext Context { get; }
/// <summary>
/// Gets the raw string of all the OData query options
/// </summary>
ODataRawQueryOptions RawValues { get; }
/// <summary>
/// Gets the <see cref="SelectExpandQueryOption"/>.
/// </summary>
SelectExpandQueryOption SelectExpand { get; }
/// <summary>
/// Gets the <see cref="ApplyQueryOption"/>.
/// </summary>
ApplyQueryOption Apply { get; }
/// <summary>
/// Gets the <see cref="FilterQueryOption"/>.
/// </summary>
FilterQueryOption Filter { get; }
/// <summary>
/// Gets the <see cref="OrderByQueryOption"/>.
/// </summary>
OrderByQueryOption OrderBy { get; }
/// <summary>
/// Gets the <see cref="SkipQueryOption"/>.
/// </summary>
SkipQueryOption Skip { get; }

/// <summary>
/// Gets the <see cref="SkipTokenQueryOption"/>.
/// </summary>
SkipTokenQueryOption SkipToken { get; }

/// <summary>
/// Gets the <see cref="TopQueryOption"/>.
/// </summary>
TopQueryOption Top { get; }

/// <summary>
/// Gets the <see cref="CountQueryOption"/>.
/// </summary>
CountQueryOption Count { get; }

/// <summary>
/// Gets or sets the query validator.
/// </summary>
ODataQueryValidator Validator { get; set; }

/// <summary>
/// Gets the <see cref="ETag"/> from IfMatch header.
/// </summary>
ETag IfMatch { get; }

/// <summary>
/// Gets the <see cref="ETag"/> from IfNoneMatch header.
/// </summary>
ETag IfNoneMatch { get; }

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
IQueryable ApplyTo(IQueryable query);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
IQueryable ApplyTo(IQueryable query, AllowedQueryOptions ignoreQueryOptions);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <param name="querySettings">The settings to use in query composition.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings, AllowedQueryOptions ignoreQueryOptions);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <param name="querySettings">The settings to use in query composition.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "These are simple conversion function and cannot be split up.")]
IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="entity">The original entity.</param>
/// <param name="querySettings">The <see cref="ODataQuerySettings"/> that contains all the query application related settings.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new entity after the $select and $expand query has been applied to.</returns>
/// <remarks>Only $select and $expand query options can be applied on single entities. This method throws if the query contains any other
/// query options.</remarks>
object ApplyTo(object entity, ODataQuerySettings querySettings, AllowedQueryOptions ignoreQueryOptions);

/// <summary>
/// Applies the query to the given entity using the given <see cref="ODataQuerySettings"/>.
/// </summary>
/// <param name="entity">The original entity.</param>
/// <param name="querySettings">The <see cref="ODataQuerySettings"/> that contains all the query application related settings.</param>
/// <returns>The new entity after the $select and $expand query has been applied to.</returns>
/// <remarks>Only $select and $expand query options can be applied on single entities. This method throws if the query contains any other
/// query options.</remarks>
object ApplyTo(object entity, ODataQuerySettings querySettings);

/// <summary>
/// Generates the Stable OrderBy query option based on the existing OrderBy and other query options.
/// </summary>
/// <returns>An order by query option that ensures stable ordering of the results.</returns>
OrderByQueryOption GenerateStableOrder();

/// <summary>
/// Check if the given query option is the supported query option.
/// </summary>
/// <param name="queryOptionName">The name of the query option.</param>
/// <returns>Returns <c>true</c> if the query option is the supported query option.</returns>
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Need lower case string here.")]
bool IsSupportedQueryOption(string queryOptionName);

/// <summary>
/// Validate all OData queries, including $skip, $top, $orderby and $filter, based on the given <paramref name="validationSettings"/>.
/// It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
void Validate(ODataValidationSettings validationSettings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNet.OData.Formatter;
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.AspNet.OData.Interfaces
{
/// <summary>
/// This defines a composite OData query options that can be used to perform query composition.
/// Currently this only supports $filter, $orderby, $top, $skip.
/// </summary>
public interface IODataQueryOptions<TEntity>
: IODataQueryOptions
{
/// <summary>
/// Gets the <see cref="ETag{TEntity}"/> from IfMatch header.
/// </summary>
new ETag<TEntity> IfMatch { get; }

/// <summary>
/// Gets the <see cref="ETag{TEntity}"/> from IfNoneMatch header.
/// </summary>
new ETag<TEntity> IfNoneMatch { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void NonbindingParameterConfigurationSupportsParameterTypeAs(Type type, b
edmTypeConfiguration = ((EnumTypeConfiguration)edmTypeConfiguration).GetNullableEnumTypeConfiguration();
}
}
NonbindingParameterConfiguration parameter = new NonbindingParameterConfiguration("name",
NonBindingParameterConfiguration parameter = new NonBindingParameterConfiguration("name",
edmTypeConfiguration);

// Assert
Expand Down Expand Up @@ -85,7 +85,7 @@ public void NonbindingParameterConfigurationSupportsParameterCollectionTypeAs(Ty
CollectionTypeConfiguration collectionType = new CollectionTypeConfiguration(elementTypeConfiguration,
typeof(IEnumerable<>).MakeGenericType(elementType));

NonbindingParameterConfiguration parameter = new NonbindingParameterConfiguration("name", collectionType);
NonBindingParameterConfiguration parameter = new NonBindingParameterConfiguration("name", collectionType);

// Assert
Assert.Equal(isNullable, parameter.Nullable);
Expand Down
Loading