1- using System ;
21using System . Linq ;
32using JsonApiDotNetCore . Models ;
43using JsonApiDotNetCore . Services ;
54
65namespace JsonApiDotNetCore . Internal . Query
76{
8- public class AttrFilterQuery
9- {
10- private readonly IJsonApiContext _jsonApiContext ;
11-
12- public AttrFilterQuery (
13- IJsonApiContext jsonApiCopntext ,
14- FilterQuery filterQuery )
15- {
16- _jsonApiContext = jsonApiCopntext ;
17-
18- var attribute = GetAttribute ( filterQuery . Key ) ;
19-
20- if ( attribute == null )
21- throw new JsonApiException ( "400" , $ "{ filterQuery . Key } is not a valid property.") ;
22-
23- FilteredAttribute = attribute ;
24- PropertyValue = filterQuery . Value ;
25- FilterOperation = GetFilterOperation ( filterQuery . Operation ) ;
26- }
27-
28- public AttrAttribute FilteredAttribute { get ; set ; }
29- public string PropertyValue { get ; set ; }
30- public FilterOperations FilterOperation { get ; set ; }
31-
32- private FilterOperations GetFilterOperation ( string prefix )
33- {
34- if ( prefix . Length == 0 ) return FilterOperations . eq ;
35-
36- FilterOperations opertion ;
37- if ( ! Enum . TryParse < FilterOperations > ( prefix , out opertion ) )
38- throw new JsonApiException ( "400" , $ "Invalid filter prefix '{ prefix } '") ;
39-
40- return opertion ;
41- }
42-
43- private AttrAttribute GetAttribute ( string propertyName )
7+ public class AttrFilterQuery : BaseFilterQuery
448 {
45- return _jsonApiContext . RequestEntity . Attributes
46- . FirstOrDefault ( attr =>
47- attr . InternalAttributeName . ToLower ( ) == propertyName . ToLower ( )
48- ) ;
9+ private readonly IJsonApiContext _jsonApiContext ;
10+
11+ public AttrFilterQuery (
12+ IJsonApiContext jsonApiCopntext ,
13+ FilterQuery filterQuery )
14+ {
15+ _jsonApiContext = jsonApiCopntext ;
16+
17+ var attribute = GetAttribute ( filterQuery . Key ) ;
18+
19+ if ( attribute == null )
20+ throw new JsonApiException ( "400" , $ "{ filterQuery . Key } is not a valid property.") ;
21+
22+ FilteredAttribute = attribute ;
23+ PropertyValue = filterQuery . Value ;
24+ FilterOperation = GetFilterOperation ( filterQuery . Operation ) ;
25+ }
26+
27+ public AttrAttribute FilteredAttribute { get ; set ; }
28+ public string PropertyValue { get ; set ; }
29+ public FilterOperations FilterOperation { get ; set ; }
30+
31+ private AttrAttribute GetAttribute ( string propertyName )
32+ {
33+ return _jsonApiContext . RequestEntity . Attributes
34+ . FirstOrDefault ( attr =>
35+ attr . InternalAttributeName . ToLower ( ) == propertyName . ToLower ( )
36+ ) ;
37+ }
4938 }
50- }
5139}
0 commit comments