-
-
Notifications
You must be signed in to change notification settings - Fork 573
Refactor Requests controller #5563
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
Open
stefannibrasil
wants to merge
7
commits into
rubyforgood:main
Choose a base branch
from
hexdevs:refactor-requests-controller-5557
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+299
−65
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
85da11f
Refactor requests controller
stefannibrasil 8089be6
Remove unnecessary donations eager loading product_drive_participant
stefannibrasil b690801
Refactor show action
stefannibrasil 72f9a3e
rename requests_info to avoid clashing with show request_info
stefannibrasil 9a694c4
Create factories only when necessary
stefannibrasil 1f08698
Rename filter variables with the view object instance from the contro…
stefannibrasil 7664d93
linter
stefannibrasil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,33 @@ | ||
| module View | ||
| RequestInfo = Data.define( | ||
| :request | ||
| ) do | ||
| class << self | ||
| def from_params(params:, organization:) | ||
| request = organization.requests.find(params[:id]) | ||
|
|
||
| new(request:) | ||
| end | ||
| end | ||
|
|
||
| def item_requests | ||
| request.item_requests.includes(:item) | ||
| end | ||
|
|
||
| def inventory | ||
| View::Inventory.new(request.organization_id) | ||
| end | ||
|
|
||
| def default_storage_location | ||
| request.partner.default_storage_location_id || request.organization.default_storage_location | ||
| end | ||
|
|
||
| def location | ||
| StorageLocation.find_by(id: default_storage_location) | ||
| end | ||
|
|
||
| def custom_units | ||
| Flipper.enabled?(:enable_packs) && request.item_requests.any? { |item| item.request_unit } | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,84 @@ | ||
| module View | ||
| Requests = Data.define( | ||
| :requests, | ||
| :filters, | ||
| :paginated_requests, | ||
| :organization, | ||
| :helpers | ||
| ) do | ||
| include DateRangeHelper | ||
|
|
||
| class << self | ||
| def filter_params(params = {}) | ||
| if params.key?(:filters) | ||
| params.require(:filters).permit(:by_request_item_id, :by_partner, :by_status, :by_request_type) | ||
| else | ||
| {} | ||
| end | ||
| end | ||
|
|
||
| def from_params(params:, organization:, helpers:) | ||
| filters = filter_params(params) | ||
|
|
||
| requests = organization | ||
| .ordered_requests | ||
| .undiscarded | ||
| .during(helpers.selected_range) | ||
| .class_filter(filters) | ||
|
|
||
| paginated_requests = requests.includes(:partner).page(params[:page]) | ||
|
|
||
| new(requests:, filters:, paginated_requests:, organization:, helpers:) | ||
| end | ||
| end | ||
|
|
||
| def unfulfilled_requests_count | ||
| organization | ||
| .requests | ||
| .where(status: [:pending, :started]) | ||
| .during(helpers.selected_range) | ||
| .class_filter(filters) | ||
| .count | ||
| end | ||
|
|
||
| def calculate_product_totals | ||
| RequestsTotalItemsService.new(requests: requests).calculate | ||
| end | ||
|
|
||
| def items | ||
| organization.items.alphabetized.select(:id, :name) | ||
| end | ||
|
|
||
| def partners | ||
| organization.partners.alphabetized.select(:id, :name, :status) | ||
| end | ||
|
|
||
| def statuses | ||
| Request.statuses.transform_keys(&:humanize) | ||
| end | ||
|
|
||
| def partner_users | ||
| User.where(id: paginated_requests.map(&:partner_user_id)).select(:id, :name, :email) | ||
| end | ||
|
|
||
| def request_types | ||
| Request.request_types.transform_keys(&:humanize) | ||
| end | ||
|
|
||
| def selected_request_type | ||
| filters[:by_request_type] | ||
| end | ||
|
|
||
| def selected_request_item | ||
| filters[:by_request_item_id] | ||
| end | ||
|
|
||
| def selected_partner | ||
| filters[:by_partner] | ||
| end | ||
|
|
||
| def selected_status | ||
| filters[:by_status] | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to remove this change from this PR. I got here by looking at other view objects and saw the bullet's warning: 8089be6cb25bfff90506e634fc486dbaf6454e9b