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

done #308

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

done #308

wants to merge 3 commits into from

Conversation

aTiukhtii
Copy link

No description provided.

Comment on lines 29 to 33
if (categoryRepository.existsById(id)) {
categoryRepository.deleteById(id);
} else {
throw new NoSuchElementException("couldn't delete category by id: " + id);
}
Copy link

Choose a reason for hiding this comment

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

This approach "fails fast" by handling the exception first, reducing the need for nested code. Since an exception ends the method, there's no need for an else clause, making the code cleaner. Let's do it this way everywhere

Suggested change
if (categoryRepository.existsById(id)) {
categoryRepository.deleteById(id);
} else {
throw new NoSuchElementException("couldn't delete category by id: " + id);
}
if (!categoryRepository.existsById(id)) {
categoryRepository.deleteById(id);
}
throw new NoSuchElementException("Couldn't delete category by id: " + id);

@aTiukhtii aTiukhtii requested a review from okuzan July 19, 2023 10:57
Copy link

@okuzan okuzan left a comment

Choose a reason for hiding this comment

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

Well done! 🚀

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.

2 participants