#17 -- REST CRUD for rules
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 59s

This commit is contained in:
Anton Romanov 2025-02-25 18:23:17 +04:00
parent d10db93950
commit 92be5c9ac6
2 changed files with 41 additions and 1 deletions

View File

@ -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);
}
}
}

View File

@ -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();