#17 -- REST CRUD for variables
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m4s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m4s
This commit is contained in:
parent
9ad33c4e79
commit
d10db93950
@ -5,6 +5,7 @@ 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.FuzzyTerm;
|
||||
import ru.ulstu.fc.rule.model.FuzzyTermForm;
|
||||
@ -12,7 +13,8 @@ import ru.ulstu.fc.rule.service.FuzzyTermService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController("fuzzyTermRest")
|
||||
@RestController
|
||||
@RequestMapping("fuzzyTermRest")
|
||||
public class FuzzyTermRestController {
|
||||
private final FuzzyTermService fuzzyTermService;
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
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.Variable;
|
||||
import ru.ulstu.fc.rule.model.VariableForm;
|
||||
import ru.ulstu.fc.rule.service.VariableService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("variableRest")
|
||||
public class VariableRestController {
|
||||
private final VariableService variableService;
|
||||
|
||||
public VariableRestController(VariableService variableService) {
|
||||
this.variableService = variableService;
|
||||
}
|
||||
|
||||
@GetMapping("/list/{projectId}")
|
||||
public List<Variable> getList(@PathVariable(value = "projectId") Integer projectId) {
|
||||
return variableService.getAllByProject(projectId);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{projectId}/{variableId}")
|
||||
public Variable getById(@PathVariable(value = "projectId") Integer projectId,
|
||||
@PathVariable(value = "variableId") Integer variableId) {
|
||||
return variableService.getById(variableId);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Variable save(@Valid VariableForm variableForm) {
|
||||
return variableService.save(variableForm);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public void delete(@Valid VariableForm variableForm) {
|
||||
if (variableForm != null && variableForm.getId() != null) {
|
||||
variableService.delete(variableForm);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,4 +9,6 @@ import java.util.List;
|
||||
public interface VariableRepository extends JpaRepository<Variable, Integer> {
|
||||
|
||||
List<Variable> findByProject(Project project);
|
||||
|
||||
List<Variable> getByProject(Project project);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import ru.ulstu.fc.rule.model.Variable;
|
||||
import ru.ulstu.fc.rule.model.VariableForm;
|
||||
import ru.ulstu.fc.rule.repository.VariableRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class VariableService {
|
||||
private final VariableRepository variableRepository;
|
||||
@ -59,4 +61,8 @@ public class VariableService {
|
||||
var.getFuzzyTerms().add(ft);
|
||||
variableRepository.save(var);
|
||||
}
|
||||
|
||||
public List<Variable> getAllByProject(Integer projectId) {
|
||||
return variableRepository.getByProject(projectService.getById(projectId));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user