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