Skip to content

Commit

Permalink
Merge pull request #17 from ZEXSM/feature/setting-version-package
Browse files Browse the repository at this point in the history
#travis#readme
  • Loading branch information
ZEXSM authored Aug 18, 2019
2 parents 8ef5079 + da77153 commit ca80536
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 56 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ branches:
only:
- master
before_script:
- dotnet restore
- dotnet restore
script:
- dotnet build
- dotnet test ./test/OData.QueryBuilder.Test -c $CONFIGURATION -f netcoreapp2.1
Expand All @@ -18,13 +18,17 @@ after_success:
- cd src/OData.QueryBuilder && dotnet minicover uninstrument --workdir ../../coverage && dotnet minicover report --workdir ../../coverage && dotnet minicover coverallsreport --workdir ../../coverage --root-path ../../ --output "coveralls.json" --service-name "travis-ci" --service-job-id $TRAVIS_JOB_ID && cd ../../
before_deploy:
- git checkout origin/master && git fetch && git remote set-url origin https://${GITHUB_OAUTH_TOKEN}@github.com/ZEXSM/OData.QueryBuilder.git
- export LAST_TAG=$(echo $(git describe --tags $(git rev-list --tags --max-count=1)) | cut -d'v' -f 2)
- export CURRENT_TAG=$(echo $LAST_TAG | cut -d. -f 1).$(echo $LAST_TAG | cut -d. -f 2).$(($(echo $LAST_TAG | cut -d. -f 3)+1))
- export PACKAGE_VERSION=${CURRENT_TAG:-$DEFAULT_PACKAGE_VERSION}
- git tag v$PACKAGE_VERSION && git push origin v$PACKAGE_VERSION
- PR_TITLE=$(git log -1 --pretty='%f')
- FEATURE=$([[ $PR_TITLE == 'feature' ]] && echo 1 || echo 0)
- RELEASE=$([[ $PR_TITLE == 'release' ]] && echo 1 || echo 0)
- LAST_TAG=$(echo $(git describe --tags $(git rev-list --tags --max-count=1)) | cut -d'v' -f 2)
- export CURRENT_TAG=$(($(echo $LAST_TAG | cut -d. -f 1)+$RELEASE)).$(($(echo $LAST_TAG | cut -d. -f 2)+$FEATURE)).$(($(echo $LAST_TAG | cut -d. -f 3)+1))
- PACKAGE_VERSION=${CURRENT_TAG:-$DEFAULT_PACKAGE_VERSION}
- git tag v$PACKAGE_VERSION && git push origin v$PACKAGE_VERSION
- dotnet pack -c $CONFIGURATION -p:PackageVersion=$PACKAGE_VERSION
deploy:
provider: releases
name: v$CURRENT_TAG
api_key: $GITHUB_OAUTH_TOKEN
skip_cleanup: true
repo: ZEXSM/OData.QueryBuilder
Expand Down
238 changes: 192 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Library provides linq syntax and allows you to build OData queries based on the
* Support `OData` operator `IN`

## Installation
To install `OData.QueryBuilder` from` Visual Studio`, find `OData.QueryBuilder` in the` NuGet` package manager user interface or enter the following command in the package manager console:
To install `OData.QueryBuilder` from `Visual Studio`, find `OData.QueryBuilder` in the `NuGet` package manager user interface or enter the following command in the package manager console:
```
Install-Package OData.QueryBuilder -Version 1.0.0
```
Expand Down Expand Up @@ -41,65 +41,211 @@ dotnet add -v 1.0.0 OData.QueryBuilder
3. Select request type

The builder allows you to build queries on the key and the list:
* ByKey(<Key>)
* Expand
* Select
* ToUri
* ByList()
* Expand
* Filter
* Select
* OrderBy
* OrderByDescending
* Top
* Skip
* Count
* ToUri
* [ByKey](#ByKey)
* [Expand](#Expand)
* [Filter](#Filter)
* [Select](#Select)
* [Select](#Select)
* [ByList](#ByList)
* [Expand](#Expand)
* [Filter](#Filter)
* [Select](#Select)
* [Filter](#Filter)
* [Select](#Select)
* [OrderBy](#OrderBy)
* [OrderByDescending](#OrderByDescending)
* [Top](#Top)
* [Skip](#Skip)
* [Count](#Count)
4. Get a Uri request from the builder
```csharp
odataQueryBuilder.ToUri()
```

## Examples

#### By key
1. Key request with a simple `Expand`
## <a name="ByKey"/> ByKey
```csharp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(s => s.ODataKind)
.ToUri();
.ToUri()
```
> http://mock/odata/ODataType(223123123)?$expand=ODataKind
2. Key request with nested `Expand` и `Select`
> http://mock/odata/ODataType(223123123)
```csharp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey(223123123)
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKind)
.Expand(ff => ff.For<ODataCodeEntity>(s => s.ODataCode)
.Select(s => s.IdCode));
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
})
.Select(s => new { s.IdType, s.Sum })
.ToUri();
```
> http://mock/odata/ODataType(223123123)?$expand=ODataKind($expand=ODataCode($select=IdCode)),ODataKindNew($select=IdKind),ODataKindNew($select=IdKind)&$select=IdType,Sum
#### By list
1. Query list with a simple `Expand`
.ByKey("223123123")
.ToUri()
```
> http://mock/odata/ODataType("223123123")
## <a name="ByList"/> ByList
```csharp
var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Expand(s => new { s.ODataKind })
.ToUri();
.ToUri()
```
> http://mock/odata/ODataType
## <a name="Select"/> Select
```csharp
.Select(s => s.Id)
```
> $select=Id
```csharp
.Select(s => new { s.Id, s.Sum, s.Type })
```
> $select=Id,Sum,Type
## <a name="Expand"/> Expand
```csharp
.Expand(s => s.BaseType)
```
> $expand=BaseType
```csharp
.Expand(s => new { s.BaseType, s.ODataKind })
```
> $expand=BaseType,ODataKind
```csharp
.Expand(f =>
{
f.For<ODataKindEntity>(s => s.ODataKind)
.Expand(s=> s.For<ODataCodeEntity>(s => s.ODataCode)
.Filter(s => s.IdKind == 1)
.Select(s => s.IdCode));
f.For<ODataKindEntity>(s => s.ODataKindNew)
.Select(s => s.IdKind);
})
```
> $expand=ODataKind($expand=ODataCode($filter=IdKind eq 1;$select=IdCode)),ODataKindNew($select=IdKind)
## <a name="Filter"/> Filter
```csharp
.Filter(s => s.ODataKind.ODataCode.IdCode >= 3 || s.IdType == 5)
```
> $filter=ODataKind/ODataCode/IdCode ge 3 or IdType eq 5
```csharp
private static string IdCodeStatic => "testCode";
...
var constValue = "3";
.Filter(s =>
s.ODataKind.ODataCode.Code == constValue || s.ODataKind.ODataCode.Code == "5"
&& s.ODataKind.ODataCode.Code == IdCodeStatic)
```
> $filter=ODataKind/ODataCode/Code eq '3' or ODataKind/ODataCode/Code eq '5' and ODataKind/ODataCode/Code eq 'testCode'
```csharp
.Filter(s => s.ODataKind.ODataCodes.Any(a => a.IdCode == 1)
&& s.ODataKind.ODataCodes.All(v => v.IdActive))
```
> $filter=ODataKind/ODataCodes/any(a:a/IdCode eq 1) and ODataKind/ODataCodes/all(v:v/IdActive)
```csharp
var constValue = 2;
var constCurrentDate = DateTime.Today.ToString("yyyy-MM-dd");

.Filter(s =>
(s.IdType < constValue && s.ODataKind.ODataCode.IdCode >= 3)
|| s.IdType == 5
&& s.IdRule != default(int?)
&& s.IdRule == null)
```
> $filter=IdType lt 2 and ODataKind/ODataCode/IdCode ge 3 or IdType eq 5 and IdRule ne null and IdRule eq null
```csharp
var constCurrentDateToday = new DateTime(2019, 2, 9);
var constCurrentDateNow = new DateTime(2019, 2, 9, 1, 2, 4);
var newObject = new ODataTypeEntity { ODataKind = new ODataKindEntity { EndDate = constCurrentDateToday } };

.Filter(s =>
s.ODataKind.OpenDate.Date == constCurrentDateNow
&& s.ODataKind.OpenDate == constCurrentDateToday
&& s.ODataKind.OpenDate == DateTime.Today
&& s.Open.Date == DateTime.Today
&& s.Open == DateTime.Today
&& s.Open == constCurrentDateToday
&& s.Open.Date == newObject.ODataKind.EndDate
&& s.ODataKind.OpenDate.Date == new DateTime(2019, 7, 9)
&& ((DateTime)s.BeginDate).Date == DateTime.Today)
```
> $filter=date(ODataKind/OpenDate) eq 2019-02-09 and ODataKind/OpenDate eq 2019-02-09T00:00:00.0000000 and ODataKind/OpenDate eq 2019-08-18T00:00:00.0000000+03:00 and date(Open) eq 2019-08-18 and Open eq 2019-08-18T00:00:00.0000000+03:00 and Open eq 2019-02-09T00:00:00.0000000 and date(Open) eq 2019-02-09 and date(ODataKind/OpenDate) eq 2019-07-09 and date(BeginDate) eq 2019-08-18
```csharp
var constStrIds = new[] { "123", "512" };
var constStrListIds = new[] { "123", "512" }.ToList();
var constIntIds = new[] { 123, 512 };
var constIntListIds = new[] { 123, 512 }.ToList();
var newObject = new ODataTypeEntity { ODataKind = new ODataKindEntity { Sequence = constIntListIds } };
var newObjectSequenceArray = new ODataTypeEntity { ODataKind = new ODataKindEntity { SequenceArray = constIntIds } };

.Filter(s => constStrIds.Contains(s.ODataKind.ODataCode.Code)
&& constStrListIds.Contains(s.ODataKind.ODataCode.Code)
&& constIntIds.Contains(s.IdType)
&& constIntListIds.Contains(s.IdType)
&& constIntIds.Contains((int)s.IdRule)
&& constIntListIds.Contains((int)s.IdRule)
&& newObject.ODataKind.Sequence.Contains(s.ODataKind.IdKind)
&& newObjectSequenceArray.ODataKind.SequenceArray.Contains(s.ODataKind.ODataCode.IdCode))
```
> $filter=ODataKind/ODataCode/Code in ('123','512') and ODataKind/ODataCode/Code in ('123','512') and IdType in (123,512) and IdType in (123,512) and IdRule in (123,512) and IdRule in (123,512) and ODataKind/IdKind in (123,512) and ODataKind/ODataCode/IdCode in (123,512)
```csharp
var constStrIds = default(IEnumerable<string>);
var constStrListIds = new string[] { }.ToList();
var constIntIds = default(int[]);
var constIntListIds = new[] { 123, 512 }.ToList();
var newObject = new ODataTypeEntity { ODataKind = new ODataKindEntity { Sequence = constIntListIds } };
var newObjectSequenceArray = new ODataTypeEntity { ODataKind = new ODataKindEntity { SequenceArray = constIntIds } };

.Filter(s => constStrIds.Contains(s.ODataKind.ODataCode.Code)
&& constStrListIds.Contains(s.ODataKind.ODataCode.Code)
&& constIntIds.Contains(s.IdType)
&& constIntListIds.Contains(s.IdType)
&& constIntIds.Contains((int)s.IdRule)
&& constIntListIds.Contains((int)s.IdRule)
&& newObject.ODataKind.Sequence.Contains(s.ODataKind.IdKind)
&& newObjectSequenceArray.ODataKind.SequenceArray.Contains(s.ODataKind.ODataCode.IdCode))
```
> $filter=IdType in (123,512) and IdRule in (123,512) and ODataKind/IdKind in (123,512)
```csharp
.Filter(s => s.IsActive && s.IsOpen == true && s.ODataKind.ODataCode.IdActive == false)
```
> $filter=IsActive and IsOpen eq true and ODataKind/ODataCode/IdActive eq false
```csharp
var constStrIds = new[] { "123", "512" };
var constValue = 3;

.Filter(s => s.IdRule == constValue
&& s.IsActive
&& (((DateTimeOffset)s.EndDate).Date == default(DateTimeOffset?) || s.EndDate > DateTime.Today)
&& (((DateTime)s.BeginDate).Date != default(DateTime?) || ((DateTime)s.BeginDate).Date <= DateTime.Today)
&& constStrIds.Contains(s.ODataKind.ODataCode.Code))
```
> $filter=IdRule eq 3 and IsActive and date(EndDate) eq null or EndDate gt 2019-08-18T00:00:00.0000000+03:00 and date(BeginDate) ne null or date(BeginDate) le 2019-08-18 and ODataKind/ODataCode/Code in ('123','512')
## <a name="OrderBy"/> OrderBy
```csharp
.OrderBy(s => s.IdType)
```
> $orderby=IdType asc
```csharp
.OrderBy(s => new { s.IdType, s.Sum })
```
> $orderby=IdType,Sum asc
## <a name="OrderByDescending"/> OrderByDescending
```csharp
.OrderByDescending(s => s.IdType)
```
> $orderby=IdType desc
```csharp
.OrderByDescending(s => new { s.IdType, s.Sum })
```
> $orderby=IdType,Sum desc
## <a name="Count"/> Count
```csharp
.Count()
```
> $count=true
```csharp
.Count(false)
```
> $count=false
## <a name="Skip"/> Skip
```csharp
.Skip(12)
```
> $skip=12
## <a name="Top"/> Top
```csharp
.Top(100)
```
> http://mock/odata/ODataType?$expand=ODataKind
> $top=100
2 changes: 2 additions & 0 deletions src/OData.QueryBuilder/Resourses/IODataQueryResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface IODataQueryResource<TEntity>
{
IODataQueryParameterKey<TEntity> ByKey(int key);

IODataQueryParameterKey<TEntity> ByKey(string key);

IODataQueryParameterList<TEntity> ByList();
}
}
7 changes: 7 additions & 0 deletions src/OData.QueryBuilder/Resourses/ODataQueryResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public IODataQueryParameterKey<TEntity> ByKey(int key)
return new ODataQueryParameterKey<TEntity>(_queryBuilder);
}

public IODataQueryParameterKey<TEntity> ByKey(string key)
{
_queryBuilder.Append($"('{key}')?");

return new ODataQueryParameterKey<TEntity>(_queryBuilder);
}

public IODataQueryParameterList<TEntity> ByList()
{
_queryBuilder.Append("?");
Expand Down
10 changes: 7 additions & 3 deletions test/OData.QueryBuilder.Test/CommonFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ namespace OData.QueryBuilder.Test
{
public class CommonFixture
{
public CommonFixture() =>
ODataQueryBuilder = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata/");
public CommonFixture()
{
ODataQueryBuilder1 = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata/");
ODataQueryBuilder2 = new ODataQueryBuilder<ODataInfoContainer>(new System.Uri("http://mock/odata/"));
}

public ODataQueryBuilder<ODataInfoContainer> ODataQueryBuilder { get; private set; }
public ODataQueryBuilder<ODataInfoContainer> ODataQueryBuilder1 { get; private set; }
public ODataQueryBuilder<ODataInfoContainer> ODataQueryBuilder2 { get; private set; }
}
}
14 changes: 13 additions & 1 deletion test/OData.QueryBuilder.Test/ODataQueryBuilderByKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ODataQueryBuilderByKeyTest : IClassFixture<CommonFixture>
private readonly ODataQueryBuilder<ODataInfoContainer> _odataQueryBuilder;

public ODataQueryBuilderByKeyTest(CommonFixture commonFixture) =>
_odataQueryBuilder = commonFixture.ODataQueryBuilder;
_odataQueryBuilder = commonFixture.ODataQueryBuilder1;

[Fact(DisplayName = "(ODataQueryBuilderKey) Expand simple => Success")]
public void ODataQueryBuilderKey_Expand_Simple_Success()
Expand All @@ -25,6 +25,18 @@ public void ODataQueryBuilderKey_Expand_Simple_Success()
uri.OriginalString.Should().Be("http://mock/odata/ODataType(223123123)?$expand=ODataKind");
}

[Fact(DisplayName = "(ODataQueryBuilderKey) Expand simple with key string => Success")]
public void ODataQueryBuilderKey_Expand_Simple_With_Key_String_Success()
{
var uri = _odataQueryBuilder
.For<ODataTypeEntity>(s => s.ODataType)
.ByKey("223123123")
.Expand(s => s.ODataKind)
.ToUri();

uri.OriginalString.Should().Be("http://mock/odata/ODataType('223123123')?$expand=ODataKind");
}

[Fact(DisplayName = "(ODataQueryBuilderKey) Select simple => Success")]
public void ODataQueryBuilderKey_Select_Simple_Success()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ODataQueryBuilderByListTest : IClassFixture<CommonFixture>
public static string IdCodeStatic => "testCode";

public ODataQueryBuilderByListTest(CommonFixture commonFixture) =>
_odataQueryBuilder = commonFixture.ODataQueryBuilder;
_odataQueryBuilder = commonFixture.ODataQueryBuilder2;

[Fact(DisplayName = "(ODataQueryBuilderList) Expand simple => Success")]
public void ODataQueryBuilderList_Expand_Simple_Success()
Expand Down

0 comments on commit ca80536

Please sign in to comment.