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

Deployments context specs (and some improvements) #1733

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

joshk
Copy link
Collaborator

@joshk joshk commented Jan 7, 2025

  • Add specs to all functions
  • Fix a function return
  • Simplify some function arguments

joshk added 2 commits January 7, 2025 22:47
And some improvements and fixes seen while adding specs, like incorrect function returns, and simplifying some of the function arguments.
the firmware association is already preloaded
@joshk joshk force-pushed the deployments-context-specs branch from 89fdfa2 to 6152d2d Compare January 7, 2025 09:47
@joshk joshk requested review from nshoes and lawik January 7, 2025 10:50
Copy link
Contributor

@nshoes nshoes left a comment

Choose a reason for hiding this comment

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

Thank you for this!


@spec get_deployment_device_count(integer()) :: term() | nil
def get_deployment_device_count(deployment_id) do
@spec get_device_count(Deployment.t()) :: term() | nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I hate this return type but that's how Repo.aggregate/3 is typed? 😕 I would have assumed it would be :: non_neg_integer() | nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I totally agree with you, and sadly thats how it is typed. I could change it to non_neg_integer but I don't know if there is another possible term() that might be returned.

@@ -14,7 +14,7 @@ defmodule NervesHubWeb.API.DeploymentController do
@whitelist_fields [:name, :org_id, :firmware_id, :conditions, :is_active]

def index(%{assigns: %{product: product}} = conn, _params) do
deployments = Deployments.get_deployments_by_product(product.id)
deployments = Deployments.get_deployments_by_product(product)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we had the choice, would we generally lean towards passing structs around or only the required bits?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, gooooood question. I mostly changed this because the only use of this function was when we had the Product and I preferred the aesthetics of this more. I did initially create a version where the product or product id could be passed through, but since its only used in two liveviews, I removed the product id version.

@joshk joshk merged commit 3a2c572 into main Jan 7, 2025
2 checks passed
@joshk joshk deleted the deployments-context-specs branch January 7, 2025 20:49
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