Skip to content

Relationship endpoint bugfixes, implement POST and DELETE on to-many relationship link #851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 274 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
274 commits
Select commit Hold shift + click to select a range
3b82416
feat: implemented post and delete to-many by using refactored code of…
maurei Oct 6, 2020
f68e82e
chore: self review
maurei Oct 6, 2020
7c84aed
feat: implemented new pipeline elements for the repository, performed…
maurei Oct 7, 2020
4b500e9
fix: merge
maurei Oct 7, 2020
f4853af
chore: refactor
maurei Oct 8, 2020
fee6027
fix: remove test that is no longer expected to pass after refactor of…
maurei Oct 8, 2020
a30c62c
chore: self review
maurei Oct 8, 2020
baa649f
fix: test
maurei Oct 8, 2020
90a2051
fix: failing test
maurei Oct 8, 2020
9f5606f
chore: self review
maurei Oct 12, 2020
7236fb4
Refactored AddRepositoryLayer/AddServiceLayer
Oct 12, 2020
fcc42b7
fix broken tests
Oct 12, 2020
5ea2ca5
fix logging
Oct 12, 2020
15c52a2
relationship renames and documentation
Oct 12, 2020
4d677a7
renamed exception
Oct 12, 2020
4d95ea3
First steps in error refactoring
Oct 12, 2020
5f2f430
removed comments
Oct 12, 2020
0a0612b
chore: refactor service layer
maurei Oct 12, 2020
a8222ef
chore: cleanup
maurei Oct 12, 2020
ad76ccb
fix: test error missing relationship assignment resources
maurei Oct 12, 2020
1e8ebdd
feat: support for composite foreign keys
maurei Oct 12, 2020
e0be517
feat: return secondary resources from GetRelationshipAsync service pi…
maurei Oct 12, 2020
37da563
fix broken build
Oct 13, 2020
ab5a05d
fix broken tests
Oct 13, 2020
07968fb
Cleanup RepositoryAccessor
Oct 13, 2020
222b831
Merge branch 'master' into feat/post-relationship-link-353
Oct 13, 2020
bc87317
TopFieldSelection
Oct 13, 2020
aa8ba92
fixes and cleanup
Oct 13, 2020
92f9eef
test: test cases for set RequestRelationship no longer relevant
maurei Oct 13, 2020
1bf957e
tests: missing resources in relationship endpoint tests
maurei Oct 13, 2020
790734b
Refactored mising resources in relationships at service layer
Oct 13, 2020
180779f
plural naming because it may affect multiple relationships
Oct 13, 2020
37d7489
Merge remote-tracking branch 'upstream/master' into feat/post-relatio…
Oct 13, 2020
9adeab9
fixed broken build
Oct 13, 2020
8f2b331
more cleanup
Oct 14, 2020
6058e5a
repository renames
Oct 14, 2020
3106f14
fixed test for composite foreign keys
Oct 14, 2020
25a1604
Temporary snapshot for work in progress...
Oct 14, 2020
a599f60
Rewrite of UpdatingRelationshipsTests to new syntax
Oct 14, 2020
140cb52
fixed broken test
Oct 15, 2020
754a05e
fixed broken test
Oct 15, 2020
2539126
refactored inverse navigation handling
Oct 15, 2020
672edfe
Merge branch 'master' into feat/post-relationship-link-353
Oct 15, 2020
8ba2cf6
fix: broken tests except for missing primary resource test
maurei Oct 15, 2020
36baa5a
fix: merge
maurei Oct 15, 2020
ac0eec2
cleanup
Oct 15, 2020
92f7a92
fix test
Oct 15, 2020
6cff598
renames
Oct 15, 2020
c5e67a7
revert diff
Oct 15, 2020
e23b368
feat: remove excess inverse loading logic
maurei Oct 15, 2020
230d712
Refactored CreatingDataTests to use new syntax
Oct 15, 2020
47ab72a
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 15, 2020
fe0e463
various comments
Oct 16, 2020
7705a38
added tests to ModelStateValidationTests for new endpoints
Oct 16, 2020
1fa1287
more cleanup
Oct 16, 2020
994ed05
test: skip injectable resource test until efcore 5 lands
maurei Oct 16, 2020
cb528e9
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Oct 16, 2020
f26e88a
Merged tests
Oct 16, 2020
d3e2174
move/merge tests
Oct 16, 2020
e571406
isolated tests with composite primary key
Oct 16, 2020
7cff727
Added TODO
Oct 16, 2020
ea16a8b
clean; update test to allow deleting non-existing relationship
Oct 16, 2020
4140c6a
added remarks
Oct 16, 2020
66a173b
Merge
maurei Oct 17, 2020
0bc914b
chore: replied to a Todo, removed flushing and simplified helper meth…
maurei Oct 17, 2020
159b6d6
feat: add FK relationship assignment optimalization in case of relati…
maurei Oct 17, 2020
18fae52
chore: refactor around SetRelationshipsAsync and UpdateAsync
maurei Oct 17, 2020
ebbf430
fix: debugged foreign key assignment optimization in repository
maurei Oct 18, 2020
e5ffdbc
fix: improved FK optimization
maurei Oct 18, 2020
7686cbf
chore: refactor
maurei Oct 19, 2020
50dd481
chore: cleanup
maurei Oct 19, 2020
e9ae2a0
cleanup
Oct 19, 2020
9059a57
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 19, 2020
a1a5736
comments
Oct 19, 2020
8e3ffb3
feat: remove dependency on foreign keys
maurei Oct 19, 2020
7efe790
chore: worked through todos
maurei Oct 19, 2020
44f454b
workaround for https://github.com/dotnet/efcore/issues/20502
Oct 19, 2020
a8b913d
fix: rename
maurei Oct 19, 2020
967b97d
Comment
maurei Oct 19, 2020
a4e52de
chore: refactor
maurei Oct 20, 2020
ff564ec
chore: refactor using EnsureCompleteReplacement, add two todos
maurei Oct 20, 2020
a0fe2db
chore: add todo
maurei Oct 20, 2020
44fd448
renames
Oct 20, 2020
eb0bcd9
changes on resource factory
Oct 20, 2020
a711f4f
chore: refactor proposal
maurei Oct 20, 2020
d2a06ad
chore: add comment
maurei Oct 20, 2020
acbf66f
chore: rename
maurei Oct 20, 2020
3172e41
comments
Oct 20, 2020
764f033
fix: Todo item on NoContent in PatchAsync controller method
maurei Oct 20, 2020
4bf60de
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 20, 2020
1627bef
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 20, 2020
0c4d3b6
revert: removed assertions on response body
Oct 20, 2020
78cb9cc
revert name changes
Oct 20, 2020
dfcd28d
Use ISet in public signatures
Oct 20, 2020
6d72a0c
made public
Oct 20, 2020
9e81c91
docs update
Oct 21, 2020
c8630bc
Refactored and isolated tests for resource creation (without relation…
Oct 21, 2020
411b52d
Added tests for create with relationships
Oct 21, 2020
067c553
feat: ISet in serializer, 204/200 return values post/patch
maurei Oct 22, 2020
cc728f4
feat: support post relationships endpoint for many-to-many
maurei Oct 22, 2020
b7a90b9
chore: review
maurei Oct 22, 2020
c5d0816
fix: additional logging flaky test
maurei Oct 22, 2020
825d7db
chore: made GetManyValue internal
maurei Oct 22, 2020
a500a1d
Test improvements and cleanup. Removed TODO claiming that checking on…
Oct 22, 2020
7126be7
Replaced TODO with GitHub issue https://github.com/json-api-dotnet/Js…
Oct 22, 2020
b35b1a2
review
Oct 22, 2020
0a7805d
fix cibuild
Oct 22, 2020
844a886
added tests for delete resource
Oct 22, 2020
b72735a
more on tests
Oct 23, 2020
a3a1ffb
chore: review
maurei Oct 23, 2020
3b36f8f
fix: resource factory null check
maurei Oct 23, 2020
74aa64f
chore: review
maurei Oct 23, 2020
515d778
chore: static setter ResourceFactory HasManyThroughAttribute
maurei Oct 23, 2020
f7e233f
revert
maurei Oct 23, 2020
fcd86e8
fix: Remove AsNoTracking in favour of explicit loading
maurei Oct 23, 2020
2b9db0d
Moved tests from the wrong folder
Oct 23, 2020
4d1406f
fix test
Oct 23, 2020
9b29fd4
Tests for posting to HasMany relationship through relationship endpoint
Oct 23, 2020
d8096cf
fix flaky test
Oct 23, 2020
4bb8dd9
Deterministic fakers
Oct 23, 2020
272a102
Updates on TODOs
Oct 24, 2020
96562eb
reduced test duplication
Oct 24, 2020
f61b44f
Added tests for removing from to-many relationships through DELETE re…
Oct 24, 2020
7cd3ff0
tomany test tweaks
Oct 24, 2020
95f0e35
removed old test
Oct 24, 2020
04db10e
more on tests
Oct 24, 2020
a64cc14
rename test
Oct 26, 2020
5c4fa96
Fixed: let fakers generate different data on subsequent calls within …
Oct 26, 2020
d2421b8
Added tests for update to-one relationships through relationships end…
Oct 26, 2020
575d66a
Refactor tests: .Where(expr).FirstAsync() -> .FirstAsync(expr)
Oct 26, 2020
6a3ed79
Added tests for updating to-many relationships through relationships …
Oct 26, 2020
cb75a0b
fixed: missing null check
Oct 26, 2020
f2f8dcb
Fix for disabled test: Cannot_remove_for_relationship_mismatch_betwee…
Oct 26, 2020
f8a87d3
feat: remove already related resources from assignment with expressio…
maurei Oct 26, 2020
016e0c6
fix: merge
maurei Oct 26, 2020
fff7aa1
cleanup
Oct 27, 2020
4fcc8e8
chore: improved GetFilteredThroughEntities call and reused it in Enab…
maurei Oct 27, 2020
4ce2cd0
merge
maurei Oct 27, 2020
00258f2
renames
Oct 27, 2020
ec31388
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 27, 2020
39fa101
Revert: commented-out code. This is needed to guard internal consiste…
Oct 27, 2020
e8db7fe
updated test
Oct 27, 2020
d68e584
Clarified documentation that PATCH replaces relationships.
Oct 27, 2020
d4787e9
added tests for missing cases
Oct 27, 2020
6d9ebff
changed tests order for consistency
Oct 27, 2020
b142258
Added tests for updating to-one relationships through primary endpoint
Oct 27, 2020
075b081
chore: review, remove resource factory, todos
maurei Oct 27, 2020
4a83fad
chore: add todos
maurei Oct 27, 2020
90368ec
Added tests for updating to-many relationships through primary endpoint
Oct 27, 2020
9536bcd
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 27, 2020
f6cb370
chore: review
maurei Oct 27, 2020
4eac167
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Oct 27, 2020
d850c6e
revert changes
Oct 27, 2020
8dd4ba3
added missing test
Oct 28, 2020
4af1e93
chore: add todos, draft bugfix deserializer id validation
maurei Oct 28, 2020
4bc315f
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Oct 28, 2020
5274383
added missing test for create
Oct 28, 2020
333e3b0
added tests for updating resources without relationships
Oct 28, 2020
583ba50
chore: add review todos
maurei Oct 28, 2020
258f224
feat: hook executor is no longer an optional dependency
maurei Oct 28, 2020
04585d0
feat: hook executor is no longer an optional dependency
maurei Oct 28, 2020
2351d2c
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Oct 28, 2020
45f4966
added tests for attribute type mismatch
Oct 28, 2020
6333be3
removed duplicate tests
Oct 28, 2020
fbcc23f
Added tests for missing request body; fixed tests for missing ID in body
Oct 28, 2020
590860b
cleanup assertions and fixed test name
Oct 28, 2020
b35edaf
merge
maurei Oct 29, 2020
914c8a2
chore: add review todos
maurei Oct 29, 2020
526a00e
chore: review todos
maurei Oct 29, 2020
413479e
fix broken build
Oct 29, 2020
6d5a332
cleanup hooks
Oct 29, 2020
f8e2875
Use public name in error for setting read-only attribute.
Oct 29, 2020
430b018
Hooks: do not execute only if default non-empty implemenation is acti…
Oct 29, 2020
1b94084
FirstAsync TODOs
Oct 29, 2020
50614b8
revert whitespace changes
Oct 29, 2020
3d41f45
revert unneeded whitespace changes
Oct 29, 2020
55a345c
Clarified test names for blocked usage
Oct 29, 2020
d451fc5
Replacement of ToListAsync with FirstAsync in tests
Oct 29, 2020
a1bdbc4
Renamed WorkItem.AssignedTo to WorkItem.Assignee
Oct 29, 2020
258a2bc
test improvements
Oct 29, 2020
756b8ff
Fail with status Conflict for pre-existing resource ID in POST.
Oct 29, 2020
e078b7e
Fail when trying to update resource ID
Oct 29, 2020
13ad9f5
test: Can_create_resource_with_duplicate_HasOne_relationship_member t…
maurei Oct 30, 2020
da53b64
chore: remove finished todo
maurei Oct 30, 2020
e5eb798
chore: remove setting of FK in base deserializer
maurei Oct 30, 2020
53f5cd6
Wrap hooks execution in facade that fits the needs of resource service.
Oct 30, 2020
f483990
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Oct 30, 2020
9974b42
renamed test to match existing conventions
Oct 30, 2020
0ad8c8a
cleanup and revert changes
Oct 30, 2020
68f6a74
feat: draft for using raw queries in complete replacement
maurei Nov 2, 2020
0ae089d
chore: remove draft, add todo about complete replacement performance …
maurei Nov 2, 2020
17f93f6
removed duplicate test
Nov 2, 2020
eee289c
re-orderd tests
Nov 2, 2020
e405d31
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 2, 2020
9804a93
chore: revert nuget package
maurei Nov 2, 2020
394ce8e
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Nov 2, 2020
4187065
chore: revert
maurei Nov 2, 2020
59d6836
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 2, 2020
ce43c6e
revert: remove duplicate (it was not)
Nov 2, 2020
69038e1
feat: correct deletion of resources when EF Core deletion requires en…
maurei Nov 2, 2020
f2e2320
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 2, 2020
6911398
refactor: remove use of RelatedIdMapper
maurei Nov 2, 2020
81ca325
Fixed: attributes must never have optional constructor parameters
Nov 2, 2020
d38e8b2
added todo and revert whitespace changes
Nov 2, 2020
7e90f2c
added missing tests
Nov 2, 2020
8036daf
added more missing tests
Nov 2, 2020
b149365
review
maurei Nov 2, 2020
c85583c
review
maurei Nov 2, 2020
8faf1d0
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 2, 2020
87f2012
chore: remove commented out code
maurei Nov 2, 2020
0bb759d
remove comments
Nov 2, 2020
644edba
added missing test
Nov 2, 2020
80d53b9
Removed unneeded Ignore: property already has NotMapped.
Nov 2, 2020
01cbcad
- Fixed: In POST resource, ?fields= must not influence change tracker…
Nov 2, 2020
885fb7e
added composite test (attr plus multiple relationships) for patch res…
Nov 2, 2020
1477a10
Split of CreateResourceWithRelationshipTests
Nov 2, 2020
493d7da
removed old test (duplicate)
Nov 2, 2020
f0c5c9f
replaced more old tests
Nov 2, 2020
34ac223
Removed TODO (these are implemented by Cannot_replace_on_relationship…
Nov 2, 2020
b6d4122
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 3, 2020
c0a52aa
fix: fix bug for update/create with include/fieldset
maurei Nov 3, 2020
6b070e5
Remove explicit foreign key properties from models
Nov 3, 2020
c470289
cleanup example models
Nov 3, 2020
f17a90f
removed left-over todo
Nov 3, 2020
52a0421
Reduced usage of InvalidRequestBodyException
Nov 3, 2020
c9bcba8
feat: preview spec compliance in 404 remove from relationship endpoint
maurei Nov 3, 2020
0e0f693
Moved throwing InvalidRequestBodyException out of resource service.
Nov 3, 2020
12e082f
fix: cleanup FlushFromCache
maurei Nov 3, 2020
a0cddab
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 3, 2020
f0cd7f0
fix: resource factory usage bug in static query building
maurei Nov 3, 2020
bfc6773
Wrap serialization errors
Nov 3, 2020
e688863
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Nov 3, 2020
d110dfa
removed unneeded new whitespace
Nov 3, 2020
becb87d
comments
Nov 3, 2020
0673986
merge
maurei Nov 3, 2020
a263977
feat: ThroughEntityFilter service to abstract away getting of through…
maurei Nov 4, 2020
fbcdda2
chore: add overload to DataStoreUpdateException
maurei Nov 4, 2020
f0e5a1f
chore: renamed composite foreign key test to not repeat 'composite_fo…
maurei Nov 4, 2020
08e5978
tests: added new composite foreign key tests
maurei Nov 4, 2020
480cf30
test: composite foreign key relationship tests
maurei Nov 4, 2020
2eac821
chore: review, revert accessor
maurei Nov 4, 2020
c731281
chore: rename Destination to Address in Dealership, fix IResourceRead…
maurei Nov 4, 2020
596a331
cleanup
Nov 4, 2020
d7ba03d
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
Nov 4, 2020
896af96
fix: revert unneccesary changes, add validation test for document parser
maurei Nov 4, 2020
3f15618
test: add clear one-to-one
maurei Nov 4, 2020
edccb59
post-merge fixes
Nov 4, 2020
73285dd
changed to offset for better coverage
Nov 4, 2020
bb5be51
Merge branch 'feat/post-relationship-link-353' of https://github.com/…
maurei Nov 4, 2020
cec8104
test: add clearing one-to-one tests
maurei Nov 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.Design;
using BenchmarkDotNet.Attributes;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Serialization;
using JsonApiDotNetCore.Serialization.Objects;
Expand Down Expand Up @@ -37,7 +38,8 @@ public JsonApiDeserializerBenchmarks()
var options = new JsonApiOptions();
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
var targetedFields = new TargetedFields();
_jsonApiDeserializer = new RequestDeserializer(resourceGraph, new ResourceFactory(new ServiceContainer()), targetedFields, new HttpContextAccessor());
var request = new JsonApiRequest();
_jsonApiDeserializer = new RequestDeserializer(resourceGraph, new ResourceFactory(new ServiceContainer()), targetedFields, new HttpContextAccessor(), request);
}

[Benchmark]
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Serialization/JsonApiSerializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static FieldsToSerialize CreateFieldsToSerialize(IResourceGraph resource

var accessor = new Mock<IResourceDefinitionAccessor>().Object;

return new FieldsToSerialize(resourceGraph, constraintProviders, accessor);
return new FieldsToSerialize(resourceGraph, constraintProviders, accessor, request);
}

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers.Annotations;
using JsonApiDotNetCore.Errors;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Serialization.Objects;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Models;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -133,9 +131,10 @@ public async Task<IActionResult> PatchAsync(TId id, [FromBody] T resource)
}

[HttpPatch("{id}/relationships/{relationshipName}")]
public async Task<IActionResult> PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List<ResourceObject> relationships)
public async Task<IActionResult> PatchRelationshipAsync(TId id, string relationshipName, [FromBody] object secondaryResourceIds)
{
await _resourceService.UpdateRelationshipAsync(id, relationshipName, relationships);
await _resourceService.SetRelationshipAsync(id, relationshipName, secondaryResourceIds);

return Ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public override async Task<IActionResult> PatchAsync(int id, [FromBody] TodoItem

[HttpPatch("{id}/relationships/{relationshipName}")]
public override async Task<IActionResult> PatchRelationshipAsync(
int id, string relationshipName, [FromBody] object relationships)
=> await base.PatchRelationshipAsync(id, relationshipName, relationships);
int id, string relationshipName, [FromBody] object secondaryResourceIds)
=> await base.PatchRelationshipAsync(id, relationshipName, secondaryResourceIds);

[HttpDelete("{id}")]
public override async Task<IActionResult> DeleteAsync(int id)
Expand Down
24 changes: 10 additions & 14 deletions src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,34 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TodoItem>()
.HasOne(t => t.Assignee)
.WithMany(p => p.AssignedTodoItems)
.HasForeignKey(t => t.AssigneeId);
.WithMany(p => p.AssignedTodoItems);

modelBuilder.Entity<TodoItem>()
.HasOne(t => t.Owner)
.WithMany(p => p.TodoItems)
.HasForeignKey(t => t.OwnerId);
.WithMany(p => p.TodoItems);

modelBuilder.Entity<ArticleTag>()
.HasKey(bc => new { bc.ArticleId, bc.TagId });
.HasKey(bc => new {bc.ArticleId, bc.TagId});

modelBuilder.Entity<IdentifiableArticleTag>()
.HasKey(bc => new { bc.ArticleId, bc.TagId });
.HasKey(bc => new {bc.ArticleId, bc.TagId});

modelBuilder.Entity<Person>()
.HasOne(t => t.StakeHolderTodoItem)
.WithMany(t => t.StakeHolders)
.HasForeignKey(t => t.StakeHolderTodoItemId)
.OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity<TodoItem>()
.HasOne(t => t.DependentOnTodo);

modelBuilder.Entity<TodoItem>()
.HasMany(t => t.ChildrenTodos)
.WithOne(t => t.ParentTodo)
.HasForeignKey(t => t.ParentTodoId);
.WithOne(t => t.ParentTodo);

modelBuilder.Entity<Passport>()
.HasOne(p => p.Person)
.WithOne(p => p.Passport)
.HasForeignKey<Person>(p => p.PassportId)
.HasForeignKey<Person>("PassportKey")
.OnDelete(DeleteBehavior.SetNull);

modelBuilder.Entity<Passport>()
Expand All @@ -81,17 +77,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<TodoItem>()
.HasOne(p => p.OneToOnePerson)
.WithOne(p => p.OneToOneTodoItem)
.HasForeignKey<TodoItem>(p => p.OneToOnePersonId);
.HasForeignKey<TodoItem>("OneToOnePersonKey");

modelBuilder.Entity<TodoItemCollection>()
.HasOne(p => p.Owner)
.WithMany(p => p.TodoCollections)
.OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity<Person>()
.HasOne(p => p.OneToOneTodoItem)
.WithOne(p => p.OneToOnePerson)
.HasForeignKey<TodoItem>(p => p.OneToOnePersonId);
.HasOne(p => p.Role)
.WithOne(p => p.Person)
.HasForeignKey<Person>("PersonRoleKey");
}
}
}
16 changes: 0 additions & 16 deletions src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace JsonApiDotNetCoreExample.Models
{
public sealed class ArticleTag
Expand All @@ -11,17 +8,4 @@ public sealed class ArticleTag
public int TagId { get; set; }
public Tag Tag { get; set; }
}

public class IdentifiableArticleTag : Identifiable
{
public int ArticleId { get; set; }
[HasOne]
public Article Article { get; set; }

public int TagId { get; set; }
[HasOne]
public Tag Tag { get; set; }

public string SomeMetaData { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace JsonApiDotNetCoreExample.Models
{
public class IdentifiableArticleTag : Identifiable
{
public int ArticleId { get; set; }
[HasOne]
public Article Article { get; set; }

public int TagId { get; set; }
[HasOne]
public Tag Tag { get; set; }

public string SomeMetaData { get; set; }
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public int? SocialSecurityNumber
[NotMapped]
public string BirthCountryName
{
get => BirthCountry.Name;
get => BirthCountry?.Name;
set
{
BirthCountry ??= new Country();
Expand Down
3 changes: 0 additions & 3 deletions src/Examples/JsonApiDotNetCoreExample/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,17 @@ public string FirstName

[HasOne]
public PersonRole Role { get; set; }
public int? PersonRoleId { get; set; }

[HasOne]
public TodoItem OneToOneTodoItem { get; set; }

[HasOne]
public TodoItem StakeHolderTodoItem { get; set; }
public int? StakeHolderTodoItemId { get; set; }

[HasOne(Links = LinkTypes.All, CanInclude = false)]
public TodoItem UnIncludeableItem { get; set; }

[HasOne]
public Passport Passport { get; set; }
public int? PassportId { get; set; }
}
}
7 changes: 0 additions & 7 deletions src/Examples/JsonApiDotNetCoreExample/Models/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@ public class Tag : Identifiable
[Attr]
public TagColor Color { get; set; }
}

public enum TagColor
{
Red,
Green,
Blue
}
}
9 changes: 9 additions & 0 deletions src/Examples/JsonApiDotNetCoreExample/Models/TagColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace JsonApiDotNetCoreExample.Models
{
public enum TagColor
{
Red,
Green,
Blue
}
}
23 changes: 0 additions & 23 deletions src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ namespace JsonApiDotNetCoreExample.Models
{
public class TodoItem : Identifiable, IIsLockable
{
public TodoItem()
{
GuidProperty = Guid.NewGuid();
}

public bool IsLocked { get; set; }

[Attr]
Expand All @@ -20,9 +15,6 @@ public TodoItem()
[Attr]
public long Ordinal { get; set; }

[Attr]
public Guid GuidProperty { get; set; }

[Attr(Capabilities = AttrCapabilities.All & ~AttrCapabilities.AllowCreate)]
public string AlwaysChangingValue
{
Expand All @@ -36,21 +28,12 @@ public string AlwaysChangingValue
[Attr(Capabilities = AttrCapabilities.All & ~(AttrCapabilities.AllowFilter | AttrCapabilities.AllowSort))]
public DateTime? AchievedDate { get; set; }

[Attr]
public DateTime? UpdatedDate { get; set; }

[Attr(Capabilities = AttrCapabilities.All & ~(AttrCapabilities.AllowCreate | AttrCapabilities.AllowChange))]
public string CalculatedValue => "calculated";

[Attr(Capabilities = AttrCapabilities.All & ~AttrCapabilities.AllowChange)]
public DateTimeOffset? OffsetDate { get; set; }

public int? OwnerId { get; set; }

public int? AssigneeId { get; set; }

public Guid? CollectionId { get; set; }

[HasOne]
public Person Owner { get; set; }

Expand All @@ -60,23 +43,17 @@ public string AlwaysChangingValue
[HasOne]
public Person OneToOnePerson { get; set; }

public int? OneToOnePersonId { get; set; }

[HasMany]
public ISet<Person> StakeHolders { get; set; }

[HasOne]
public TodoItemCollection Collection { get; set; }

// cyclical to-one structure
public int? DependentOnTodoId { get; set; }

[HasOne]
public TodoItem DependentOnTodo { get; set; }

// cyclical to-many structure
public int? ParentTodoId {get; set;}

[HasOne]
public TodoItem ParentTodo { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public sealed class TodoItemCollection : Identifiable<Guid>

[HasOne]
public Person Owner { get; set; }

public int? OwnerId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ public class CustomArticleService : JsonApiResourceService<Article>
{
public CustomArticleService(
IResourceRepository<Article> repository,
IGetResourcesByIds getResourcesById,
IQueryLayerComposer queryLayerComposer,
IPaginationContext paginationContext,
IJsonApiOptions options,
ILoggerFactory loggerFactory,
IJsonApiRequest request,
IResourceChangeTracker<Article> resourceChangeTracker,
IResourceFactory resourceFactory,
IResourceHookExecutor hookExecutor = null)
: base(repository, queryLayerComposer, paginationContext, options, loggerFactory, request,
resourceChangeTracker, resourceFactory, hookExecutor)
ITargetedFields targetedFields,
IResourceContextProvider resourceContextProvider,
IResourceHookExecutorFacade hookExecutor)
: base(repository, getResourcesById, queryLayerComposer, paginationContext, options, loggerFactory,
request, resourceChangeTracker, resourceFactory, targetedFields, resourceContextProvider, hookExecutor)
{ }

public override async Task<Article> GetAsync(int id)
Expand Down
4 changes: 3 additions & 1 deletion src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public override void ConfigureServices(IServiceCollection services)
{
options.EnableSensitiveDataLogging();
options.UseNpgsql(_connectionString, innerOptions => innerOptions.SetPostgresVersion(new Version(9, 6)));
}, ServiceLifetime.Transient);
},
// TODO: Remove ServiceLifetime.Transient, after all integration tests have been converted to use IntegrationTestContext.
ServiceLifetime.Transient);

services.AddJsonApi<AppDbContext>(ConfigureJsonApiOptions, discovery => discovery.AddCurrentAssembly());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JsonApiDotNetCore.Queries;
using JsonApiDotNetCore.Repositories;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;
using MultiDbContextExample.Data;

Expand All @@ -12,11 +13,10 @@ public class DbContextARepository<TResource> : EntityFrameworkCoreRepository<TRe
where TResource : class, IIdentifiable<int>
{
public DbContextARepository(ITargetedFields targetedFields, DbContextResolver<DbContextA> contextResolver,
IResourceGraph resourceGraph, IGenericServiceFactory genericServiceFactory,
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders,
ILoggerFactory loggerFactory)
: base(targetedFields, contextResolver, resourceGraph, genericServiceFactory, resourceFactory,
constraintProviders, loggerFactory)
IResourceGraph resourceGraph, IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders,
IGetResourcesByIds getResourcesByIds, ILoggerFactory loggerFactory)
: base(targetedFields, contextResolver, resourceGraph, resourceFactory,
constraintProviders, getResourcesByIds, loggerFactory)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JsonApiDotNetCore.Queries;
using JsonApiDotNetCore.Repositories;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;
using MultiDbContextExample.Data;

Expand All @@ -12,11 +13,10 @@ public class DbContextBRepository<TResource> : EntityFrameworkCoreRepository<TRe
where TResource : class, IIdentifiable<int>
{
public DbContextBRepository(ITargetedFields targetedFields, DbContextResolver<DbContextB> contextResolver,
IResourceGraph resourceGraph, IGenericServiceFactory genericServiceFactory,
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders,
ILoggerFactory loggerFactory)
: base(targetedFields, contextResolver, resourceGraph, genericServiceFactory, resourceFactory,
constraintProviders, loggerFactory)
IResourceGraph resourceGraph, IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders,
IGetResourcesByIds getResourcesByIds, ILoggerFactory loggerFactory)
: base(targetedFields, contextResolver, resourceGraph, resourceFactory,
constraintProviders, getResourcesByIds, loggerFactory)
{
}
}
Expand Down
Loading