Skip to content

Commit 32fa0aa

Browse files
committed
Merge branch 'desarrollo' into produccion
2 parents f480492 + 68eccf9 commit 32fa0aa

5 files changed

Lines changed: 166 additions & 151 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public class IngredienteListadoDTO {
99
private String referenciaIngrediente;
1010
private String abreviaturaUnidad; // ← nuevo
1111

12+
private Long idUnidadMedida; // ← AGREGAR
13+
14+
1215
// Constructor vacío (necesario para el nuevo mapper manual)
1316
public IngredienteListadoDTO() {}
1417

@@ -39,4 +42,8 @@ public IngredienteListadoDTO(com.example.Proyecto.model.Ingredientes ingrediente
3942

4043
public String getAbreviaturaUnidad() { return abreviaturaUnidad; } // ← nuevo
4144
public void setAbreviaturaUnidad(String abreviaturaUnidad) { this.abreviaturaUnidad = abreviaturaUnidad; } // ← nuevo
45+
46+
public Long getIdUnidadMedida() { return idUnidadMedida; }
47+
public void setIdUnidadMedida(Long idUnidadMedida) { this.idUnidadMedida = idUnidadMedida; }
48+
4249
}

API (SpringBoot)/Proyecto/src/main/java/com/example/Proyecto/service/PedidosProveedores/PedidosProveedoresService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void marcarComoEntregado(int idPedidoProv) {
230230
}
231231

232232
// 4. Cambiar el estado del pedido a 'ENTREGADO'
233-
String sqlUpdateEstado = "UPDATE pedidos-proveedores SET ESTADO_PEDIDO = 'ENTREGADO' WHERE ID_PEDIDO_PROV = ?";
233+
String sqlUpdateEstado = "UPDATE pedidos_proveedores SET ESTADO_PEDIDO = 'ENTREGADO' WHERE ID_PEDIDO_PROV = ?";
234234
jdbcTemplate.update(sqlUpdateEstado, idPedidoProv);
235235
}
236236
}

Frontend/app/Http/Controllers/Inventario/RecetasController.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,35 @@ public function __construct(RecetasService $recetasService, ProductoService $pro
2121
}
2222

2323
public function index()
24-
{
25-
$resRecetas = $this->recetasService->obtenerTodasLasRecetas();
26-
$productos = $this->productosService->obtenerProductos();
27-
28-
try {
29-
$responseIng = Http::get('http://32.193.167.191:8080/recetas/lista-modal');
30-
$ingredientesParaModal = $responseIng->successful() ? $responseIng->json() : [];
31-
} catch (\Exception $e) {
32-
$ingredientesParaModal = [];
33-
}
24+
{
25+
$resRecetas = $this->recetasService->obtenerTodasLasRecetas();
26+
27+
// ✅ Envolver en try/catch
28+
try {
29+
$productos = $this->productosService->obtenerProductos();
30+
} catch (\Exception $e) {
31+
$productos = [];
32+
Log::error('Error al obtener productos en RecetasController: ' . $e->getMessage());
33+
}
3434

35-
if (!$resRecetas['success']) {
36-
return back()->with('error', $resRecetas['error']);
37-
}
35+
try {
36+
$responseIng = Http::get('http://32.193.167.191:8080/recetas/lista-modal');
37+
$ingredientesParaModal = $responseIng->successful() ? $responseIng->json() : [];
38+
} catch (\Exception $e) {
39+
$ingredientesParaModal = [];
40+
}
3841

39-
return view('inventarioviews.recetas.index', [
40-
'recetas' => $resRecetas['data'],
41-
'productos' => $productos,
42-
'ingredientes' => $ingredientesParaModal
43-
]);
42+
if (!$resRecetas['success']) {
43+
return back()->with('error', $resRecetas['error']);
4444
}
4545

46+
return view('inventarioviews.recetas.index', [
47+
'recetas' => $resRecetas['data'],
48+
'productos' => $productos,
49+
'ingredientes' => $ingredientesParaModal
50+
]);
51+
}
52+
4653
public function show($idProducto)
4754
{
4855
$res = $this->recetasService->obtenerRecetaPorIdProducto($idProducto);
Lines changed: 132 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,164 @@
1-
<?php
1+
<?php
22

3-
namespace App\Services\Inventario;
3+
namespace App\Services\Inventario;
44

5-
use Illuminate\Support\Facades\Http;
5+
use Illuminate\Support\Facades\Http;
66

7-
class CategoriaIngredientesService
8-
{
9-
protected $baseUrl;
10-
11-
public function __construct()
12-
{
13-
// Obtiene la URL base de la API desde el archivo .env
14-
$this->baseUrl = env('API_BASE_URL', 'http://32.193.167.191:8080');
15-
}
16-
17-
/**
18-
* Helper para obtener el cliente HTTP.
19-
* @return \Illuminate\Http\Client\PendingRequest
20-
*/
21-
protected function getApiClient()
7+
class CategoriaIngredientesService
228
{
23-
return Http::baseUrl($this->baseUrl);
24-
}
25-
26-
// =========================================================================
27-
// CRUD: OBTENER TODAS (GET /categorias/ingredientes)
28-
// =========================================================================
29-
30-
/**
31-
* Obtiene el listado de categorías de ingredientes desde la API.
32-
* @return array Retorna un array con 'success' y 'data' o 'error'.
33-
*/
34-
public function obtenerCategoriasIngredientes(): array
35-
{
36-
try {
37-
$response = $this->getApiClient()->get('/categorias/ingredientes');
9+
protected $baseUrl;
10+
11+
public function __construct()
12+
{
13+
// Obtiene la URL base de la API desde el archivo .env
14+
$this->baseUrl = env('API_BASE_URL', 'http://32.193.167.191:8080');
15+
}
16+
17+
/**
18+
* Helper para obtener el cliente HTTP.
19+
* @return \Illuminate\Http\Client\PendingRequest
20+
*/
21+
protected function getApiClient()
22+
{
23+
return Http::baseUrl($this->baseUrl)
24+
->acceptJson()
25+
->contentType('application/json'); }
26+
27+
// =========================================================================
28+
// CRUD: OBTENER TODAS (GET /categorias/ingredientes)
29+
// =========================================================================
30+
31+
/**
32+
* Obtiene el listado de categorías de ingredientes desde la API.
33+
* @return array Retorna un array con 'success' y 'data' o 'error'.
34+
*/
35+
public function obtenerCategoriasIngredientes(): array
36+
{
37+
try {
38+
$response = $this->getApiClient()->get('/categorias/ingredientes');
39+
40+
if ($response->successful()) {
41+
return [
42+
'success' => true,
43+
'data' => $response->json()
44+
];
45+
}
3846

39-
if ($response->successful()) {
4047
return [
41-
'success' => true,
42-
'data' => $response->json()
48+
'success' => false,
49+
'error' => $response->json()['error'] ?? 'Error desconocido al obtener categorías (' . $response->status() . ')'
4350
];
44-
}
45-
46-
return [
47-
'success' => false,
48-
'error' => $response->json()['error'] ?? 'Error desconocido al obtener categorías (' . $response->status() . ')'
49-
];
5051

51-
} catch (\Exception $e) {
52-
return [
53-
'success' => false,
54-
'error' => 'No se pudo conectar con el servidor de la API: ' . $e->getMessage()
55-
];
52+
} catch (\Exception $e) {
53+
return [
54+
'success' => false,
55+
'error' => 'No se pudo conectar con el servidor de la API: ' . $e->getMessage()
56+
];
57+
}
5658
}
57-
}
5859

59-
// =========================================================================
60-
// CRUD: CREAR (POST /nuevacategoriaingrediente)
61-
// =========================================================================
60+
// =========================================================================
61+
// CRUD: CREAR (POST /nuevacategoriaingrediente)
62+
// =========================================================================
63+
64+
/**
65+
* Crea una nueva categoría de ingrediente.
66+
* @param array $data Array con nombreCategoria.
67+
*/
68+
public function crearCategoriaIngrediente(array $data): array
69+
{
70+
try {
71+
$payload = [
72+
'nombreCategoria' => $data['nombreCategoria']
73+
];
6274

63-
/**
64-
* Crea una nueva categoría de ingrediente.
65-
* @param array $data Array con nombreCategoria.
66-
*/
67-
public function crearCategoriaIngrediente(array $data): array
68-
{
69-
try {
70-
$payload = [
71-
'nombreCategoria' => $data['nombreCategoria']
72-
];
75+
$response = $this->getApiClient()->post('/nuevacategoriaingrediente', $payload);
7376

74-
$response = $this->getApiClient()->post('/nuevacategoriaingrediente', $payload);
77+
if ($response->successful()) {
78+
return [
79+
'success' => true,
80+
'response' => $response->body()
81+
];
82+
}
7583

76-
if ($response->successful()) {
7784
return [
78-
'success' => true,
79-
'response' => $response->body()
85+
'success' => false,
86+
'error' => $response->json()['error'] ?? 'Error al crear la categoría (' . $response->status() . ')'
8087
];
81-
}
82-
83-
return [
84-
'success' => false,
85-
'error' => $response->json()['error'] ?? 'Error al crear la categoría (' . $response->status() . ')'
86-
];
8788

88-
} catch (\Exception $e) {
89-
return [
90-
'success' => false,
91-
'error' => 'Fallo de conexión al intentar crear: ' . $e->getMessage()
92-
];
89+
} catch (\Exception $e) {
90+
return [
91+
'success' => false,
92+
'error' => 'Fallo de conexión al intentar crear: ' . $e->getMessage()
93+
];
94+
}
9395
}
94-
}
9596

96-
// =========================================================================
97-
// CRUD: ACTUALIZAR (PUT /categoriaingrediente/{id})
98-
// =========================================================================
97+
// =========================================================================
98+
// CRUD: ACTUALIZAR (PUT /categoriaingrediente/{id})
99+
// =========================================================================
100+
101+
/**
102+
* Actualiza una categoría de ingrediente existente por ID.
103+
*/
104+
public function actualizarCategoriaIngrediente(int $id, array $data): array
105+
{
106+
try {
107+
$payload = [
108+
'nombreCategoria' => $data['nombreCategoria']
109+
];
99110

100-
/**
101-
* Actualiza una categoría de ingrediente existente por ID.
102-
*/
103-
public function actualizarCategoriaIngrediente(int $id, array $data): array
104-
{
105-
try {
106-
$payload = [
107-
'nombreCategoria' => $data['nombreCategoria']
108-
];
111+
$response = $this->getApiClient()->put("/categoriaingrediente/{$id}", $payload);
109112

110-
$response = $this->getApiClient()->put("/categoriaingrediente/{$id}", $payload);
113+
if ($response->successful()) {
114+
return [
115+
'success' => true,
116+
'response' => $response->body()
117+
];
118+
}
111119

112-
if ($response->successful()) {
113120
return [
114-
'success' => true,
115-
'response' => $response->body()
121+
'success' => false,
122+
'error' => $response->json()['error'] ?? 'Error al actualizar la categoría (' . $response->status() . ')'
116123
];
117-
}
118124

119-
return [
120-
'success' => false,
121-
'error' => $response->json()['error'] ?? 'Error al actualizar la categoría (' . $response->status() . ')'
122-
];
123-
124-
} catch (\Exception $e) {
125-
return [
126-
'success' => false,
127-
'error' => 'Fallo de conexión al intentar actualizar: ' . $e->getMessage()
128-
];
125+
} catch (\Exception $e) {
126+
return [
127+
'success' => false,
128+
'error' => 'Fallo de conexión al intentar actualizar: ' . $e->getMessage()
129+
];
130+
}
129131
}
130-
}
131132

132-
// =========================================================================
133-
// CRUD: ELIMINAR (DELETE /eliminarcategoria/{id})
134-
// =========================================================================
133+
// =========================================================================
134+
// CRUD: ELIMINAR (DELETE /eliminarcategoria/{id})
135+
// =========================================================================
136+
137+
/**
138+
* Elimina una categoría de ingrediente por ID.
139+
*/
140+
public function eliminarCategoriaIngrediente(int $id): array
141+
{
142+
try {
143+
$response = $this->getApiClient()->delete("/eliminarcategoria/{$id}");
144+
145+
if ($response->successful()) {
146+
return [
147+
'success' => true,
148+
'response' => $response->body()
149+
];
150+
}
135151

136-
/**
137-
* Elimina una categoría de ingrediente por ID.
138-
*/
139-
public function eliminarCategoriaIngrediente(int $id): array
140-
{
141-
try {
142-
$response = $this->getApiClient()->delete("/eliminarcategoria/{$id}");
152+
return [
153+
'success' => false,
154+
'error' => $response->json()['error'] ?? 'Error al eliminar la categoría (' . $response->status() . ')'
155+
];
143156

144-
if ($response->successful()) {
157+
} catch (\Exception $e) {
145158
return [
146-
'success' => true,
147-
'response' => $response->body()
159+
'success' => false,
160+
'error' => 'Fallo de conexión al intentar eliminar: ' . $e->getMessage()
148161
];
149162
}
150-
151-
return [
152-
'success' => false,
153-
'error' => $response->json()['error'] ?? 'Error al eliminar la categoría (' . $response->status() . ')'
154-
];
155-
156-
} catch (\Exception $e) {
157-
return [
158-
'success' => false,
159-
'error' => 'Fallo de conexión al intentar eliminar: ' . $e->getMessage()
160-
];
161163
}
162-
}
163-
}
164+
}

Frontend/app/Services/Inventario/ProduccionService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function registrarProduccion(array $data): array
6767
// Spring espera el formato de ProduccionRequest (idProducto, cantidadProducida, etc.)
6868
$response = $this->getApiClient()->post('/inventario/produccion', $data);
6969

70-
if ($response->successful() && $response->status() === 201) {
70+
if ($response->successful() ) {
7171
return [
7272
'success' => true,
7373
'response' => $response->json()

0 commit comments

Comments
 (0)