Refactor entity classes to change ID type from Long to Integer; update User registration method to accept Departamento object
This commit is contained in:
parent
0551d35bab
commit
5df6894c10
|
|
@ -18,7 +18,7 @@ public class Categoria {
|
|||
@Id
|
||||
@Column(name = "idcategoria")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String nombre;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class Departamento {
|
|||
@Id
|
||||
@Column(name = "iddepartamentos")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) // ID autoincremental
|
||||
private int id;
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false, unique = true) // No se permite usuarios duplicados
|
||||
private String nombre;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import lombok.Getter;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -22,10 +23,10 @@ public class Item {
|
|||
private Integer id;
|
||||
|
||||
@Column(name = "fecha_alta",nullable = false)
|
||||
private Date fechaAlta;
|
||||
private LocalDate fechaAlta;
|
||||
|
||||
@Column(name = "fecha_modificacion")
|
||||
private Date fechaModificacion;
|
||||
private LocalDate fechaModificacion;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "users_id", nullable = false)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class Propiedad {
|
|||
@Id
|
||||
@Column(name = "idpropiedad")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String nombre;
|
||||
|
|
@ -26,6 +26,6 @@ public class Propiedad {
|
|||
@JoinColumn(name = "tipodato_idtipodato")
|
||||
private TipoDato tipoDato;
|
||||
|
||||
@OneToMany(mappedBy = "priopiedad")
|
||||
@OneToMany(mappedBy = "propiedad")
|
||||
private List<Valor> valores;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class TipoDato {
|
|||
@Id
|
||||
@Column(name = "idtipodato")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "tipo_dato")
|
||||
private String tipoDato;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class Ubicacion {
|
|||
@Id
|
||||
@Column(name = "idubicacion")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String nombre;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ public class User {
|
|||
|
||||
@OneToMany(mappedBy = "user")
|
||||
private List<Item> items;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "departamentos_iddepartamentos", nullable = true)
|
||||
private Departamento departamento;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ieslamar.GestionInventario.services;
|
||||
|
||||
import com.ieslamar.GestionInventario.entities.Departamento;
|
||||
import com.ieslamar.GestionInventario.entities.Role;
|
||||
import com.ieslamar.GestionInventario.entities.User;
|
||||
import com.ieslamar.GestionInventario.repos.UserRepository;
|
||||
|
|
@ -18,13 +19,13 @@ public class UserService {
|
|||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public void registerUser(String username, String password, String role, String mail, Integer departamentos_iddepartamentos) {
|
||||
public void registerUser(String username, String password, String role, String mail, Departamento departamento) {
|
||||
User user = new User();
|
||||
user.setNombre(username);
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
user.setRole(Role.valueOf(role));
|
||||
user.setMail(mail);
|
||||
user.setDepartamentos_iddepartamentos(departamentos_iddepartamentos);
|
||||
user.setDepartamento(departamento);
|
||||
userRepository.save(user);
|
||||
}
|
||||
public List<User> getAllUsers() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue