Skip to content

Conversation

@julienbourdeau
Copy link
Contributor

I was looking at the pagination and realize that 2 Query object (only 2 out of ~30) have an override of the constructor.

I think it's better to rely on filters of this and let Dry::Validation gem handle the required/optional filters.

The main benefits are:

  • remove duplications of the the defaults value in optional arguments (fitler, search_terms...)
  • better validation
  • more consistency

@julienbourdeau julienbourdeau self-assigned this Nov 5, 2025
Comment on lines +30 to +32
def wallet
@wallet ||= organization.wallets.find_by(id: filters.wallet_id)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should remove this.
then, use organization.where(id: ...).exists?to return not_found_failure and add.where(wallet_id: ...)` to the base scope 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is clear as it is.

however if we can drop the not_found_failure on wallet and use a base scope like we do for the webhooks query is also good. All in all the wallet is a filter, if wallet is not found no wallet transaction would be returned. However this could be a breaking change on public APIs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd prefer to do it this way but I definitely don't want to introduce a breaking change

Copy link
Contributor

@ancorcruz ancorcruz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice refactor. looks good to me.

Comment on lines +20 to +21
rescue BaseService::FailedResult
result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is being rescued here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because the validate_filters raise a validation failure. So we could argue the return result unless validate.success? is the "useless" part but it's done this way in other query objects so I want to follow the pattern for now.

I think we should definitely improve the validation part. Like make the BaseQuery ensure it has validation. We'll see

Comment on lines +30 to +32
def wallet
@wallet ||= organization.wallets.find_by(id: filters.wallet_id)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is clear as it is.

however if we can drop the not_found_failure on wallet and use a base scope like we do for the webhooks query is also good. All in all the wallet is a filter, if wallet is not found no wallet transaction would be returned. However this could be a breaking change on public APIs

Comment on lines +21 to +22
rescue BaseService::FailedResult
result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question, what is being rescued here... I haven't seen this rescue in other query objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the majority of objects don't have contracts validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants