소스 검색

feat: habilitarPeriodo service

AldrickChavarria 3 달 전
부모
커밋
a70d5b5b03
2개의 변경된 파일35개의 추가작업 그리고 1개의 파일을 삭제
  1. 33 1
      Back/backendP-Educativa/app/Http/Controllers/Api/PeriodoController.php
  2. 2 0
      Back/backendP-Educativa/routes/api.php

+ 33 - 1
Back/backendP-Educativa/app/Http/Controllers/Api/PeriodoController.php

@@ -74,7 +74,7 @@ class PeriodoController extends Controller
                 'idPeriodo' => 'required|string|max:10',
             ]);
 
-            // Desactivar todos los periodos excepto el estatus Eliminado
+            
             DB::table('periodos')
                 ->where('estatus', '<>', 'Eliminado')
                 ->update(['estatus' => 'Inactivo']);
@@ -131,6 +131,38 @@ class PeriodoController extends Controller
         }
     }
 
+    public function habilitarPeriodo(Request $request)
+    {
+        try {
+            $validated = $request->validate([
+                'idPeriodo' => 'required|string|max:10',
+            ]);
+
+            $updated = DB::table('periodos')
+                ->where('idPeriodo', $validated['idPeriodo'])
+                ->update([
+                    'estatus' => 'Inactivo',
+                    'ulActualizacion' => now(),
+                ]);
+
+            if ($updated) {
+                return response()->json([
+                    'mensaje' => 'Periodo eliminado correctamente',
+                    'idPeriodo' => $validated['idPeriodo']
+                ], 200);
+            } else {
+                return response()->json([
+                    'mensaje' => 'No se encontró el periodo para eliminar'
+                ], 404);
+            }
+
+        } catch (\Exception $e) {
+            return response()->json([
+                'mensaje' => 'Error al eliminar el periodo: ' . $e->getMessage()
+            ], 500);
+        }
+    }
+
 
 
 

+ 2 - 0
Back/backendP-Educativa/routes/api.php

@@ -68,6 +68,8 @@ Route::middleware(['auth:sanctum'])->group(function () {
     Route::get('getAllPeriodos', [PeriodoController::class, 'getAllPeriodos']);
     Route::post('activarPeriodo', [PeriodoController::class, 'activarPeriodo']);
     Route::post('deshabilitarPeriodo', [PeriodoController::class, 'eliminarPeriodo']);
+    Route::post('habilitarPeriodo', [PeriodoController::class, 'habilitarPeriodo']);
+
 
     //Rutas de Usuarios
     Route::get('count', [ActividadController::class, 'count']);