Skip to content

Commit d7b5b55

Browse files
committed
documentation: finish
1 parent 4a6e2e3 commit d7b5b55

File tree

1 file changed

+14
-55
lines changed

1 file changed

+14
-55
lines changed

src/Examples/JsonApiDotNetCoreExample/Resources/ArticleResource.cs

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,18 @@
88
using Microsoft.Extensions.Logging;
99
using System.Security.Principal;
1010

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+
}
2525

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

Comments
 (0)