Skip to content

Commit 696cb84

Browse files
committed
HotFix: Problemas de JSON recetas adecuación variable a ISO Ubuntu, parametro unidad de medida
1 parent 2c7800e commit 696cb84

3 files changed

Lines changed: 64 additions & 52 deletions

File tree

API (SpringBoot)/Proyecto/src/main/java/com/example/Proyecto/dto/RecetaDetalleDTO.java

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,20 @@ public class RecetaDetalleDTO {
77
private Long idReceta;
88
private Long idProducto;
99
private String nombreProducto;
10+
1011
private Long idIngrediente;
1112
private String nombreIngrediente;
1213

13-
private Long idUnidad;
1414
private BigDecimal cantidadRequerida;
15-
private String nombreUnidad;
16-
17-
public String getNombreUnidad() {
18-
return nombreUnidad;
19-
}
20-
21-
public BigDecimal getCantidadRequerida() {
22-
return cantidadRequerida;
23-
}
24-
25-
public String getNombreIngrediente() {
26-
return nombreIngrediente;
27-
}
2815

29-
public Long getIdIngrediente() {
30-
return idIngrediente;
31-
}
16+
// 🔥 IMPORTANTE
17+
private Long idUnidad;
3218

33-
public String getNombreProducto() {
34-
return nombreProducto;
35-
}
19+
private String nombreUnidad;
3620

37-
public Long getIdProducto() {
38-
return idProducto;
39-
}
21+
// =========================
22+
// GETTERS Y SETTERS
23+
// =========================
4024

4125
public Long getIdReceta() {
4226
return idReceta;
@@ -46,30 +30,59 @@ public void setIdReceta(Long idReceta) {
4630
this.idReceta = idReceta;
4731
}
4832

33+
public Long getIdProducto() {
34+
return idProducto;
35+
}
36+
4937
public void setIdProducto(Long idProducto) {
5038
this.idProducto = idProducto;
5139
}
5240

41+
public String getNombreProducto() {
42+
return nombreProducto;
43+
}
44+
5345
public void setNombreProducto(String nombreProducto) {
5446
this.nombreProducto = nombreProducto;
5547
}
5648

49+
public Long getIdIngrediente() {
50+
return idIngrediente;
51+
}
52+
5753
public void setIdIngrediente(Long idIngrediente) {
5854
this.idIngrediente = idIngrediente;
5955
}
6056

57+
public String getNombreIngrediente() {
58+
return nombreIngrediente;
59+
}
60+
6161
public void setNombreIngrediente(String nombreIngrediente) {
6262
this.nombreIngrediente = nombreIngrediente;
6363
}
6464

65+
public BigDecimal getCantidadRequerida() {
66+
return cantidadRequerida;
67+
}
68+
6569
public void setCantidadRequerida(BigDecimal cantidadRequerida) {
6670
this.cantidadRequerida = cantidadRequerida;
6771
}
6872

73+
public Long getIdUnidad() {
74+
return idUnidad;
75+
}
76+
77+
public void setIdUnidad(Long idUnidad) {
78+
this.idUnidad = idUnidad;
79+
}
80+
81+
public String getNombreUnidad() {
82+
return nombreUnidad;
83+
}
84+
6985
public void setNombreUnidad(String nombreUnidad) {
7086
this.nombreUnidad = nombreUnidad;
7187
}
72-
73-
public Long getIdUnidad() { return idUnidad; } // ← faltaba
74-
public void setIdUnidad(Long idUnidad) { this.idUnidad = idUnidad; }
75-
}
88+
}

API (SpringBoot)/Proyecto/src/main/java/com/example/Proyecto/dto/RecetaRequest.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@
33
import java.math.BigDecimal;
44
import java.util.List;
55

6-
/**
7-
* DTO utilizado para recibir los datos de una nueva receta o una actualización.
8-
* Contiene el ID del producto y la lista de ingredientes requeridos.
9-
*/
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
108
public class RecetaRequest {
119

12-
// El ID del producto al que pertenece la receta
1310
private Long idProducto;
14-
15-
// La lista de ingredientes y sus cantidades
1611
private List<IngredienteReceta> ingredientes;
1712

18-
// ==========================================================
19-
// Getters y Setters de RecetaRequest
20-
// ==========================================================
21-
2213
public Long getIdProducto() {
2314
return idProducto;
2415
}
@@ -35,22 +26,17 @@ public void setIngredientes(List<IngredienteReceta> ingredientes) {
3526
this.ingredientes = ingredientes;
3627
}
3728

38-
// ==========================================================
39-
// Clase interna DTO: IngredienteReceta
40-
// ==========================================================
41-
42-
/**
43-
* DTO interno que representa un solo ingrediente dentro de la lista de la receta.
44-
*/
29+
// ==========================================
4530
public static class IngredienteReceta {
4631

4732
private Long idIngrediente;
48-
// Se usa BigDecimal para evitar errores de precisión con la cantidad
33+
34+
// 🔥 MAPEA LO QUE ENVÍA LARAVEL
35+
@JsonProperty("cantidadRequerida")
4936
private BigDecimal cantidadNecesaria;
50-
// Se usa el ID de la unidad (Long), consistente con la DB
37+
5138
private Long idUnidad;
5239

53-
// Getters
5440
public Long getIdIngrediente() {
5541
return idIngrediente;
5642
}
@@ -63,7 +49,6 @@ public Long getIdUnidad() {
6349
return idUnidad;
6450
}
6551

66-
// Setters
6752
public void setIdIngrediente(Long idIngrediente) {
6853
this.idIngrediente = idIngrediente;
6954
}

API (SpringBoot)/Proyecto/src/main/java/com/example/Proyecto/service/Inventario/RecetasService.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,41 @@ public void eliminarReceta(Long idProducto) {
162162

163163
// Modificación en RecetasService.java
164164
public List<RecetaDetalleDTO> obtenerTodasLasRecetasOptimizadas() {
165+
165166
String sql = "SELECT r.ID_RECETA, r.ID_PRODUCTO, p.NOMBRE_PRODUCTO, " +
166-
"rd.ID_INGREDIENTE, i.NOMBRE_INGREDIENTE, rd.CANTIDAD_REQUERIDA, u.NOMBRE_UNIDAD " +
167+
"rd.ID_INGREDIENTE, i.NOMBRE_INGREDIENTE, rd.CANTIDAD_REQUERIDA, " +
168+
"rd.ID_UNIDAD, u.NOMBRE_UNIDAD " + // ✅ FIX CLAVE
167169
"FROM recetas_detalle rd " +
168170
"JOIN recetas r ON rd.ID_RECETA = r.ID_RECETA " +
169171
"JOIN productos p ON r.ID_PRODUCTO = p.ID_PRODUCTO " +
170172
"LEFT JOIN ingredientes i ON rd.ID_INGREDIENTE = i.ID_INGREDIENTE " +
171173
"LEFT JOIN unidades_medida u ON rd.ID_UNIDAD = u.ID_UNIDAD";
172-
// cambios relevantes
174+
173175
return jdbcTemplate.query(sql, (rs, rowNum) -> {
176+
174177
RecetaDetalleDTO dto = new RecetaDetalleDTO();
178+
175179
dto.setIdReceta(rs.getLong("ID_RECETA"));
176180
dto.setIdProducto(rs.getLong("ID_PRODUCTO"));
177181
dto.setNombreProducto(rs.getString("NOMBRE_PRODUCTO"));
182+
178183
dto.setIdIngrediente(rs.getLong("ID_INGREDIENTE"));
179184
dto.setNombreIngrediente(rs.getString("NOMBRE_INGREDIENTE"));
185+
180186
dto.setCantidadRequerida(rs.getBigDecimal("CANTIDAD_REQUERIDA"));
187+
188+
// 🔥 FIX CRÍTICO
189+
dto.setIdUnidad(
190+
rs.getObject("ID_UNIDAD") != null
191+
? rs.getLong("ID_UNIDAD")
192+
: null
193+
);
194+
181195
dto.setNombreUnidad(rs.getString("NOMBRE_UNIDAD"));
196+
182197
return dto;
183198
});
184199
}
185-
186200
public List<RecetaDetalleDTO> obtenerRecetaOptimizadaPorProducto(Long idProducto) {
187201
String sql = "SELECT r.ID_RECETA, r.ID_PRODUCTO, p.NOMBRE_PRODUCTO, " +
188202
"rd.ID_INGREDIENTE, i.NOMBRE_INGREDIENTE, rd.CANTIDAD_REQUERIDA, " +

0 commit comments

Comments
 (0)