Skip to content

Commit 151c82c

Browse files
author
Chris Santero
committed
MappedDocumentMaterializer: allow performing final modifications to resource
1 parent 4f517a0 commit 151c82c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

JSONAPI/Http/MappedDocumentMaterializer.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43
using System.Linq.Expressions;
54
using System.Net.Http;
6-
using System.Reflection;
75
using System.Threading;
86
using System.Threading.Tasks;
97
using JSONAPI.Core;
@@ -83,6 +81,8 @@ public virtual async Task<ISingleResourceDocument> GetRecordById(string id, Http
8381
throw JsonApiException.CreateForNotFound(
8482
string.Format("No record exists with type `{0}` and ID `{1}`.", ResourceTypeName, id));
8583

84+
await OnResourceFetched(primaryResource);
85+
8686
var baseUrl = _baseUrlService.GetBaseUrl(request);
8787
return _singleResourceDocumentBuilder.BuildDocument(primaryResource, baseUrl, jsonApiPaths, null);
8888
}
@@ -112,7 +112,17 @@ protected virtual Expression<Func<TDto, object>>[] GetIncludePathsForSingleResou
112112
{
113113
return null;
114114
}
115-
115+
116+
/// <summary>
117+
/// Hook for performing any final modifications to the resource before serialization
118+
/// </summary>
119+
/// <param name="resource"></param>
120+
/// <returns></returns>
121+
protected virtual Task OnResourceFetched(TDto resource)
122+
{
123+
return Task.FromResult(0);
124+
}
125+
116126
private string ConvertToJsonKeyPath(Expression<Func<TDto, object>> expression)
117127
{
118128
var visitor = new PathVisitor(_resourceTypeRegistry);

0 commit comments

Comments
 (0)