From 3359db7b978b7450f51184dfd2227a6df2027eab Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 27 Feb 2025 11:39:07 +0400 Subject: [PATCH] #4 -- Add ajax methods for variables and terms --- .../rule/controller/FuzzyRuleController.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java index 7febe09..5ab299e 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java @@ -8,16 +8,29 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import ru.ulstu.fc.rule.model.FuzzyRuleForm; +import ru.ulstu.fc.rule.model.FuzzyTerm; +import ru.ulstu.fc.rule.model.Variable; import ru.ulstu.fc.rule.service.FuzzyRuleService; +import ru.ulstu.fc.rule.service.FuzzyTermService; +import ru.ulstu.fc.rule.service.VariableService; + +import java.util.List; @Controller @RequestMapping("rule") public class FuzzyRuleController { - private final FuzzyRuleService ruleService; + private final FuzzyRuleService fuzzyRuleService; + private final VariableService variableService; + private final FuzzyTermService fuzzyTermService; - public FuzzyRuleController(FuzzyRuleService ruleService) { - this.ruleService = ruleService; + public FuzzyRuleController(FuzzyRuleService fuzzyRuleService, + VariableService variableService, + FuzzyTermService fuzzyTermService) { + this.fuzzyRuleService = fuzzyRuleService; + this.variableService = variableService; + this.fuzzyTermService = fuzzyTermService; } @GetMapping("/edit/{projectId}/{ruleId}") @@ -26,7 +39,7 @@ public class FuzzyRuleController { model.addAttribute("projectId", projectId); model.addAttribute("fuzzyRuleForm", (id != null && id != 0) - ? new FuzzyRuleForm(id, ruleService.getById(id)) + ? new FuzzyRuleForm(id, fuzzyRuleService.getById(id)) : new FuzzyRuleForm(id, projectId)); return "rule/edit"; } @@ -37,15 +50,27 @@ public class FuzzyRuleController { model.addAttribute("projectId", fuzzyRuleForm.getProjectId()); return "rule/edit"; } - ruleService.save(fuzzyRuleForm); + fuzzyRuleService.save(fuzzyRuleForm); return "redirect:/project/edit/" + fuzzyRuleForm.getProjectId(); } @PostMapping(value = "save", params = "delete") public String delete(FuzzyRuleForm fuzzyRuleForm) { if (fuzzyRuleForm != null && fuzzyRuleForm.getId() != null) { - ruleService.delete(fuzzyRuleForm); + fuzzyRuleService.delete(fuzzyRuleForm); } return "redirect:/project/edit/" + fuzzyRuleForm.getProjectId(); } + + @ResponseBody + @GetMapping("/getVariables/{projectId}") + public List getVariables(@PathVariable("projectId") Integer projectId) { + return variableService.getAllByProject(projectId); + } + + @ResponseBody + @GetMapping("/getFuzzyTerms/{variableId}") + public List getTerms(@PathVariable("variableId") Integer variableId) { + return fuzzyTermService.getByVariableId(variableId); + } }