#13 -- Add rule crud
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 2m1s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 2m1s
This commit is contained in:
parent
be3f70f14c
commit
495b04e51d
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "interactive"
|
||||
}
|
@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import ru.ulstu.fc.project.model.Project;
|
||||
import ru.ulstu.fc.project.model.ProjectForm;
|
||||
import ru.ulstu.fc.project.service.ProjectService;
|
||||
import ru.ulstu.fc.rule.model.Rule;
|
||||
import ru.ulstu.fc.rule.model.RuleForm;
|
||||
|
||||
|
@ -1,5 +1,43 @@
|
||||
package ru.ulstu.fc.rule.controller;
|
||||
|
||||
public class RuleService {
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import ru.ulstu.fc.project.repository.RuleRepository;
|
||||
import ru.ulstu.fc.project.service.ProjectService;
|
||||
import ru.ulstu.fc.rule.model.Rule;
|
||||
import ru.ulstu.fc.rule.model.RuleForm;
|
||||
|
||||
@Service
|
||||
public class RuleService {
|
||||
private final RuleRepository ruleRepository;
|
||||
private final ProjectService projectService;
|
||||
|
||||
public RuleService(RuleRepository ruleRepository, ProjectService projectService) {
|
||||
this.ruleRepository = ruleRepository;
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
public Rule getById(Integer id) {
|
||||
return ruleRepository
|
||||
.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Rule not found by id"));
|
||||
}
|
||||
|
||||
public Object save(RuleForm ruleForm) {
|
||||
if (ruleForm.getId() == null) {
|
||||
Rule rule = new Rule();
|
||||
rule.setProject(projectService.getById(ruleForm.getProjectId()));
|
||||
// rule.set...
|
||||
return ruleRepository.save(rule);
|
||||
}
|
||||
Rule dbRule = getById(ruleForm.getId());
|
||||
dbRule.setProject(projectService.getById(ruleForm.getProjectId()));
|
||||
// dbRule.set ...
|
||||
return ruleRepository.save(dbRule);
|
||||
}
|
||||
|
||||
public void delete(RuleForm ruleForm) {
|
||||
getById(ruleForm.getId());
|
||||
ruleRepository.deleteById(ruleForm.getId());
|
||||
}
|
||||
}
|
||||
|
@ -13,17 +13,13 @@ public class Antecedent extends BaseEntity {
|
||||
public Variable getVariable() {
|
||||
return variable;
|
||||
}
|
||||
|
||||
public void setVariable(Variable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ public class Rule extends BaseEntity {
|
||||
@ManyToOne
|
||||
private Consequent consequent;
|
||||
|
||||
public Rule() {
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
@ -1,10 +1,32 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
public class RuleForm {
|
||||
private final Integer projectId;
|
||||
private Integer id;
|
||||
private Integer projectId;
|
||||
|
||||
public RuleForm() {
|
||||
}
|
||||
|
||||
public RuleForm(Rule rule) {
|
||||
this.projectId = (rule == null || rule.getProject() == null)
|
||||
? null
|
||||
: rule.getProject().getId();
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user