#76-fix removing rule

pull/77/head
BarminaA 2 years ago
parent bf87d34f20
commit f7338f34c9

@ -2,16 +2,21 @@ package ru.ulstu.extractor.rule.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import ru.ulstu.extractor.rule.model.AddRuleForm; import ru.ulstu.extractor.rule.model.AddRuleForm;
import ru.ulstu.extractor.rule.repository.RuleRepository;
import ru.ulstu.extractor.rule.service.AntecedentValueService; import ru.ulstu.extractor.rule.service.AntecedentValueService;
import ru.ulstu.extractor.rule.service.RuleService; import ru.ulstu.extractor.rule.service.RuleService;
import ru.ulstu.extractor.ts.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import static ru.ulstu.extractor.core.Route.*; import static ru.ulstu.extractor.core.Route.ADD_RULE;
import static ru.ulstu.extractor.core.Route.DELETE_RULE;
import static ru.ulstu.extractor.core.Route.LIST_RULE;
@Controller @Controller
@ApiIgnore @ApiIgnore
@ -19,15 +24,13 @@ public class RuleController {
private final RuleService ruleService; private final RuleService ruleService;
private final AntecedentValueService antecedentValueService; private final AntecedentValueService antecedentValueService;
private final TimeSeriesService timeSeriesService; private final TimeSeriesService timeSeriesService;
private final RuleRepository ruleRepository;
public RuleController(RuleService ruleService, public RuleController(RuleService ruleService,
AntecedentValueService antecedentValueService, AntecedentValueService antecedentValueService,
TimeSeriesService timeSeriesService, RuleRepository ruleRepository) { TimeSeriesService timeSeriesService) {
this.ruleService = ruleService; this.ruleService = ruleService;
this.antecedentValueService = antecedentValueService; this.antecedentValueService = antecedentValueService;
this.timeSeriesService = timeSeriesService; this.timeSeriesService = timeSeriesService;
this.ruleRepository = ruleRepository;
} }
@GetMapping(LIST_RULE) @GetMapping(LIST_RULE)
@ -52,8 +55,7 @@ public class RuleController {
@GetMapping(DELETE_RULE) @GetMapping(DELETE_RULE)
public String deleteRule(Model model, @RequestParam Integer id) { public String deleteRule(Model model, @RequestParam Integer id) {
ruleRepository.deleteById(id); ruleService.deleteById(id);
model.addAttribute("rule", ruleRepository.findAll());
return "redirect:/" + LIST_RULE; return "redirect:/" + LIST_RULE;
} }
} }

@ -56,4 +56,8 @@ public class RuleService {
.orElseThrow(() -> new RuntimeException("Правило не найдено"))) .orElseThrow(() -> new RuntimeException("Правило не найдено")))
: new AddRuleForm(); : new AddRuleForm();
} }
public void deleteById(Integer id) {
ruleRepository.deleteById(id);
}
} }

Loading…
Cancel
Save