This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Refactoring of application package - Repositories interface extracted into repository subpackage This provides a global fix for import cycle issues, solving the problem of having to create a separate repositories interfaces for the service layer - Services interface introduced. Provides a convenient way for controllers to access the service layer # Decouple transaction control from the application package ## Transaction-related functionality moved to application/transaction package - Allows transactions to be managed without introducing import cycle issues with application package - Transactional method refactored: ` func Transactional(tm TransactionManager, todo func(f TransactionalResources) error) error` The `tm` parameter is used by the `Transactional` method to initiate the transaction. Code executed within the transaction block (i.e. the `todo` function) may interact with transactional resources (e.g. repositories) via the `TransactionalResources` parameter. **Some notes:** The `Application` object implements `TransactionManager`, so transactions can continue to be conveniently managed inside the controller package: ``` err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error { // transactional code } ``` `TransactionalResources` implements the `Repositories` interface, providing convenient access to repository types: ``` err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error { tr.ResourceRepository().Delete(ctx, ctx.ResourceID) } ``` The scope of `TransactionalResources` may be easily extended in the future to include other transactional resources, not just repositories. # Introduction of service layer - Transaction control moved to service layer Since the service layer is responsible for the atomic integrity of the operation, transaction control was moved to the service layer where required. - Extracted db-specific code from service layer to repository layer This leaves the service layer as a purely business logic layer. In many cases, this has left the service layer as a thin facade over the repository layer, which is exactly what the Service Layer design pattern recommends. For example, `RoleManagementService` which was previously over 300 lines of code is now only about 40 lines. - Fixed Preload issues Many hours was spent deep inside the Gorm source code to determine why `Preload()` was failing, and I'm pleased to report that I was able to identify the issue and rectify it in our code. As a result, I was able to do some extensive code refactoring to significantly reduce the number of lines of code required to execute some queries and get the results we required. For example, I was able to reduce the methods in `RoleManagementService` (some of them around 70 lines of code) significantly (in some cases just over 10 lines of code) in the `IdentityRole` repository. # Adds `IdentityAssociation` struct This type is a general purpose DTO for transferring membership and role assignment state from the repository/service layer to the controller layer. It is designed to replace multiple other DTO types (such as the [`IdentityOrganization`](https://github.com/fabric8-services/fabric8-auth/blob/master/authorization/organization/organization.go) type) with a single reusable type. Two convenience methods have been added to the `authorization` package to support this struct: ``` func AppendAssociation(associations []IdentityAssociation, resourceID string, resourceName *string, identityID *uuid.UUID, member bool, role *string) func MergeAssociations(associations []IdentityAssociation, merge []IdentityAssociation) []IdentityAssociation ``` The `AppendAssociation` function can be used to add new state to an `IdentityAssociation` array. It either merges the state into an existing element (if there is a match) or creates a new element if necessary. The `MergeAssociations` function is used to correctly merge the state of two separate `IdentityAssociation` arrays into one. Fixes #446 Signed-off-by: Shane Bryzak <sbryzak@redhat.com>
- Loading branch information
Showing
77 changed files
with
1,630 additions
and
1,473 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.