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

Pass district id as parameter for update and trigger #667

Merged
merged 9 commits into from
Apr 27, 2021

Conversation

Yuuki77
Copy link
Contributor

@Yuuki77 Yuuki77 commented Apr 2, 2021

Part of #617

pass district id as parameter for update and trigger endpoints.
in following pr, I will add the logic to create heritage with district name.
By adding this endpoint, we can make the heritage unique for each district in the future.

@Yuuki77 Yuuki77 force-pushed the update-heritage-with-district branch from d70e332 to bc5f8fe Compare April 2, 2021 03:27
@degicat
Copy link

degicat commented Apr 2, 2021

@davidsiaw please review this

@degicat degicat requested a review from davidsiaw April 2, 2021 03:46
Copy link
Contributor

@davidsiaw davidsiaw left a comment

Choose a reason for hiding this comment

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

Can we use the same update method and just use district if its provided for now?

Comment on lines 31 to 29
def update_with_district
@heritage = BuildHeritage.new(permitted_params, district: @district).execute
@heritage.save_and_deploy!(without_before_deploy: false,
description: "Update to #{@heritage.image_path}")
render json: @heritage
Copy link
Contributor

Choose a reason for hiding this comment

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

can't this just be in update but with district as an optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidsiaw ok I updated the logic to pass the value in body as optional.
Let me know what you think 🙏

@Yuuki77 Yuuki77 force-pushed the update-heritage-with-district branch 2 times, most recently from 73a4865 to bcba35c Compare April 5, 2021 05:12
@Yuuki77 Yuuki77 changed the title Add update_with_district endpoint Pass district id as parameter for update and trigger Apr 5, 2021
@Yuuki77 Yuuki77 requested a review from davidsiaw April 5, 2021 05:16
Copy link
Contributor

@davidsiaw davidsiaw left a comment

Choose a reason for hiding this comment

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

Looks great! We just need more testing to cover some cases

@@ -22,7 +23,7 @@ def create
end

def update
@heritage = BuildHeritage.new(permitted_params).execute
@heritage = BuildHeritage.new(permitted_params, district: @district).execute
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks this looks like a very clean way to handle it. Its also a very implicit if statement, so I think we should have a test to get the heritage for the following cases:

  1. endpoint has no district, name passed in
  2. endpoint has no district, name and district passed in
  3. endpoint has district, name passed in
  4. endpoint has district, name and district passed in
  5. endpoint has district, with another endpoint in different district with the same name, name passed in
  6. endpoint has district, with another endpoint in different district with the same name, name and district passed in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidsiaw just to confirm, what do you mean by endpointhere?
like endpoint has no district, name passed in
this is the case when pass heritage name but there is no district?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not pass, but the database has an endpoint but district is set to nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

district has endpionts right?

has_many :endpoints, inverse_of: :district, dependent: :destroy

Copy link
Contributor Author

@Yuuki77 Yuuki77 Apr 5, 2021

Choose a reason for hiding this comment

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

also district name should be unique
also I could not understand what you mean by 🙏

endpoint has district, with another endpoint in different district with the same name, name passed in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidsiaw updated the logic
05f4bae
also existing tests cover for when no district name is given

Copy link
Contributor

Choose a reason for hiding this comment

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

@Yuuki77 I think it is hard to write this test from what I see, because you are testing the API. You should test BuildHeritage instead, and it will be clearer. What we need to test essentially is all the permutations of

  1. The various states of the database
  2. The inputs passed to update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidsiaw added the test.
I think the other scenario is that the wrong district is passed (which has always been possible).
So I added the checks.
other that existing tests should cover.
The change I made here was to pass district in update, which was nil.
dd9fef7

@Yuuki77 Yuuki77 requested a review from davidsiaw April 5, 2021 06:55
@@ -22,7 +23,7 @@ def create
end

def update
@heritage = BuildHeritage.new(permitted_params).execute
@heritage = BuildHeritage.new(permitted_params, district: @district).execute
Copy link
Contributor

Choose a reason for hiding this comment

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

@Yuuki77 I think it is hard to write this test from what I see, because you are testing the API. You should test BuildHeritage instead, and it will be clearer. What we need to test essentially is all the permutations of

  1. The various states of the database
  2. The inputs passed to update

@Yuuki77 Yuuki77 force-pushed the update-heritage-with-district branch from 5c38f2f to 42a9a9e Compare April 14, 2021 02:09
@Yuuki77 Yuuki77 force-pushed the update-heritage-with-district branch from e12dc5e to dd9fef7 Compare April 14, 2021 02:11
@Yuuki77 Yuuki77 requested a review from davidsiaw April 14, 2021 02:22
Copy link
Contributor

@davidsiaw davidsiaw left a comment

Choose a reason for hiding this comment

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

Just a few more things

app/controllers/heritages_controller.rb Outdated Show resolved Hide resolved
app/services/build_heritage.rb Outdated Show resolved Hide resolved
spec/requests/update_heritage_spec.rb Outdated Show resolved Hide resolved
@Yuuki77 Yuuki77 force-pushed the update-heritage-with-district branch from 3cac758 to 506cbc5 Compare April 21, 2021 07:44
@Yuuki77 Yuuki77 requested a review from davidsiaw April 21, 2021 08:42
@Yuuki77
Copy link
Contributor Author

Yuuki77 commented Apr 21, 2021

Thank you for the reviews 🙇
I have updated it

Copy link
Contributor

@davidsiaw davidsiaw left a comment

Choose a reason for hiding this comment

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

LGTM

@davidsiaw davidsiaw merged commit 3df6846 into master Apr 27, 2021
@davidsiaw davidsiaw deleted the update-heritage-with-district branch April 27, 2021 07:50
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