|
|
@@ -0,0 +1,57 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Api;
|
|
|
+
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
+
|
|
|
+
|
|
|
+class PeriodoController extends Controller
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ public function crearPeriodo(Request $request)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // Validar datos
|
|
|
+ $validated = $request->validate([
|
|
|
+ 'idEscuela' => 'required|string|max:10',
|
|
|
+ 'idPeriodo' => 'required|string|max:10',
|
|
|
+ 'nombrePeriodo' => 'required|string|max:100',
|
|
|
+ 'fechaFinalizacion' => 'required|date',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Insertar en la base de datos
|
|
|
+ DB::table('periodos')->insert([
|
|
|
+ 'idEscuela' => $validated['idEscuela'],
|
|
|
+ 'idPeriodo' => $validated['idPeriodo'],
|
|
|
+ 'nombrePeriodo' => $validated['nombrePeriodo'],
|
|
|
+ 'fechaFinalizacion' => $validated['fechaFinalizacion'],
|
|
|
+ 'estatus' => 'Activo',
|
|
|
+ 'ulActualizacion' => now(),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Crear carpeta en S3 (la carpeta se crea al subir un archivo vacío o establecer un "prefix")
|
|
|
+ $folderPath = 'periodos/' . $validated['nombrePeriodo'] . '/';
|
|
|
+ Storage::disk('s3')->put($folderPath . 'readme.txt', 'Carpeta creada para el periodo ' . $validated['nombrePeriodo']);
|
|
|
+
|
|
|
+ return response()->json([
|
|
|
+ 'mensaje' => 'Periodo creado correctamente',
|
|
|
+ 'carpetaS3' => $folderPath,
|
|
|
+ ], 201);
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return response()->json([
|
|
|
+ 'mensaje' => 'Error al crear el periodo: ' . $e->getMessage()
|
|
|
+ ], 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|