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

service: add CRUD actions for CheckConfigService #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

carlinmack
Copy link
Contributor

❤️ Thank you for your contribution!

close #10

Description

Please describe briefly your pull request.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

Sorry, something went wrong.

Copy link
Member

@slint slint left a comment

Choose a reason for hiding this comment

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

Nits and minor things (just had some spare time and quickly went through 😅)

Copy link

@ntarocco ntarocco left a comment

Choose a reason for hiding this comment

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

Nice work! I have added a few comments. However, it might be that you were already planning to implement some of my suggestions in subsequent PRs.

def validate_community_id(self, value):
"""Validate that the community_id is a valid UUID."""
try:
UUID(value)
Copy link

@ntarocco ntarocco Mar 14, 2025

Choose a reason for hiding this comment

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

minor: it might be nice to check if the community exist. It could also be that it is the caller checking that.
CommunityMetadata.query(CommunityMetadata.id == value).exists()

Just noticed that there is a foreign key.

try:
validated_data = schema.load(data)
except ValidationError as e:
raise ValueError(f"Validation error: {e.messages}")

Choose a reason for hiding this comment

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

If there will be a form to create this, we will need to return a more structured error message, so that the UI can parse the response.

enabled=validated_data.get("enabled", True),
)
uow.register(ModelCommitOp(check_config))
return check_config

Choose a reason for hiding this comment

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

We normally return a ResultItem, see for example here

)
uow.register(ModelCommitOp(check_config))
return check_config
except Exception as e:

Choose a reason for hiding this comment

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

I would avoid, whenever possible, have a catch-all Exception, which can hide inner issues and makes it difficult for the caller to handle a specific exception. Is it needed?

raise NotImplementedError()
self.require_permission(identity, "read")
check_config = get_check_config(id_)
return check_config

Choose a reason for hiding this comment

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

same here for the ResultItem obj

if "enabled" in params:
query = query.filter_by(enabled=params["enabled"])

return query.all()

Choose a reason for hiding this comment

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

See ResultsList here. query.all() might be very inefficient without a limit or pagination, in case of a large number of results.

Comment on lines +118 to +122
return check_config
except NoResultFound:
raise ValueError(f"Check configuration with id '{id_}' not found")
except Exception as e:
raise ValueError(f"Failed to update check configuration: {str(e)}")

Choose a reason for hiding this comment

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

see comments above ☺️

Comment on lines +132 to +137

return True
except NoResultFound:
raise ValueError(f"Check configuration with id '{id_}' not found")
except Exception as e:
raise ValueError(f"Failed to delete check configuration: {str(e)}")

Choose a reason for hiding this comment

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

same here

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.

Service CRUD for CheckConfig
3 participants