Skip to content

Commit f2e411c

Browse files
committed
style: rename Entity to Resource
1 parent d038582 commit f2e411c

24 files changed

+50
-68
lines changed

src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public IResourceGraph Build()
3838

3939
private void SetResourceLinksOptions(ResourceContext resourceContext)
4040
{
41-
var attribute = (LinksAttribute)resourceContext.EntityType.GetCustomAttribute(typeof(LinksAttribute));
41+
var attribute = (LinksAttribute)resourceContext.ResourceType.GetCustomAttribute(typeof(LinksAttribute));
4242
if (attribute != null)
4343
{
4444
resourceContext.RelationshipLinks = attribute.RelationshipLinks;
@@ -69,12 +69,12 @@ public IResourceGraphBuilder AddResource(Type entityType, Type idType, string pl
6969

7070
private ResourceContext GetEntity(string pluralizedTypeName, Type entityType, Type idType) => new ResourceContext
7171
{
72-
EntityName = pluralizedTypeName,
73-
EntityType = entityType,
72+
ResourceName = pluralizedTypeName,
73+
ResourceType = entityType,
7474
IdentityType = idType,
7575
Attributes = GetAttributes(entityType),
7676
Relationships = GetRelationships(entityType),
77-
ResourceType = GetResourceDefinitionType(entityType)
77+
ResourceDefinitionType = GetResourceDefinitionType(entityType)
7878
};
7979

8080

@@ -234,7 +234,7 @@ private string GetResourceNameFromDbSetProperty(PropertyInfo property, Type reso
234234

235235
private void AssertEntityIsNotAlreadyDefined(Type entityType)
236236
{
237-
if (_entities.Any(e => e.EntityType == entityType))
237+
if (_entities.Any(e => e.ResourceType == entityType))
238238
throw new InvalidOperationException($"Cannot add entity type {entityType} to context resourceGraph, there is already an entity of that type configured.");
239239
}
240240
}

src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,14 @@ public HashSet<TEntity> LoadDbValues<TEntity>(IEnumerable<TEntity> entities, Res
9797
return new HashSet<TEntity>(dbValues);
9898
}
9999

100-
101100
public bool ShouldLoadDbValues(Type entityType, ResourceHook hook)
102101
{
103102
var discovery = GetHookDiscovery(entityType);
104-
105103
if (discovery.DatabaseValuesDisabledHooks.Contains(hook))
106-
{
107104
return false;
108-
}
109105
if (discovery.DatabaseValuesEnabledHooks.Contains(hook))
110-
{
111106
return true;
112-
}
113-
else
114-
{
115-
return _options.LoaDatabaseValues;
116-
}
107+
return _options.LoaDatabaseValues;
117108
}
118109

119110
bool ShouldExecuteHook(DependentType entityType, ResourceHook hook)

src/JsonApiDotNetCore/Internal/Contracts/IContextEntityProvider.cs renamed to src/JsonApiDotNetCore/Internal/Contracts/IResourceContextProvider.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq.Expressions;
4-
using JsonApiDotNetCore.Internal;
52
using JsonApiDotNetCore.Models;
63

74
namespace JsonApiDotNetCore.Internal.Contracts
@@ -14,7 +11,7 @@ public interface IResourceContextProvider
1411
/// <summary>
1512
/// Gets all registered context entities
1613
/// </summary>
17-
ResourceContext[] GetContextEntities();
14+
ResourceContext[] GetResourceContexts();
1815

1916
/// <summary>
2017
/// Get the resource metadata by the DbSet property name

src/JsonApiDotNetCore/Internal/InverseRelationships.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public void Resolve()
4545
{
4646
DbContext context = _resolver.GetContext();
4747

48-
foreach (ResourceContext ce in _provider.GetContextEntities())
48+
foreach (ResourceContext ce in _provider.GetResourceContexts())
4949
{
50-
IEntityType meta = context.Model.FindEntityType(ce.EntityType);
50+
IEntityType meta = context.Model.FindEntityType(ce.ResourceType);
5151
if (meta == null) continue;
5252
foreach (var attr in ce.Relationships)
5353
{

src/JsonApiDotNetCore/Internal/ContextEntity.cs renamed to src/JsonApiDotNetCore/Internal/ResourceContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public class ResourceContext
1111
/// <summary>
1212
/// The exposed resource name
1313
/// </summary>
14-
public string EntityName { get; set; }
14+
public string ResourceName { get; set; }
1515

1616
/// <summary>
1717
/// The data model type
1818
/// </summary>
19-
public Type EntityType { get; set; }
19+
public Type ResourceType { get; set; }
2020

2121
/// <summary>
2222
/// The identity member type
@@ -27,7 +27,7 @@ public class ResourceContext
2727
/// The concrete <see cref="ResourceDefinition{T}"/> type.
2828
/// We store this so that we don't need to re-compute the generic type.
2929
/// </summary>
30-
public Type ResourceType { get; set; }
30+
public Type ResourceDefinitionType { get; set; }
3131

3232
/// <summary>
3333
/// Exposed resource attributes.

src/JsonApiDotNetCore/Internal/ResourceGraph.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,25 @@ namespace JsonApiDotNetCore.Internal
1313
public class ResourceGraph : IResourceGraph
1414
{
1515
internal List<ValidationResult> ValidationResults { get; }
16-
private List<ResourceContext> _entities { get; }
16+
private List<ResourceContext> _resources { get; }
1717

1818
public ResourceGraph(List<ResourceContext> entities, List<ValidationResult> validationResults = null)
1919
{
20-
_entities = entities;
20+
_resources = entities;
2121
ValidationResults = validationResults;
2222
}
2323

2424
/// <inheritdoc />
25-
public ResourceContext[] GetContextEntities() => _entities.ToArray();
26-
25+
public ResourceContext[] GetResourceContexts() => _resources.ToArray();
2726
/// <inheritdoc />
2827
public ResourceContext GetResourceContext(string entityName)
29-
=> _entities.SingleOrDefault(e => string.Equals(e.EntityName, entityName, StringComparison.OrdinalIgnoreCase));
30-
28+
=> _resources.SingleOrDefault(e => string.Equals(e.ResourceName, entityName, StringComparison.OrdinalIgnoreCase));
3129
/// <inheritdoc />
3230
public ResourceContext GetResourceContext(Type entityType)
33-
=> _entities.SingleOrDefault(e => e.EntityType == entityType);
31+
=> _resources.SingleOrDefault(e => e.ResourceType == entityType);
3432
/// <inheritdoc />
3533
public ResourceContext GetResourceContext<TResource>() where TResource : class, IIdentifiable
3634
=> GetResourceContext(typeof(TResource));
37-
3835
/// <inheritdoc/>
3936
public List<IResourceField> GetFields<T>(Expression<Func<T, dynamic>> selector = null) where T : IIdentifiable
4037
{
@@ -65,7 +62,6 @@ public List<RelationshipAttribute> GetRelationships(Type type)
6562
{
6663
return GetResourceContext(type).Relationships.ToList();
6764
}
68-
6965
/// <inheritdoc />
7066
public RelationshipAttribute GetInverse(RelationshipAttribute relationship)
7167
{
@@ -144,7 +140,5 @@ private enum FieldFilterType
144140
Attribute,
145141
Relationship
146142
}
147-
148-
149143
}
150144
}

src/JsonApiDotNetCore/Middleware/DefaultTypeMatchFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void OnActionExecuting(ActionExecutingContext context)
3333

3434
throw new JsonApiException(409,
3535
$"Cannot '{context.HttpContext.Request.Method}' type '{deserializedType.Name}' "
36-
+ $"to '{expectedJsonApiResource?.EntityName}' endpoint.",
36+
+ $"to '{expectedJsonApiResource?.ResourceName}' endpoint.",
3737
detail: "Check that the request payload type matches the type expected by this endpoint.");
3838
}
3939
}

src/JsonApiDotNetCore/Middleware/RequestMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task Invoke(HttpContext httpContext,
4646
{
4747
_currentRequest.SetRequestResource(GetCurrentEntity());
4848
_currentRequest.IsRelationshipPath = PathIsRelationship();
49-
_currentRequest.BasePath = GetBasePath(_currentRequest.GetRequestResource().EntityName);
49+
_currentRequest.BasePath = GetBasePath(_currentRequest.GetRequestResource().ResourceName);
5050
}
5151

5252
if (IsValid())

src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected RelationshipAttribute GetRelationship(string propertyName)
6666
if (propertyName == null) return null;
6767
var relationship = _requestResource.Relationships.FirstOrDefault(r => r.Is(propertyName));
6868
if (relationship == null)
69-
throw new JsonApiException(400, $"{propertyName} is not a valid relationship on {_requestResource.EntityName}.");
69+
throw new JsonApiException(400, $"{propertyName} is not a valid relationship on {_requestResource.ResourceName}.");
7070

7171
return relationship;
7272
}

src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class FilterService : QueryParameterService, IFilterService
1818

1919
public FilterService(IResourceDefinitionProvider resourceDefinitionProvider, IResourceGraph resourceGraph, ICurrentRequest currentRequest) : base(resourceGraph, currentRequest)
2020
{
21-
_requestResourceDefinition = resourceDefinitionProvider.Get(_requestResource.EntityType);
21+
_requestResourceDefinition = resourceDefinitionProvider.Get(_requestResource.ResourceType);
2222
_filters = new List<FilterQueryContext>();
2323
}
2424

0 commit comments

Comments
 (0)