Skip to content
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

Write enhancements (continued) #875

Merged
merged 65 commits into from
Nov 17, 2020
Merged

Write enhancements (continued) #875

merged 65 commits into from
Nov 17, 2020

Conversation

bart-degreed
Copy link
Contributor

@bart-degreed bart-degreed commented Nov 10, 2020

Continuation of #851.

This PR primarily concerns write operations and addresses several topics:

  • Add POST/DELETE relationship endpoints, which enable to add/remove resources to/from a to-many relationship.
  • Redesign of handling updates, where we try to fetch the minimum data required to perform the operation. If the operation fails, we run additional queries to determine why and produce a descriptive error according to json:api requirements.
  • Rely more on the EF Core navigation metadata model, instead of dealing with foreign keys directly.
  • Apply the whole operation in a single SaveChanges() call, removing the need for internal transaction management.
  • Add resource change tracking for POST, similar to PATCH. Note that in practice, you'll only notice if using client-generated IDs.
  • Add documentation for create/update/delete endpoints, including examples.
  • Add support for required relationships.
  • Add support for database tables where the primary key starts with 0 or Guid.Empty.
  • Refactoring of tests to hit all combinations of create/update/delete for the various endpoints and relationship kinds.
  • Additional tests and improved error messages for corner cases like malformed request bodies, foreign key constraint violations, implicit removal in one-to-one relationships, required/optional relationships, composite foreign keys and obfuscated IDs.
  • Replaced IResourceRepository dependency in resource services with IResourceRepositoryAccessor, which dynamically queries the IoC container for a compatible repository and forwards the request to it.
  • Replaced optional IResourceHookExecutor dependency in resource services with IResourceHookExecutorFacade. Depending on startup options, we register an implementation that does nothing (the default) or delegate to hook executor.
  • Added IHasMultipleErrors, which users can add to their custom exceptions, so JADNC will serialize a proper error response for them. (ping @bjornharrtell)
  • Added extension method AddResourceRepository() on IServiceCollection, similar to AddResourceService(). This registers repositories by their read and write interface, which is now needed due to IResourceRepositoryAccessor usage. Note you only need this when not using service discovery.
  • Added protected virtual method in repository that enables to override saving changes to DbContext.
  • Replaced static JsonApiOptions.RelatedIdMapper property with settable properties on HasManyThroughAttribute (to use non-default primary key names). For the other relationship kinds, we don't need this information anymore, as we rely on the user-defined EF Core mappings.
  • Fixed: we used to return 200 OK with { data: null } in PATCH responses without side effects, where we should return 204 No Content without a body.
  • Lots of other fixes, some of them below...

Fixes #353
Fixes #850
Fixes #852
Fixes #853
Fixes #578
Fixes #870
Fixes #790
Fixes #363
Fixes #690

@bart-degreed bart-degreed mentioned this pull request Nov 10, 2020
Bart Koelman and others added 26 commits November 13, 2020 14:08
…nt test, fix bug in HasFkLeftSide method in repo
…opy/paste Update method in derived classes
@maurei maurei merged commit baa1802 into master Nov 17, 2020
@maurei maurei deleted the write-enhancements branch November 17, 2020 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment