фильтр не робит
This commit is contained in:
parent
58f188941b
commit
61bc65a4ea
@ -33,7 +33,7 @@ export default {
|
||||
if (urlParams != "") {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += "componentAmount=" + this.serialNumber;
|
||||
urlParams += "amount=" + this.serialNumber;
|
||||
}
|
||||
DataService.readAll(this.dataFilterUrl + urlParams, (data) => new Component(data))
|
||||
.then(data => {
|
||||
|
@ -23,8 +23,8 @@ public class ComponentController {
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ComponentDTO updateComponent(@PathVariable Long id,@RequestParam("name") String name, @RequestParam("amount") Integer amount) {
|
||||
return new ComponentDTO(componentService.updateComponent(id,name, amount));
|
||||
public ComponentDTO updateComponent(@PathVariable Long id,@RequestBody @Valid ComponentDTO componentDTO) {
|
||||
return new ComponentDTO(componentService.updateComponent(id,componentDTO.getComponentName(), componentDTO.getAmount()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@ -48,4 +48,13 @@ public class ComponentController {
|
||||
.map(ComponentDTO::new)
|
||||
.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 {
|
||||
private long id;
|
||||
private String ComponentName;
|
||||
private Integer Amount;
|
||||
private String componentName;
|
||||
private Integer amount;
|
||||
private List<FavorDTO> favorsDTOListFromComponents;
|
||||
|
||||
public ComponentDTO(Component component){
|
||||
this.id =component.getId();
|
||||
this.ComponentName = component.getComponentName();
|
||||
this.Amount = component.getAmount();
|
||||
this.componentName = component.getComponentName();
|
||||
this.amount = component.getAmount();
|
||||
this.favorsDTOListFromComponents = component.getFavors() == null ? null: component.getFavors()
|
||||
.stream()
|
||||
.filter(x -> x.getComponents().contains(component.getId()))
|
||||
@ -27,10 +27,10 @@ public class ComponentDTO {
|
||||
return id;
|
||||
}
|
||||
public String getComponentName(){
|
||||
return ComponentName;
|
||||
return componentName;
|
||||
}
|
||||
public Integer getAmount(){
|
||||
return Amount;
|
||||
return amount;
|
||||
}
|
||||
public List<FavorDTO> getFavorsDTOListFromComponents() {
|
||||
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.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
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
|
||||
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);
|
||||
validatorUtil.validate(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)
|
||||
public Component findComponent(Long id) {
|
||||
final Optional <Component> component = componentRepository.findById(id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user