mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-19 07:10:21 +00:00
movidos los ficheros por funciones
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
package com.imprimelibros.erp.configurationERP;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "variables")
|
||||
public class Variable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String clave;
|
||||
|
||||
private String valor;
|
||||
|
||||
// Getters y setters
|
||||
|
||||
public Long getId() { return id; }
|
||||
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public String getClave() { return clave; }
|
||||
|
||||
public void setClave(String clave) { this.clave = clave; }
|
||||
|
||||
public String getValor() { return valor; }
|
||||
|
||||
public void setValor(String valor) { this.valor = valor; }
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.imprimelibros.erp.configurationERP;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface VariableRepository extends JpaRepository<Variable, Long> {
|
||||
Optional<Variable> findByClave(String clave);
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.imprimelibros.erp.configurationERP;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class VariableService {
|
||||
|
||||
@Autowired
|
||||
private VariableRepository variableRepository;
|
||||
|
||||
public Integer getValorEntero(String clave) {
|
||||
return variableRepository.findByClave(clave)
|
||||
.<Integer>map(v -> Integer.parseInt(v.getValor()))
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException("No se encontró la variable con clave '" + clave + "'"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user