|
8 | 8 | using Microsoft.Extensions.Logging;
|
9 | 9 | using System.Security.Principal;
|
10 | 10 |
|
11 |
| -//namespace JsonApiDotNetCoreExample.Resources |
12 |
| -//{ |
13 |
| -// public class ArticleResource : ResourceDefinition<Article> |
14 |
| -// { |
15 |
| -// public override IEnumerable<Article> OnReturn(HashSet<Article> entities, ResourcePipeline pipeline) |
16 |
| -// { |
17 |
| -// if (pipeline == ResourcePipeline.ReadSingle && entities.Single().Name == "Classified") |
18 |
| -// { |
19 |
| -// throw new JsonApiException(403, "You are not allowed to see this article!", new UnauthorizedAccessException()); |
20 |
| -// } |
21 |
| -// return entities.Where(t => t.Name != "This should be not be included"); |
22 |
| -// } |
23 |
| -// } |
24 |
| -//} |
| 11 | +namespace JsonApiDotNetCoreExample.Resources |
| 12 | +{ |
| 13 | + public class ArticleResource : ResourceDefinition<Article> |
| 14 | + { |
| 15 | + public override IEnumerable<Article> OnReturn(HashSet<Article> entities, ResourcePipeline pipeline) |
| 16 | + { |
| 17 | + if (pipeline == ResourcePipeline.ReadSingle && entities.Single().Name == "Classified") |
| 18 | + { |
| 19 | + throw new JsonApiException(403, "You are not allowed to see this article!", new UnauthorizedAccessException()); |
| 20 | + } |
| 21 | + return entities.Where(t => t.Name != "This should be not be included"); |
| 22 | + } |
| 23 | + } |
| 24 | +} |
25 | 25 |
|
26 |
| - |
27 |
| - |
28 |
| -//namespace JsonApiDotNetCoreExample.Resources |
29 |
| -//{ |
30 |
| - |
31 |
| -// /// This is a scoped service, which means wil log will have a request-based |
32 |
| -// /// unique id associated to it. |
33 |
| -// public class UserActionsLogger : IUserActionsLogger |
34 |
| -// { |
35 |
| -// public ILogger GetLogger { get; private set; } |
36 |
| -// public UserActionsLogger(ILoggerFactory loggerFactory, |
37 |
| -// IUserService userService) |
38 |
| -// { |
39 |
| -// var userId = userService.GetUser().Id; |
40 |
| -// GetLogger = loggerFactory.CreateLogger($"[request: {Guid.NewGuid()}, user: {userId}] User Actions Log:"); |
41 |
| -// } |
42 |
| -// } |
43 |
| - |
44 |
| -// /// Resource definitions are also injected as scoped services. |
45 |
| -// public class ArticleResource : ResourceDefinition<Article> |
46 |
| -// { |
47 |
| - |
48 |
| -// public override IEnumerable<Article> OnReturn(HashSet<Article> entities, ResourcePipeline pipeline) |
49 |
| -// { |
50 |
| -// return entities.Where(a => a.SoftDeleted == false); |
51 |
| -// } |
52 |
| - |
53 |
| -// } |
54 |
| - |
55 |
| -// public class PersonResource : ResourceDefinition<Person> |
56 |
| -// { |
57 |
| -// public override IEnumerable<Person> OnReturn(HashSet<Person> entities, ResourcePipeline pipeline) |
58 |
| -// { |
59 |
| -// if (pipeline == ResourcePipeline.Get || pipeline == ResourcePipeline.GetSingle) |
60 |
| -// { |
61 |
| -// return entities.Where(p => !p.WantsPrivacy); |
62 |
| -// } |
63 |
| -// return entities; |
64 |
| -// } |
65 |
| -// } |
66 |
| -//} |
0 commit comments