-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from Research-Institute/develop
v1.3.1
- Loading branch information
Showing
14 changed files
with
355 additions
and
96 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,39 @@ | ||
using System; | ||
using System.Linq; | ||
using JsonApiDotNetCore.Models; | ||
using JsonApiDotNetCore.Services; | ||
|
||
namespace JsonApiDotNetCore.Internal.Query | ||
{ | ||
public class AttrFilterQuery | ||
{ | ||
private readonly IJsonApiContext _jsonApiContext; | ||
|
||
public AttrFilterQuery( | ||
IJsonApiContext jsonApiCopntext, | ||
FilterQuery filterQuery) | ||
{ | ||
_jsonApiContext = jsonApiCopntext; | ||
|
||
var attribute = GetAttribute(filterQuery.Key); | ||
|
||
if (attribute == null) | ||
throw new JsonApiException("400", $"{filterQuery.Key} is not a valid property."); | ||
|
||
FilteredAttribute = attribute; | ||
PropertyValue = filterQuery.Value; | ||
FilterOperation = GetFilterOperation(filterQuery.Operation); | ||
} | ||
|
||
public AttrAttribute FilteredAttribute { get; set; } | ||
public string PropertyValue { get; set; } | ||
public FilterOperations FilterOperation { get; set; } | ||
|
||
private FilterOperations GetFilterOperation(string prefix) | ||
{ | ||
if (prefix.Length == 0) return FilterOperations.eq; | ||
|
||
FilterOperations opertion; | ||
if (!Enum.TryParse<FilterOperations>(prefix, out opertion)) | ||
throw new JsonApiException("400", $"Invalid filter prefix '{prefix}'"); | ||
|
||
return opertion; | ||
} | ||
|
||
private AttrAttribute GetAttribute(string propertyName) | ||
public class AttrFilterQuery : BaseFilterQuery | ||
{ | ||
return _jsonApiContext.RequestEntity.Attributes | ||
.FirstOrDefault(attr => | ||
attr.InternalAttributeName.ToLower() == propertyName.ToLower() | ||
); | ||
private readonly IJsonApiContext _jsonApiContext; | ||
|
||
public AttrFilterQuery( | ||
IJsonApiContext jsonApiCopntext, | ||
FilterQuery filterQuery) | ||
{ | ||
_jsonApiContext = jsonApiCopntext; | ||
|
||
var attribute = GetAttribute(filterQuery.Key); | ||
|
||
if (attribute == null) | ||
throw new JsonApiException("400", $"{filterQuery.Key} is not a valid property."); | ||
|
||
FilteredAttribute = attribute; | ||
PropertyValue = filterQuery.Value; | ||
FilterOperation = GetFilterOperation(filterQuery.Operation); | ||
} | ||
|
||
public AttrAttribute FilteredAttribute { get; set; } | ||
public string PropertyValue { get; set; } | ||
public FilterOperations FilterOperation { get; set; } | ||
|
||
private AttrAttribute GetAttribute(string propertyName) | ||
{ | ||
return _jsonApiContext.RequestEntity.Attributes | ||
.FirstOrDefault(attr => | ||
attr.InternalAttributeName.ToLower() == propertyName.ToLower() | ||
); | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
|
||
namespace JsonApiDotNetCore.Internal.Query | ||
{ | ||
public class BaseFilterQuery | ||
{ | ||
protected FilterOperations GetFilterOperation(string prefix) | ||
{ | ||
if (prefix.Length == 0) return FilterOperations.eq; | ||
|
||
FilterOperations opertion; | ||
if (!Enum.TryParse<FilterOperations>(prefix, out opertion)) | ||
throw new JsonApiException("400", $"Invalid filter prefix '{prefix}'"); | ||
|
||
return opertion; | ||
} | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.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,51 @@ | ||
using System.Linq; | ||
using JsonApiDotNetCore.Models; | ||
using JsonApiDotNetCore.Services; | ||
|
||
namespace JsonApiDotNetCore.Internal.Query | ||
{ | ||
public class RelatedAttrFilterQuery : BaseFilterQuery | ||
{ | ||
private readonly IJsonApiContext _jsonApiContext; | ||
|
||
public RelatedAttrFilterQuery( | ||
IJsonApiContext jsonApiCopntext, | ||
FilterQuery filterQuery) | ||
{ | ||
_jsonApiContext = jsonApiCopntext; | ||
|
||
var relationshipArray = filterQuery.Key.Split('.'); | ||
|
||
var relationship = GetRelationship(relationshipArray[0]); | ||
if (relationship == null) | ||
throw new JsonApiException("400", $"{relationshipArray[0]} is not a valid relationship."); | ||
|
||
var attribute = GetAttribute(relationship, relationshipArray[1]); | ||
if (attribute == null) | ||
throw new JsonApiException("400", $"{relationshipArray[1]} is not a valid attribute on {relationshipArray[0]}."); | ||
|
||
FilteredRelationship = relationship; | ||
FilteredAttribute = attribute; | ||
PropertyValue = filterQuery.Value; | ||
FilterOperation = GetFilterOperation(filterQuery.Operation); | ||
} | ||
|
||
public AttrAttribute FilteredAttribute { get; set; } | ||
public string PropertyValue { get; set; } | ||
public FilterOperations FilterOperation { get; set; } | ||
public RelationshipAttribute FilteredRelationship { get; private set; } | ||
|
||
private RelationshipAttribute GetRelationship(string propertyName) | ||
{ | ||
return _jsonApiContext.RequestEntity.Relationships | ||
.FirstOrDefault(r => r.InternalRelationshipName.ToLower() == propertyName.ToLower()); | ||
} | ||
|
||
private AttrAttribute GetAttribute(RelationshipAttribute relationship, string attribute) | ||
{ | ||
var relatedContextExntity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type); | ||
return relatedContextExntity.Attributes | ||
.FirstOrDefault(a => a.InternalAttributeName.ToLower() == attribute.ToLower()); | ||
} | ||
} | ||
} |
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.