фильтр не робит
This commit is contained in:
parent
58f188941b
commit
61bc65a4ea
@ -33,7 +33,7 @@ export default {
|
|||||||
if (urlParams != "") {
|
if (urlParams != "") {
|
||||||
urlParams += "&";
|
urlParams += "&";
|
||||||
}
|
}
|
||||||
urlParams += "componentAmount=" + this.serialNumber;
|
urlParams += "amount=" + this.serialNumber;
|
||||||
}
|
}
|
||||||
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Component(data))
|
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Component(data))
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
@ -23,8 +23,8 @@ public class ComponentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public ComponentDTO updateComponent(@PathVariable Long id,@RequestParam("name") String name, @RequestParam("amount") Integer amount) {
|
public ComponentDTO updateComponent(@PathVariable Long id,@RequestBody @Valid ComponentDTO componentDTO) {
|
||||||
return new ComponentDTO(componentService.updateComponent(id,name, amount));
|
return new ComponentDTO(componentService.updateComponent(id,componentDTO.getComponentName(), componentDTO.getAmount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@ -48,4 +48,13 @@ public class ComponentController {
|
|||||||
.map(ComponentDTO::new)
|
.map(ComponentDTO::new)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/filter")
|
||||||
|
public List<ComponentDTO> getFilteredComponents(@RequestParam(value = "id", required = false) Long id,
|
||||||
|
@RequestParam(value = "componentName", required = false) String modelName,
|
||||||
|
@RequestParam(value = "amount", required = false) int amount ) {
|
||||||
|
return componentService.findFilteredComponents(id, modelName, amount).stream()
|
||||||
|
.map(ComponentDTO::new)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ComponentDTO {
|
public class ComponentDTO {
|
||||||
private long id;
|
private long id;
|
||||||
private String ComponentName;
|
private String componentName;
|
||||||
private Integer Amount;
|
private Integer amount;
|
||||||
private List<FavorDTO> favorsDTOListFromComponents;
|
private List<FavorDTO> favorsDTOListFromComponents;
|
||||||
|
|
||||||
public ComponentDTO(Component component){
|
public ComponentDTO(Component component){
|
||||||
this.id =component.getId();
|
this.id =component.getId();
|
||||||
this.ComponentName = component.getComponentName();
|
this.componentName = component.getComponentName();
|
||||||
this.Amount = component.getAmount();
|
this.amount = component.getAmount();
|
||||||
this.favorsDTOListFromComponents = component.getFavors() == null ? null: component.getFavors()
|
this.favorsDTOListFromComponents = component.getFavors() == null ? null: component.getFavors()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(x -> x.getComponents().contains(component.getId()))
|
.filter(x -> x.getComponents().contains(component.getId()))
|
||||||
@ -27,10 +27,10 @@ public class ComponentDTO {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
public String getComponentName(){
|
public String getComponentName(){
|
||||||
return ComponentName;
|
return componentName;
|
||||||
}
|
}
|
||||||
public Integer getAmount(){
|
public Integer getAmount(){
|
||||||
return Amount;
|
return amount;
|
||||||
}
|
}
|
||||||
public List<FavorDTO> getFavorsDTOListFromComponents() {
|
public List<FavorDTO> getFavorsDTOListFromComponents() {
|
||||||
return favorsDTOListFromComponents;
|
return favorsDTOListFromComponents;
|
||||||
|
@ -2,8 +2,16 @@ package ru.ulstu.is.sbapp.repair.repository;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.is.sbapp.repair.model.Component;
|
import ru.ulstu.is.sbapp.repair.model.Component;
|
||||||
|
|
||||||
public interface ComponentRepository extends JpaRepository<Component, Long> {
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ComponentRepository extends JpaRepository<Component, Long> {
|
||||||
|
@Query(value = "select * from Component where (\"ID\" = :id or :id is Null) and " +
|
||||||
|
"(\"NAME\" = :componentName or :componentName is Null) and " +
|
||||||
|
"(\"AMOUNT\" = :amount or :amount is Null)", nativeQuery = true)
|
||||||
|
public List<Component> findFilteredComponents(@Param("id") Long id,
|
||||||
|
@Param("componentName") String componentName,
|
||||||
|
@Param("amount") int amount );
|
||||||
}
|
}
|
||||||
|
@ -28,15 +28,16 @@ public class ComponentService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Component addComponent(String name, int amount) {
|
public Component addComponent(String name, int amount) {
|
||||||
if (!StringUtils.hasText(name)) {
|
|
||||||
throw new IllegalArgumentException("name is null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
final Component component = new Component(amount, name);
|
final Component component = new Component(amount, name);
|
||||||
validatorUtil.validate(component);
|
validatorUtil.validate(component);
|
||||||
return componentRepository.save(component);
|
return componentRepository.save(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<Component> findFilteredComponents(Long id, String componentName, int amount) {
|
||||||
|
return componentRepository.findFilteredComponents(id, componentName, amount);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Component findComponent(Long id) {
|
public Component findComponent(Long id) {
|
||||||
final Optional <Component> component = componentRepository.findById(id);
|
final Optional <Component> component = componentRepository.findById(id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user