1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using JsonApiDotNetCore . Builders ;
3
4
using JsonApiDotNetCore . Internal . Query ;
@@ -23,7 +24,7 @@ public void Property_Sort_Order_Uses_NewExpression()
23
24
// Assert
24
25
Assert . Equal ( 2 , sorts . Count ) ;
25
26
26
- Assert . Equal ( nameof ( Model . Prop ) , sorts [ 0 ] . Attribute . PropertyInfo . Name ) ;
27
+ Assert . Equal ( nameof ( Model . CreatedAt ) , sorts [ 0 ] . Attribute . PropertyInfo . Name ) ;
27
28
Assert . Equal ( SortDirection . Ascending , sorts [ 0 ] . SortDirection ) ;
28
29
29
30
Assert . Equal ( nameof ( Model . Password ) , sorts [ 1 ] . Attribute . PropertyInfo . Name ) ;
@@ -62,7 +63,7 @@ public class Model : Identifiable
62
63
{
63
64
[ Attr ] public string AlwaysExcluded { get ; set ; }
64
65
[ Attr ] public string Password { get ; set ; }
65
- [ Attr ] public string Prop { get ; set ; }
66
+ [ Attr ] public DateTime CreatedAt { get ; set ; }
66
67
}
67
68
68
69
public sealed class RequestFilteredResource : ResourceDefinition < Model >
@@ -72,19 +73,21 @@ public sealed class RequestFilteredResource : ResourceDefinition<Model>
72
73
public RequestFilteredResource ( bool isAdmin ) : base ( new ResourceGraphBuilder ( new JsonApiOptions ( ) , NullLoggerFactory . Instance ) . AddResource < Model > ( ) . Build ( ) )
73
74
{
74
75
if ( isAdmin )
75
- HideFields ( m => m . AlwaysExcluded ) ;
76
+ HideFields ( model => model . AlwaysExcluded ) ;
76
77
else
77
- HideFields ( m => new { m . AlwaysExcluded , m . Password } ) ;
78
+ HideFields ( model => new { model . AlwaysExcluded , model . Password } ) ;
78
79
}
79
80
80
81
public override QueryFilters GetQueryFilters ( )
81
82
=> new QueryFilters {
82
83
{ "is-active" , ( query , value ) => query . Select ( x => x ) }
83
84
} ;
85
+
84
86
public override PropertySortOrder GetDefaultSortOrder ( )
85
- => new PropertySortOrder {
86
- ( t => t . Prop , SortDirection . Ascending ) ,
87
- ( t => t . Password , SortDirection . Descending )
87
+ => new PropertySortOrder
88
+ {
89
+ ( model => model . CreatedAt , SortDirection . Ascending ) ,
90
+ ( model => model . Password , SortDirection . Descending )
88
91
} ;
89
92
}
90
93
}
0 commit comments