diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java index 8093133..bde8fb2 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java @@ -11,15 +11,18 @@ public class FuzzyRuleService { private final FuzzyRuleRepository ruleRepository; private final ProjectService projectService; - public FuzzyRuleService(FuzzyRuleRepository ruleRepository, ProjectService projectService) { + public FuzzyRuleService(FuzzyRuleRepository ruleRepository, + ProjectService projectService) { this.ruleRepository = ruleRepository; this.projectService = projectService; } public FuzzyRule getById(Integer id) { - return ruleRepository + FuzzyRule fuzzyRule = ruleRepository .findById(id) .orElseThrow(() -> new RuntimeException("Rule not found by id")); + checkIsCurrentUserFuzzyRuleWithThrow(fuzzyRule); + return fuzzyRule; } public FuzzyRule save(FuzzyRuleForm ruleForm) { @@ -35,7 +38,10 @@ public class FuzzyRuleService { } public void delete(FuzzyRuleForm ruleForm) { - getById(ruleForm.getId()); - ruleRepository.deleteById(ruleForm.getId()); + ruleRepository.delete(getById(ruleForm.getId())); + } + + public void checkIsCurrentUserFuzzyRuleWithThrow(FuzzyRule fuzzyRule) { + projectService.checkIsCurrentUserProjectWithThrow(fuzzyRule.getProject()); } }