diff --git a/app/Http/Controllers/Api/EstadosValoresController.php b/app/Http/Controllers/Api/EstadosValoresController.php new file mode 100644 index 0000000..22cc583 --- /dev/null +++ b/app/Http/Controllers/Api/EstadosValoresController.php @@ -0,0 +1,19 @@ + 1, + "msg" => "!Lista de estados", + "data" => $EstadosValoresList, + ]); + } +} diff --git a/app/Http/Controllers/Api/EstandarController.php b/app/Http/Controllers/Api/EstandarController.php index c3a9e3d..691e211 100644 --- a/app/Http/Controllers/Api/EstandarController.php +++ b/app/Http/Controllers/Api/EstandarController.php @@ -33,6 +33,18 @@ public function listEstandar(){ ]); } + public function listEstandarValores(){ + $estandaresNombreslist = Estandar::select('estandars.name') + ->orderBy('estandars.id','asc') + ->get(); + return response([ + "status" => 1, + "msg" => "!Lista de nombres de Estandares", + "data" => $estandaresNombreslist, + ]); + } + + public function showEstandar($id){ if(Estandar::where("id",$id)->exists()){ $estandar = Estandar::find($id); diff --git a/app/Http/Controllers/Api/PlanController.php b/app/Http/Controllers/Api/PlanController.php index 1fb0da6..d71d3ca 100644 --- a/app/Http/Controllers/Api/PlanController.php +++ b/app/Http/Controllers/Api/PlanController.php @@ -146,7 +146,7 @@ public function listPlan(){ $planAll = plan::select('plans.id','plans.nombre', 'plans.codigo','plans.avance','plans.estado','plans.id_user','estandars.name as estandar_name','users.name as user_name') ->join('estandars', 'plans.id_estandar', '=', 'estandars.id') ->join('users', 'plans.id_user', '=', 'users.id') - ->orderBy('id','asc') + ->orderBy('plans.id','asc') ->get(); foreach($planAll as $plan){ @@ -166,7 +166,6 @@ public function updatePlan(Request $request, $id){ if(plan::where(["id_user"=>$id_user,"id"=>$id])->exists()){ $plan = plan::find($id); $plan->nombre = $request->nombre; - $plan->codigo = $request->codigo; $plan->oportunidad_plan = $request->oportunidad_plan; $plan->semestre_ejecucion = $request->semestre_ejecucion; $plan->duracion = $request->duracion; diff --git a/app/Http/Controllers/Api/ResponsablesController.php b/app/Http/Controllers/Api/ResponsablesController.php index 950cb13..fa34926 100644 --- a/app/Http/Controllers/Api/ResponsablesController.php +++ b/app/Http/Controllers/Api/ResponsablesController.php @@ -4,8 +4,101 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\plan; +use App\Models\Responsables; class ResponsablesController extends Controller { - + public function create(Request $request) { + $request->validate([ + "id_plan"=> "required|integer", + "nombre"=> "required", + ]); + $id_user = auth()->user()->id; + if(plan::where(["id"=>$request->id_plan])->exists()){ + $plan = plan::find($request->id_plan); + if($plan->id_user == $id_user){ + $responsable = new Responsables(); + $responsable->id_plan = $request->id_plan; + $responsable->nombre = $request->nombre; + $responsable->save(); + return response([ + "status" => 1, + "message" => "Responsable creado exitosamente", + ]); + } + else{ + return response([ + "status" => 0, + "message" => "No tienes permisos para crear responsables", + ],404); + } + } + else{ + return response([ + "status" => 0, + "message" => "No se encontro el plan", + ],404); + } + } + + public function update(Request $request){ + $request->validate([ + "id"=> "required|integer", + "nombre"=> "required" + ]); + $id_user = auth()->user()->id; + if(Responsables::where(["id"=>$request->id])->exists()){ + $responsable = Responsables::find($request->id); + $plan = plan::find($responsable->id_plan); + if($plan->id_user == $id_user){ + $responsable->nombre = $request->nombre; + $responsable->save(); + return response([ + "status" => 1, + "message" => "Responsable actualizado exitosamente", + ]); + } + else{ + return response([ + "status" => 0, + "message" => "No tienes permisos para actualizar responsables", + ],404); + } + } + else{ + return response([ + "status" => 0, + "message" => "No se encontro al responsable", + ],404); + } + } + + public function delete($id) + { + $id_user = auth()->user()->id; + if(Responsables::where(["id"=>$id])->exists()){ + $responsable = Responsables::find($id); + $plan = plan::find($responsable->id_plan); + if($plan->id_user == $id_user){ + $responsable->delete(); + return response([ + "status" => 1, + "message" => "Responsable eliminado exitosamente", + ]); + } + else{ + return response([ + "status" => 0, + "message" => "No tienes permisos para eliminar responsables", + ],404); + } + } + else{ + return response([ + "status" => 0, + "message" => "No se encontro al responsable", + ],404); + } + } } diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 49173bc..8fc519c 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -43,7 +43,9 @@ public function login(Request $request){ $token = $user->createToken("auth_token")->plainTextToken; return response()->json([ "message" => "Usuario logueado", - "access_token" => $token + "access_token" => $token, + "nombre" => $user->name, + "apellido" => $user->lastname, ]); }else{ return response()->json([ diff --git a/app/Models/EstadosValores.php b/app/Models/EstadosValores.php new file mode 100644 index 0000000..ca73530 --- /dev/null +++ b/app/Models/EstadosValores.php @@ -0,0 +1,16 @@ + + */ +class EstadosValoresFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + 'valor' => $this, + ]; + } +} diff --git a/database/migrations/2022_08_12_203741_create_estados_valores_table.php b/database/migrations/2022_08_12_203741_create_estados_valores_table.php new file mode 100644 index 0000000..f76611d --- /dev/null +++ b/database/migrations/2022_08_12_203741_create_estados_valores_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('valor'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('estados_valores'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d565153..39584e1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,6 +15,7 @@ class DatabaseSeeder extends Seeder */ public function run() { + //Usuarios \App\Models\User::factory()->create([ "name"=>"Alexis", @@ -135,6 +136,22 @@ public function run() "valor"=>"ComisiĆ³n de desarrollo docente", ]); + // Estados valores : Planificado, Programado, Reprogramado, En proceso o Concluido. + ;\App\Models\EstadosValores::factory()->create([ + "valor"=>"Planificado", + ]); + ;\App\Models\EstadosValores::factory()->create([ + "valor"=>"Programado", + ]); + ;\App\Models\EstadosValores::factory()->create([ + "valor"=>"Reprogramado", + ]); + ;\App\Models\EstadosValores::factory()->create([ + "valor"=>"En proceso", + ]); + ;\App\Models\EstadosValores::factory()->create([ + "valor"=>"Concluido", + ]); } } diff --git a/routes/api.php b/routes/api.php index cbc70aa..442bbeb 100644 --- a/routes/api.php +++ b/routes/api.php @@ -5,7 +5,6 @@ use App\Http\Controllers\Api\UserController; use App\Http\Controllers\Api\EstandarController; use App\Http\Controllers\Api\PlanController; - use App\Http\Controllers\Api\AccionesMejorasController; use App\Http\Controllers\Api\CausasRaicesController; use App\Http\Controllers\Api\FuentesController; @@ -15,6 +14,9 @@ use App\Http\Controllers\Api\MetasController; use App\Http\Controllers\Api\FuentesValoresController; use App\Http\Controllers\Api\ResponsablesValoresController; +use App\Http\Controllers\Api\ResponsablesController; +use App\Http\Controllers\Api\EstadosValoresController; + Route::post('register', [UserController::class, 'register']); Route::post('login', [UserController::class, 'login'])->name('login'); @@ -23,6 +25,10 @@ Route::get('responsables',[ResponsablesValoresController::class,'listResponsablesValores']); //fuentes Valores Route::get('fuentes',[FuentesValoresController::class,'listFuentesValores']); +//Estados valores +Route::get('estados',[EstadosValoresController::class,'listEstadosValores']); +//Estandares valores +Route::get('estandares', [EstandarController::class,'listEstandarValores']); Route::middleware("auth:sanctum")->group (function(){ //rutas auth @@ -79,9 +85,9 @@ Route::delete('causa/{id}',[CausasRaicesController::class,'delete']); //ruta responsables - /*Route::post('responsable',[CausasRaicesController::class,'create']); - Route::put('responsable',[CausasRaicesController::class,'update']); - Route::delete('responsable/{id}',[CausasRaicesController::class,'delete']);*/ + Route::post('responsable',[ResponsablesController::class,'create']); + Route::put('responsable',[ResponsablesController::class,'update']); + Route::delete('responsable/{id}',[ResponsablesController::class,'delete']); });