@@ -12,106 +12,106 @@ namespace JsonApiDotNetCore.Hooks
12
12
/// Contains the resources from the request and the corresponding database values.
13
13
///
14
14
/// Also contains information about updated relationships through
15
- /// implementation of IRelationshipsDictionary<typeparamref name="TResource "/>>
15
+ /// implementation of IRelationshipsDictionary<typeparamref name="TEntity "/>>
16
16
/// </summary>
17
- public interface IResourceDiffs < TResource > : IRelationshipsDictionary < TResource > , IEnumerable < ResourceDiffPair < TResource > > where TResource : class , IIdentifiable
17
+ public interface IEntityDiff < TEntity > : IRelationshipsDictionary < TEntity > , IEnumerable < EntityDiffPair < TEntity > > where TEntity : class , IIdentifiable
18
18
{
19
19
/// <summary>
20
20
/// The database values of the resources affected by the request.
21
21
/// </summary>
22
- HashSet < TResource > DatabaseValues { get ; }
22
+ HashSet < TEntity > DatabaseValues { get ; }
23
23
24
24
/// <summary>
25
25
/// The resources that were affected by the request.
26
26
/// </summary>
27
- HashSet < TResource > Resources { get ; }
27
+ HashSet < TEntity > Entities { get ; }
28
28
}
29
29
30
30
/// <inheritdoc />
31
- public class ResourceDiffs < TResource > : IResourceDiffs < TResource > where TResource : class , IIdentifiable
31
+ public class EntityDiffs < TEntity > : IEntityDiff < TEntity > where TEntity : class , IIdentifiable
32
32
{
33
33
/// <inheritdoc />
34
- public HashSet < TResource > DatabaseValues { get => _databaseValues ?? ThrowNoDbValuesError ( ) ; }
35
- private readonly HashSet < TResource > _databaseValues ;
34
+ public HashSet < TEntity > DatabaseValues { get => _databaseValues ?? ThrowNoDbValuesError ( ) ; }
35
+ private readonly HashSet < TEntity > _databaseValues ;
36
36
private readonly bool _databaseValuesLoaded ;
37
37
38
38
/// <inheritdoc />
39
- public HashSet < TResource > Resources { get ; private set ; }
39
+ public HashSet < TEntity > Entities { get ; private set ; }
40
40
/// <inheritdoc />
41
- public RelationshipsDictionary < TResource > AffectedRelationships { get ; private set ; }
41
+ public RelationshipsDictionary < TEntity > AffectedRelationships { get ; private set ; }
42
42
43
- public ResourceDiffs ( HashSet < TResource > requestEntities ,
44
- HashSet < TResource > databaseEntities ,
45
- Dictionary < RelationshipAttribute , HashSet < TResource > > relationships )
43
+ public EntityDiffs ( HashSet < TEntity > requestEntities ,
44
+ HashSet < TEntity > databaseEntities ,
45
+ Dictionary < RelationshipAttribute , HashSet < TEntity > > relationships )
46
46
{
47
- Resources = requestEntities ;
48
- AffectedRelationships = new RelationshipsDictionary < TResource > ( relationships ) ;
47
+ Entities = requestEntities ;
48
+ AffectedRelationships = new RelationshipsDictionary < TEntity > ( relationships ) ;
49
49
_databaseValues = databaseEntities ;
50
50
_databaseValuesLoaded |= _databaseValues != null ;
51
51
}
52
52
53
53
/// <summary>
54
54
/// Used internally by the ResourceHookExecutor to make live a bit easier with generics
55
55
/// </summary>
56
- internal ResourceDiffs ( IEnumerable requestEntities ,
56
+ internal EntityDiffs ( IEnumerable requestEntities ,
57
57
IEnumerable databaseEntities ,
58
58
Dictionary < RelationshipAttribute , IEnumerable > relationships )
59
- : this ( ( HashSet < TResource > ) requestEntities , ( HashSet < TResource > ) databaseEntities , TypeHelper . ConvertRelationshipDictionary < TResource > ( relationships ) ) { }
59
+ : this ( ( HashSet < TEntity > ) requestEntities , ( HashSet < TEntity > ) databaseEntities , TypeHelper . ConvertRelationshipDictionary < TEntity > ( relationships ) ) { }
60
60
61
61
62
62
/// <inheritdoc />
63
- public Dictionary < RelationshipAttribute , HashSet < TResource > > GetByRelationship < TPrincipalResource > ( ) where TPrincipalResource : class , IIdentifiable
63
+ public Dictionary < RelationshipAttribute , HashSet < TEntity > > GetByRelationship < TPrincipalResource > ( ) where TPrincipalResource : class , IIdentifiable
64
64
{
65
65
return GetByRelationship ( typeof ( TPrincipalResource ) ) ;
66
66
}
67
67
68
68
/// <inheritdoc />
69
- public Dictionary < RelationshipAttribute , HashSet < TResource > > GetByRelationship ( Type principalType )
69
+ public Dictionary < RelationshipAttribute , HashSet < TEntity > > GetByRelationship ( Type principalType )
70
70
{
71
71
return AffectedRelationships . GetByRelationship ( principalType ) ;
72
72
}
73
73
74
74
/// <inheritdoc />
75
- public IEnumerator < ResourceDiffPair < TResource > > GetEnumerator ( )
75
+ public IEnumerator < EntityDiffPair < TEntity > > GetEnumerator ( )
76
76
{
77
77
if ( ! _databaseValuesLoaded ) ThrowNoDbValuesError ( ) ;
78
78
79
- foreach ( var entity in Resources )
79
+ foreach ( var entity in Entities )
80
80
{
81
- TResource currentValueInDatabase = null ;
81
+ TEntity currentValueInDatabase = null ;
82
82
currentValueInDatabase = _databaseValues . Single ( e => entity . StringId == e . StringId ) ;
83
- yield return new ResourceDiffPair < TResource > ( entity , currentValueInDatabase ) ;
83
+ yield return new EntityDiffPair < TEntity > ( entity , currentValueInDatabase ) ;
84
84
}
85
85
}
86
86
87
87
/// <inheritdoc />
88
88
IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
89
89
90
- private HashSet < TResource > ThrowNoDbValuesError ( )
90
+ private HashSet < TEntity > ThrowNoDbValuesError ( )
91
91
{
92
92
throw new MemberAccessException ( "Cannot access database entities if the LoadDatabaseValues option is set to false" ) ;
93
93
}
94
94
}
95
95
96
96
/// <summary>
97
- /// A wrapper that contains an resource that is affected by the request,
97
+ /// A wrapper that contains an entity that is affected by the request,
98
98
/// matched to its current database value
99
99
/// </summary>
100
- public class ResourceDiffPair < TResource > where TResource : class , IIdentifiable
100
+ public class EntityDiffPair < TEntity > where TEntity : class , IIdentifiable
101
101
{
102
- public ResourceDiffPair ( TResource resource , TResource databaseValue )
102
+ public EntityDiffPair ( TEntity entity , TEntity databaseValue )
103
103
{
104
- Resource = resource ;
104
+ Entity = entity ;
105
105
DatabaseValue = databaseValue ;
106
106
}
107
107
108
108
/// <summary>
109
109
/// The resource from the request matching the resource from the database.
110
110
/// </summary>
111
- public TResource Resource { get ; private set ; }
111
+ public TEntity Entity { get ; private set ; }
112
112
/// <summary>
113
113
/// The resource from the database matching the resource from the request.
114
114
/// </summary>
115
- public TResource DatabaseValue { get ; private set ; }
115
+ public TEntity DatabaseValue { get ; private set ; }
116
116
}
117
117
}
0 commit comments