diff --git a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleRestController.java b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleRestController.java new file mode 100644 index 0000000..03469d9 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleRestController.java @@ -0,0 +1,40 @@ +package ru.ulstu.fc.rule.controller; + +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.DeleteMapping; +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.RestController; +import ru.ulstu.fc.rule.model.FuzzyRule; +import ru.ulstu.fc.rule.model.FuzzyRuleForm; +import ru.ulstu.fc.rule.service.FuzzyRuleService; + +@RestController +@RequestMapping("fuzzyRuleRest") +public class FuzzyRuleRestController { + private final FuzzyRuleService ruleService; + + public FuzzyRuleRestController(FuzzyRuleService ruleService) { + this.ruleService = ruleService; + } + + @GetMapping("/get/{projectId}/{ruleId}") + public FuzzyRule get(@PathVariable(value = "projectId") Integer projectId, + @PathVariable(value = "ruleId") Integer id) { + return ruleService.getById(id); + } + + @PostMapping + public FuzzyRule save(@Valid FuzzyRuleForm fuzzyRuleForm) { + return ruleService.save(fuzzyRuleForm); + } + + @DeleteMapping + public void delete(@Valid FuzzyRuleForm fuzzyRuleForm) { + if (fuzzyRuleForm != null && fuzzyRuleForm.getId() != null) { + ruleService.delete(fuzzyRuleForm); + } + } +} 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 e4df2b7..8093133 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java @@ -22,7 +22,7 @@ public class FuzzyRuleService { .orElseThrow(() -> new RuntimeException("Rule not found by id")); } - public Object save(FuzzyRuleForm ruleForm) { + public FuzzyRule save(FuzzyRuleForm ruleForm) { FuzzyRule rule; if (ruleForm.getId() == null || ruleForm.getId() == 0) { rule = new FuzzyRule();