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.project.service.ProjectRulesService; import ru.ulstu.fc.rule.model.FuzzyRule; import ru.ulstu.fc.rule.model.dto.FuzzyRuleDataDto; import ru.ulstu.fc.rule.model.dto.FuzzyRuleDto; import ru.ulstu.fc.rule.service.FuzzyRuleParseService; import ru.ulstu.fc.rule.service.FuzzyRuleService; import java.util.List; @RestController @RequestMapping("fuzzyRuleRest") public class FuzzyRuleRestController { private final FuzzyRuleService ruleService; private final ProjectRulesService projectRulesService; private final FuzzyRuleParseService fuzzyRuleParseService; public FuzzyRuleRestController(FuzzyRuleService ruleService, ProjectRulesService projectRulesService, FuzzyRuleParseService fuzzyRuleParseService) { this.ruleService = ruleService; this.projectRulesService = projectRulesService; this.fuzzyRuleParseService = fuzzyRuleParseService; } @GetMapping("/getAll/{projectId}") public List getAll(@PathVariable(value = "projectId") Integer projectId) { return projectRulesService.getDtoByProjectId(projectId); } @GetMapping("/get/{ruleId}") public FuzzyRuleDto get(@PathVariable(value = "ruleId") Integer id) { return ruleService.getByIdDto(id); } @PostMapping public FuzzyRule save(@Valid FuzzyRuleDto fuzzyRuleDto) { return ruleService.save(fuzzyRuleDto); } @DeleteMapping public void delete(@Valid FuzzyRuleDto fuzzyRuleDto) { if (fuzzyRuleDto != null && fuzzyRuleDto.getId() != null) { ruleService.delete(fuzzyRuleDto); } } @PostMapping("parse/{projectId}") public List parseRule(@PathVariable("projectId") Integer projectId, String data) { return fuzzyRuleParseService.parseFuzzyRules(data, projectId); } @PostMapping("generate-rules/{projectId}") public void generateRules(@PathVariable("projectId") Integer projectId, FuzzyRuleDataDto fuzzyRuleDataDto) { fuzzyRuleParseService.generateRules(projectId, fuzzyRuleDataDto); } }