-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 😅)
There was a problem hiding this 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) |
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
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)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments above
|
||
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)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
❤️ Thank you for your contribution!
close #10
Description
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: