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

Remove code from Spree::Api::PromotionsController #3529

Merged

Conversation

SamuelMartini
Copy link
Contributor

@SamuelMartini SamuelMartini commented Feb 28, 2020

Description
Little change to make Spree::Api::PromotionsController leaner and also consistent with how solidus api deals with ActiveRecord::RecordNotFound and authorization.

Checklist:

@kennyadsl kennyadsl added the changelog:solidus_api Changes to the solidus_api gem label Mar 3, 2020
@SamuelMartini SamuelMartini force-pushed the SamuelMartini/lean_promotions_controller branch from 8b14eb5 to c5551e2 Compare March 4, 2020 14:48
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@SamuelMartini thank you for this PR, looks good to me, I left just a small style note, let me know what you think.

def load_promotion
@promotion = Spree::Promotion.find_by(id: params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
@promotion = Spree::Promotion.with_coupon_code(params[:id])
@promotion ||= Spree::Promotion.find(params[:id])
Copy link
Member

Choose a reason for hiding this comment

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

@SamuelMartini for consistency with what was done after this I would consider using the || here as well, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SamuelMartini SamuelMartini force-pushed the SamuelMartini/lean_promotions_controller branch from c5551e2 to eb481bd Compare March 12, 2020 16:33
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@SamuelMartini thank you 👍

Make it leaner by using the way solidus api has to deal with ActiveRecord::RecordNotFound
and authorization.

In `load_promotion`, `find_by` is replaced with `find` and the order of
the finders is inverted to have the exception as last operator: if a
promotion can't be found, raise an exception.
@SamuelMartini SamuelMartini force-pushed the SamuelMartini/lean_promotions_controller branch from eb481bd to 996a15a Compare March 13, 2020 10:03
@aldesantis
Copy link
Member

Thanks @SamuelMartini!

@aldesantis aldesantis merged commit c55539b into solidusio:master Mar 26, 2020
@aldesantis aldesantis deleted the SamuelMartini/lean_promotions_controller branch March 26, 2020 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants