Skip to content

Commit 1ecab38

Browse files
committed
refactor: rename pipeline enum members
1 parent f66f894 commit 1ecab38

15 files changed

+133
-133
lines changed

src/Examples/JsonApiDotNetCoreExample/Resources/ArticleResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public ArticleResource(IResourceGraph graph) : base(graph) { }
1616

1717
public override IEnumerable<Article> OnReturn(HashSet<Article> entities, ResourcePipeline pipeline)
1818
{
19-
if (pipeline == ResourcePipeline.ReadSingle && entities.Single().Name == "Classified")
19+
if (pipeline == ResourcePipeline.GetSingle && entities.Single().Name == "Classified")
2020
{
2121
throw new JsonApiException(403, "You are not allowed to see this article!", new UnauthorizedAccessException());
2222
}

src/Examples/JsonApiDotNetCoreExample/Resources/PassportResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public PassportResource(IResourceGraph graph) : base(graph)
1616

1717
public override void BeforeRead(ResourcePipeline pipeline, bool nestedHook = false, string stringId = null)
1818
{
19-
if (pipeline == ResourcePipeline.ReadSingle && nestedHook)
19+
if (pipeline == ResourcePipeline.GetSingle && nestedHook)
2020
{
2121
throw new JsonApiException(403, "Not allowed to include passports on individual people", new UnauthorizedAccessException());
2222
}

src/JsonApiDotNetCore/Hooks/Execution/ResourcePipelineEnum.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
public enum ResourcePipeline
99
{
1010
None,
11-
Read,
12-
ReadSingle,
13-
ReadRelationship,
14-
Create,
11+
Get,
12+
GetSingle,
13+
GetRelationship,
14+
Post,
1515
Patch,
1616
PatchRelationship,
1717
Delete,
18-
BulkCreate,
18+
BulkPost,
1919
BulkPatch,
2020
BulkDelete
2121
}

src/JsonApiDotNetCore/Hooks/IResourceHookContainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public interface IBeforeHooks<TEntity> where TEntity : class, IIdentifiable
7979
/// Implement this hook to run custom logic in the <see cref=" EntityResourceService{T}"/>
8080
/// layer just before creation of entities of type <typeparamref name="TEntity"/>.
8181
/// <para />
82-
/// For the <see cref="ResourcePipeline.Create"/> pipeline, <paramref name="entities"/>
82+
/// For the <see cref="ResourcePipeline.Post"/> pipeline, <paramref name="entities"/>
8383
/// will typically contain one entry. For <see cref="ResourcePipeline.BulkCreate"/>,
8484
/// <paramref name="entities"/> can contain multiple entities.
8585
/// <para />
@@ -103,7 +103,7 @@ public interface IBeforeHooks<TEntity> where TEntity : class, IIdentifiable
103103
/// </summary>
104104
/// <param name="pipeline">An enum indicating from where the hook was triggered.</param>
105105
/// <param name="isIncluded">Indicates whether the to be queried entities are the main request entities or if they were included</param>
106-
/// <param name="stringId">The string id of the requested entity, in the case of <see cref="ResourcePipeline.ReadSingle"/></param>
106+
/// <param name="stringId">The string id of the requested entity, in the case of <see cref="ResourcePipeline.GetSingle"/></param>
107107
void BeforeRead(ResourcePipeline pipeline, bool isIncluded = false, string stringId = null);
108108
/// <summary>
109109
/// Implement this hook to run custom logic in the <see cref=" EntityResourceService{T}"/>
@@ -161,7 +161,7 @@ public interface IBeforeHooks<TEntity> where TEntity : class, IIdentifiable
161161
/// layer just before updating relationships to entities of type <typeparamref name="TEntity"/>.
162162
/// <para />
163163
/// This hook is fired when a relationship is created to entities of type
164-
/// <typeparamref name="TEntity"/> from a dependent pipeline (<see cref="ResourcePipeline.Create"/>
164+
/// <typeparamref name="TEntity"/> from a dependent pipeline (<see cref="ResourcePipeline.Post"/>
165165
/// or <see cref="ResourcePipeline.Patch"/>). For example, If an Article was created
166166
/// and its author relationship was set to an existing Person, this hook will be fired
167167
/// for that particular Person.

src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public virtual IEnumerable<TEntity> BeforeDelete<TEntity>(IEnumerable<TEntity> e
9494
/// <inheritdoc/>
9595
public virtual IEnumerable<TEntity> OnReturn<TEntity>(IEnumerable<TEntity> entities, ResourcePipeline pipeline) where TEntity : class, IIdentifiable
9696
{
97-
if (GetHook(ResourceHook.OnReturn, entities, out var container, out var node) && pipeline != ResourcePipeline.ReadRelationship)
97+
if (GetHook(ResourceHook.OnReturn, entities, out var container, out var node) && pipeline != ResourcePipeline.GetRelationship)
9898
{
9999
IEnumerable<TEntity> updated = container.OnReturn((HashSet<TEntity>)node.UniqueEntities, pipeline);
100100
ValidateHookResponse(updated);
@@ -257,7 +257,7 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, EntityChildLayer lay
257257

258258
// fire the BeforeImplicitUpdateRelationship hook for o1
259259
var implicitPrincipalTargets = node.RelationshipsFromPreviousLayer.GetPrincipalEntities();
260-
if (pipeline != ResourcePipeline.Create && implicitPrincipalTargets.Any())
260+
if (pipeline != ResourcePipeline.Post && implicitPrincipalTargets.Any())
261261
{
262262
FireForAffectedImplicits(entityType, implicitPrincipalTargets, pipeline, uniqueEntities);
263263
}
@@ -294,7 +294,7 @@ void FireForAffectedImplicits(Type entityType, Dictionary<RelationshipProxy, IEn
294294
/// <param name="pipeline">The pipeine from which the hook was fired</param>
295295
void ValidateHookResponse<T>(IEnumerable<T> returnedList, ResourcePipeline pipeline = 0)
296296
{
297-
if (pipeline == ResourcePipeline.ReadSingle && returnedList.Count() > 1)
297+
if (pipeline == ResourcePipeline.GetSingle && returnedList.Count() > 1)
298298
{
299299
throw new ApplicationException("The returned collection from this hook may contain at most one item in the case of the" +
300300
pipeline.ToString("G") + "pipeline");

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public virtual async Task<TResource> CreateAsync(TResource resource)
9797
{
9898
var entity = MapIn(resource);
9999

100-
entity = IsNull(_hookExecutor) ? entity : _hookExecutor.BeforeCreate(AsList(entity), ResourcePipeline.Create).SingleOrDefault();
100+
entity = IsNull(_hookExecutor) ? entity : _hookExecutor.BeforeCreate(AsList(entity), ResourcePipeline.Post).SingleOrDefault();
101101
entity = await _entities.CreateAsync(entity);
102102

103103
// this ensures relationships get reloaded from the database if they have
@@ -113,8 +113,8 @@ public virtual async Task<TResource> CreateAsync(TResource resource)
113113
}
114114
if (!IsNull(_hookExecutor, entity))
115115
{
116-
_hookExecutor.AfterCreate(AsList(entity), ResourcePipeline.Create);
117-
entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.Read).SingleOrDefault();
116+
_hookExecutor.AfterCreate(AsList(entity), ResourcePipeline.Post);
117+
entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.Get).SingleOrDefault();
118118
}
119119
return MapOut(entity);
120120
}
@@ -129,7 +129,7 @@ public virtual async Task<bool> DeleteAsync(TId id)
129129

130130
public virtual async Task<IEnumerable<TResource>> GetAsync()
131131
{
132-
_hookExecutor?.BeforeRead<TEntity>(ResourcePipeline.Read);
132+
_hookExecutor?.BeforeRead<TEntity>(ResourcePipeline.Get);
133133
var entities = _entities.Get();
134134

135135
entities = ApplySortAndFilterQuery(entities);
@@ -145,8 +145,8 @@ public virtual async Task<IEnumerable<TResource>> GetAsync()
145145
if (!IsNull(_hookExecutor, entities))
146146
{
147147
var result = entities.ToList();
148-
_hookExecutor.AfterRead(result, ResourcePipeline.Read);
149-
entities = _hookExecutor.OnReturn(result, ResourcePipeline.Read).AsQueryable();
148+
_hookExecutor.AfterRead(result, ResourcePipeline.Get);
149+
entities = _hookExecutor.OnReturn(result, ResourcePipeline.Get).AsQueryable();
150150
}
151151

152152
if (_jsonApiContext.Options.IncludeTotalRecordCount)
@@ -159,7 +159,7 @@ public virtual async Task<IEnumerable<TResource>> GetAsync()
159159

160160
public virtual async Task<TResource> GetAsync(TId id)
161161
{
162-
var pipeline = ResourcePipeline.ReadSingle;
162+
var pipeline = ResourcePipeline.GetSingle;
163163
_hookExecutor?.BeforeRead<TEntity>(pipeline, id.ToString());
164164
TEntity entity;
165165
if (ShouldIncludeRelationships())
@@ -186,12 +186,12 @@ public virtual async Task<TResource> GetAsync(TId id)
186186
public virtual async Task<object> GetRelationshipAsync(TId id, string relationshipName)
187187
{
188188

189-
_hookExecutor?.BeforeRead<TEntity>(ResourcePipeline.ReadRelationship, id.ToString());
189+
_hookExecutor?.BeforeRead<TEntity>(ResourcePipeline.GetRelationship, id.ToString());
190190
var entity = await _entities.GetAndIncludeAsync(id, relationshipName);
191191
if (!IsNull(_hookExecutor, entity))
192192
{
193-
_hookExecutor.AfterRead(AsList(entity), ResourcePipeline.ReadRelationship);
194-
entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.ReadRelationship).SingleOrDefault();
193+
_hookExecutor.AfterRead(AsList(entity), ResourcePipeline.GetRelationship);
194+
entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.GetRelationship).SingleOrDefault();
195195
}
196196

197197
// TODO: it would be better if we could distinguish whether or not the relationship was not found,

test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/AfterCreateTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public void AfterCreate()
2121
var todoList = CreateTodoWithOwner();
2222

2323
// act
24-
hookExecutor.AfterCreate(todoList, ResourcePipeline.Create);
24+
hookExecutor.AfterCreate(todoList, ResourcePipeline.Post);
2525

2626
// assert
27-
todoResourceMock.Verify(rd => rd.AfterCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Create), Times.Once());
28-
ownerResourceMock.Verify(rd => rd.AfterUpdateRelationship(It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Create), Times.Once());
27+
todoResourceMock.Verify(rd => rd.AfterCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Post), Times.Once());
28+
ownerResourceMock.Verify(rd => rd.AfterUpdateRelationship(It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Post), Times.Once());
2929
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
3030
}
3131

@@ -40,10 +40,10 @@ public void AfterCreate_Without_Parent_Hook_Implemented()
4040
var todoList = CreateTodoWithOwner();
4141

4242
// act
43-
hookExecutor.AfterCreate(todoList, ResourcePipeline.Create);
43+
hookExecutor.AfterCreate(todoList, ResourcePipeline.Post);
4444

4545
// assert
46-
ownerResourceMock.Verify(rd => rd.AfterUpdateRelationship(It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Create), Times.Once());
46+
ownerResourceMock.Verify(rd => rd.AfterUpdateRelationship(It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Post), Times.Once());
4747
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
4848
}
4949

@@ -58,10 +58,10 @@ public void AfterCreate_Without_Child_Hook_Implemented()
5858
var todoList = CreateTodoWithOwner();
5959

6060
// act
61-
hookExecutor.AfterCreate(todoList, ResourcePipeline.Create);
61+
hookExecutor.AfterCreate(todoList, ResourcePipeline.Post);
6262

6363
// assert
64-
todoResourceMock.Verify(rd => rd.AfterCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Create), Times.Once());
64+
todoResourceMock.Verify(rd => rd.AfterCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Post), Times.Once());
6565
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
6666
}
6767

@@ -76,7 +76,7 @@ public void AfterCreate_Without_Any_Hook_Implemented()
7676
var todoList = CreateTodoWithOwner();
7777

7878
// act
79-
hookExecutor.AfterCreate(todoList, ResourcePipeline.Create);
79+
hookExecutor.AfterCreate(todoList, ResourcePipeline.Post);
8080

8181
// assert
8282
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);

test/UnitTests/ResourceHooks/ResourceHookExecutor/Create/BeforeCreateTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public void BeforeCreate()
2222
var todoList = CreateTodoWithOwner();
2323

2424
// act
25-
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Create);
25+
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Post);
2626
// assert
27-
todoResourceMock.Verify(rd => rd.BeforeCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Create), Times.Once());
28-
ownerResourceMock.Verify(rd => rd.BeforeUpdateRelationship(It.IsAny<HashSet<string>>(), It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Create), Times.Once());
27+
todoResourceMock.Verify(rd => rd.BeforeCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Post), Times.Once());
28+
ownerResourceMock.Verify(rd => rd.BeforeUpdateRelationship(It.IsAny<HashSet<string>>(), It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Post), Times.Once());
2929
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
3030
}
3131

@@ -41,10 +41,10 @@ public void BeforeCreate_Without_Parent_Hook_Implemented()
4141
var todoList = CreateTodoWithOwner();
4242

4343
// act
44-
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Create);
44+
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Post);
4545
// assert
46-
todoResourceMock.Verify(rd => rd.BeforeCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Create), Times.Never());
47-
ownerResourceMock.Verify(rd => rd.BeforeUpdateRelationship(It.IsAny<HashSet<string>>(), It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Create), Times.Once());
46+
todoResourceMock.Verify(rd => rd.BeforeCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Post), Times.Never());
47+
ownerResourceMock.Verify(rd => rd.BeforeUpdateRelationship(It.IsAny<HashSet<string>>(), It.IsAny<IAffectedRelationships<Person>>(), ResourcePipeline.Post), Times.Once());
4848
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
4949
}
5050
[Fact]
@@ -59,9 +59,9 @@ public void BeforeCreate_Without_Child_Hook_Implemented()
5959
var todoList = CreateTodoWithOwner();
6060

6161
// act
62-
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Create);
62+
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Post);
6363
// assert
64-
todoResourceMock.Verify(rd => rd.BeforeCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Create), Times.Once());
64+
todoResourceMock.Verify(rd => rd.BeforeCreate(It.IsAny<HashSet<TodoItem>>(), ResourcePipeline.Post), Times.Once());
6565
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
6666
}
6767
[Fact]
@@ -76,7 +76,7 @@ public void BeforeCreate_Without_Any_Hook_Implemented()
7676
var todoList = CreateTodoWithOwner();
7777

7878
// act
79-
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Create);
79+
hookExecutor.BeforeCreate(todoList, ResourcePipeline.Post);
8080
// assert
8181
VerifyNoOtherCalls(todoResourceMock, ownerResourceMock);
8282
}

0 commit comments

Comments
 (0)