-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #822 from bart-degreed/soft-deletion-fixes
Fixes in resource definition callbacks
- Loading branch information
Showing
13 changed files
with
607 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/JsonApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/CompaniesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.Controllers; | ||
using JsonApiDotNetCore.Services; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class CompaniesController : JsonApiController<Company> | ||
{ | ||
public CompaniesController(IJsonApiOptions options, ILoggerFactory loggerFactory, | ||
IResourceService<Company> resourceService) | ||
: base(options, loggerFactory, resourceService) | ||
{ | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/JsonApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/Company.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Generic; | ||
using JsonApiDotNetCore.Resources; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class Company : Identifiable | ||
{ | ||
[Attr] | ||
public string Name { get; set; } | ||
|
||
[Attr] | ||
public bool IsSoftDeleted { get; set; } | ||
|
||
[HasMany] | ||
public ICollection<Department> Departments { get; set; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../JsonApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/CompanyResourceDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Linq; | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.Queries.Expressions; | ||
using JsonApiDotNetCore.Resources; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class CompanyResourceDefinition : ResourceDefinition<Company> | ||
{ | ||
private readonly IResourceGraph _resourceGraph; | ||
|
||
public CompanyResourceDefinition(IResourceGraph resourceGraph) : base(resourceGraph) | ||
{ | ||
_resourceGraph = resourceGraph; | ||
} | ||
|
||
public override FilterExpression OnApplyFilter(FilterExpression existingFilter) | ||
{ | ||
var resourceContext = _resourceGraph.GetResourceContext<Company>(); | ||
var isSoftDeletedAttribute = resourceContext.Attributes.Single(attribute => attribute.Property.Name == nameof(Company.IsSoftDeleted)); | ||
|
||
var isNotSoftDeleted = new ComparisonExpression(ComparisonOperator.Equals, | ||
new ResourceFieldChainExpression(isSoftDeletedAttribute), new LiteralConstantExpression("false")); | ||
|
||
return existingFilter == null | ||
? (FilterExpression) isNotSoftDeleted | ||
: new LogicalExpression(LogicalOperator.And, new[] {isNotSoftDeleted, existingFilter}); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/JsonApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/Department.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using JsonApiDotNetCore.Resources; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class Department : Identifiable | ||
{ | ||
[Attr] | ||
public string Name { get; set; } | ||
|
||
[Attr] | ||
public bool IsSoftDeleted { get; set; } | ||
|
||
[HasOne] | ||
public Company Company { get; set; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...onApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/DepartmentResourceDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Linq; | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.Queries.Expressions; | ||
using JsonApiDotNetCore.Resources; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class DepartmentResourceDefinition : ResourceDefinition<Department> | ||
{ | ||
private readonly IResourceGraph _resourceGraph; | ||
|
||
public DepartmentResourceDefinition(IResourceGraph resourceGraph) : base(resourceGraph) | ||
{ | ||
_resourceGraph = resourceGraph; | ||
} | ||
|
||
public override FilterExpression OnApplyFilter(FilterExpression existingFilter) | ||
{ | ||
var resourceContext = _resourceGraph.GetResourceContext<Department>(); | ||
var isSoftDeletedAttribute = resourceContext.Attributes.Single(attribute => attribute.Property.Name == nameof(Department.IsSoftDeleted)); | ||
|
||
var isNotSoftDeleted = new ComparisonExpression(ComparisonOperator.Equals, | ||
new ResourceFieldChainExpression(isSoftDeletedAttribute), new LiteralConstantExpression("false")); | ||
|
||
return existingFilter == null | ||
? (FilterExpression) isNotSoftDeleted | ||
: new LogicalExpression(LogicalOperator.And, new[] {isNotSoftDeleted, existingFilter}); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/JsonApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/DepartmentsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using JsonApiDotNetCore.Configuration; | ||
using JsonApiDotNetCore.Controllers; | ||
using JsonApiDotNetCore.Services; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class DepartmentsController : JsonApiController<Department> | ||
{ | ||
public DepartmentsController(IJsonApiOptions options, ILoggerFactory loggerFactory, | ||
IResourceService<Department> resourceService) | ||
: base(options, loggerFactory, resourceService) | ||
{ | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test/JsonApiDotNetCoreExampleTests/IntegrationTests/SoftDeletion/SoftDeletionDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.SoftDeletion | ||
{ | ||
public sealed class SoftDeletionDbContext : DbContext | ||
{ | ||
public DbSet<Company> Companies { get; set; } | ||
public DbSet<Department> Departments { get; set; } | ||
|
||
public SoftDeletionDbContext(DbContextOptions<SoftDeletionDbContext> options) : base(options) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.