-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix use Guid in filter * feature ToRelativeUri * review use contaner model
- Loading branch information
Showing
21 changed files
with
329 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/OData.QueryBuilder/Builders/AbstractODataQueryBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using OData.QueryBuilder.Conventions.Constants; | ||
using OData.QueryBuilder.Options; | ||
using System; | ||
|
||
namespace OData.QueryBuilder.Builders | ||
{ | ||
public abstract class AbstractODataQueryBuilder | ||
{ | ||
protected readonly string _baseUrl; | ||
protected readonly ODataQueryBuilderOptions _odataQueryBuilderOptions; | ||
|
||
public AbstractODataQueryBuilder(ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
{ | ||
_baseUrl = string.Empty; | ||
_odataQueryBuilderOptions = odataQueryBuilderOptions ?? new ODataQueryBuilderOptions(); | ||
} | ||
|
||
public AbstractODataQueryBuilder(string baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
{ | ||
_baseUrl = !string.IsNullOrEmpty(baseUrl) ? | ||
$"{baseUrl.TrimEnd(QuerySeparators.Slash)}{QuerySeparators.Slash}" | ||
: | ||
throw new ArgumentException($"{nameof(baseUrl)} is null"); | ||
_odataQueryBuilderOptions = odataQueryBuilderOptions ?? new ODataQueryBuilderOptions(); | ||
} | ||
|
||
public AbstractODataQueryBuilder(Uri baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: this(baseUrl?.OriginalString, odataQueryBuilderOptions) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
using OData.QueryBuilder.Conventions.AddressingEntities.Resources; | ||
using OData.QueryBuilder.Conventions.Constants; | ||
using OData.QueryBuilder.Conventions.AddressingEntities; | ||
using OData.QueryBuilder.Conventions.AddressingEntities.Resources; | ||
using OData.QueryBuilder.Options; | ||
using System; | ||
using System.Text; | ||
|
||
namespace OData.QueryBuilder.Builders | ||
{ | ||
public class ODataQueryBuilder<TResource> : ODataResource<TResource> | ||
public sealed class ODataQueryBuilder : AbstractODataQueryBuilder | ||
{ | ||
public ODataQueryBuilder(Uri baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base($"{baseUrl.OriginalString.TrimEnd(QuerySeparators.Slash)}{QuerySeparators.Slash}", | ||
odataQueryBuilderOptions ?? new ODataQueryBuilderOptions()) | ||
public ODataQueryBuilder(ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base(odataQueryBuilderOptions) | ||
{ | ||
} | ||
|
||
public ODataQueryBuilder(string baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base($"{baseUrl.TrimEnd(QuerySeparators.Slash)}{QuerySeparators.Slash}", | ||
odataQueryBuilderOptions ?? new ODataQueryBuilderOptions()) | ||
: base(baseUrl, odataQueryBuilderOptions) | ||
{ | ||
} | ||
|
||
public ODataQueryBuilder(Uri baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base(baseUrl, odataQueryBuilderOptions) | ||
{ | ||
} | ||
|
||
public IAddressingEntries<TEntity> For<TEntity>(string resource) => | ||
new ODataResource(new StringBuilder(_baseUrl), _odataQueryBuilderOptions) | ||
.For<TEntity>(resource); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using OData.QueryBuilder.Conventions.AddressingEntities; | ||
using OData.QueryBuilder.Conventions.AddressingEntities.Resources; | ||
using OData.QueryBuilder.Options; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
|
||
namespace OData.QueryBuilder.Builders | ||
{ | ||
public sealed class ODataQueryBuilder<TResource> : AbstractODataQueryBuilder | ||
{ | ||
public ODataQueryBuilder(ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base(odataQueryBuilderOptions) | ||
{ | ||
} | ||
|
||
public ODataQueryBuilder(string baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base(baseUrl, odataQueryBuilderOptions) | ||
{ | ||
} | ||
|
||
public ODataQueryBuilder(Uri baseUrl, ODataQueryBuilderOptions odataQueryBuilderOptions = default) | ||
: base(baseUrl, odataQueryBuilderOptions) | ||
{ | ||
} | ||
|
||
public IAddressingEntries<TEntity> For<TEntity>(Expression<Func<TResource, object>> resource) => | ||
new ODataResource<TResource>(new StringBuilder(_baseUrl), _odataQueryBuilderOptions) | ||
.For<TEntity>(resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 3 additions & 6 deletions
9
src/OData.QueryBuilder/Conventions/AddressingEntities/Resources/IODataResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace OData.QueryBuilder.Conventions.AddressingEntities.Resources | ||
namespace OData.QueryBuilder.Conventions.AddressingEntities.Resources | ||
{ | ||
public interface IODataResource<TResource> | ||
internal interface IODataResource | ||
{ | ||
IAddressingEntries<TEntity> For<TEntity>(Expression<Func<TResource, object>> resource); | ||
IAddressingEntries<TEntity> For<TEntity>(string resource); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/OData.QueryBuilder/Conventions/AddressingEntities/Resources/IODataResource{T}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace OData.QueryBuilder.Conventions.AddressingEntities.Resources | ||
{ | ||
internal interface IODataResource<TResource> | ||
{ | ||
IAddressingEntries<TEntity> For<TEntity>(Expression<Func<TResource, object>> resource); | ||
} | ||
} |
19 changes: 8 additions & 11 deletions
19
src/OData.QueryBuilder/Conventions/AddressingEntities/Resources/ODataResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
using OData.QueryBuilder.Expressions.Visitors; | ||
using OData.QueryBuilder.Options; | ||
using System; | ||
using System.Linq.Expressions; | ||
using OData.QueryBuilder.Options; | ||
using System.Text; | ||
|
||
namespace OData.QueryBuilder.Conventions.AddressingEntities.Resources | ||
{ | ||
public class ODataResource<TResource> : IODataResource<TResource> | ||
internal class ODataResource : IODataResource | ||
{ | ||
private readonly ODataQueryBuilderOptions _odataQueryBuilderOptions; | ||
private readonly string _resourse; | ||
private readonly StringBuilder _stringBuilder; | ||
|
||
public ODataResource(string resourse, ODataQueryBuilderOptions odataQueryBuilderOptions) | ||
public ODataResource(StringBuilder stringBuilder, ODataQueryBuilderOptions odataQueryBuilderOptions) | ||
{ | ||
_odataQueryBuilderOptions = odataQueryBuilderOptions; | ||
_resourse = resourse; | ||
_stringBuilder = stringBuilder; | ||
} | ||
|
||
public IAddressingEntries<TEntity> For<TEntity>(Expression<Func<TResource, object>> resource) | ||
public IAddressingEntries<TEntity> For<TEntity>(string resource) | ||
{ | ||
var query = new ODataResourceExpressionVisitor().ToQuery(resource.Body); | ||
_stringBuilder.Append(resource); | ||
|
||
return new AddressingEntries<TEntity>(new StringBuilder($"{_resourse}{query}"), _odataQueryBuilderOptions); | ||
return new AddressingEntries<TEntity>(_stringBuilder, _odataQueryBuilderOptions); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/OData.QueryBuilder/Conventions/AddressingEntities/Resources/ODataResource{T}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using OData.QueryBuilder.Expressions.Visitors; | ||
using OData.QueryBuilder.Options; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
|
||
namespace OData.QueryBuilder.Conventions.AddressingEntities.Resources | ||
{ | ||
internal class ODataResource<TResource> : IODataResource<TResource> | ||
{ | ||
private readonly ODataQueryBuilderOptions _odataQueryBuilderOptions; | ||
private readonly StringBuilder _stringBuilder; | ||
|
||
public ODataResource(StringBuilder stringBuilder, ODataQueryBuilderOptions odataQueryBuilderOptions) | ||
{ | ||
_odataQueryBuilderOptions = odataQueryBuilderOptions; | ||
_stringBuilder = stringBuilder; | ||
} | ||
|
||
public IAddressingEntries<TEntity> For<TEntity>(Expression<Func<TResource, object>> resource) | ||
{ | ||
var query = new ODataResourceExpressionVisitor().ToQuery(resource.Body); | ||
|
||
_stringBuilder.Append(query); | ||
|
||
return new AddressingEntries<TEntity>(_stringBuilder, _odataQueryBuilderOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.