diff --git a/.vs/PIS-proyect/FileContentIndex/c99f5113-1122-4638-b05d-1f66fd627d31.vsidx b/.vs/PIS-proyect/FileContentIndex/c99f5113-1122-4638-b05d-1f66fd627d31.vsidx new file mode 100644 index 0000000..18aba43 Binary files /dev/null and b/.vs/PIS-proyect/FileContentIndex/c99f5113-1122-4638-b05d-1f66fd627d31.vsidx differ diff --git a/.vs/PIS-proyect/FileContentIndex/read.lock b/.vs/PIS-proyect/FileContentIndex/read.lock new file mode 100644 index 0000000..e69de29 diff --git a/.vs/PIS-proyect/config/applicationhost.config b/.vs/PIS-proyect/config/applicationhost.config new file mode 100644 index 0000000..0d88f0d --- /dev/null +++ b/.vs/PIS-proyect/config/applicationhost.config @@ -0,0 +1,1016 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.vs/PIS-proyect/v17/.suo b/.vs/PIS-proyect/v17/.suo new file mode 100644 index 0000000..29dbfd4 Binary files /dev/null and b/.vs/PIS-proyect/v17/.suo differ diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..f8b4888 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..38f11aa --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,10 @@ +{ + "ExpandedNodes": [ + "", + "\\app", + "\\app\\Models", + "\\app\\Providers" + ], + "SelectedNode": "\\app\\Providers\\AppServiceProvider.php", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/phptasks.json b/.vs/phptasks.json new file mode 100644 index 0000000..e6e3456 --- /dev/null +++ b/.vs/phptasks.json @@ -0,0 +1,3 @@ +{ + "tasks": [] +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..ef3f236 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/app/Http/Controllers/Api/EstandarController.php b/app/Http/Controllers/Api/EstandarController.php new file mode 100644 index 0000000..c3a9e3d --- /dev/null +++ b/app/Http/Controllers/Api/EstandarController.php @@ -0,0 +1,92 @@ +validate([ + "name"=>"required", + ]); + $id_user = auth()->user()->id; + $estandar = new Estandar(); + $estandar->id_user = $id_user; + $estandar->name = $request->name; + $estandar->save(); + return response([ + "status" => 1, + "msg" => "!Estandar creado exitosamente", + ]); + } + + public function listEstandar(){ + $estandares = Estandar::all(); + return response([ + "status" => 1, + "msg" => "!Lista de Estandares", + "data" => $estandares, + ]); + } + + public function showEstandar($id){ + if(Estandar::where("id",$id)->exists()){ + $estandar = Estandar::find($id); + return response([ + "status" => 1, + "msg" => "!Estandar", + "data" => $estandar, + ]); + } + else{ + return response([ + "status" => 0, + "msg" => "!No se encontro el estandar", + ],404); + } + + } + + public function updateEstandar(Request $request, $id){ + $id_user = auth()->user()->id; + if(Estandar::where(["id_user"=>$id_user,"id"=>$id])->exists()){ + $estandar = Estandar::find($id); + $estandar->name = isset($request->name) ? $request->name : $estandar->title; + $estandar->save(); + return response([ + "status" => 1, + "msg" => "!Estandar actualizado", + "data" => $estandar, + ]); + } + else{ + return response([ + "status" => 0, + "msg" => "!No se encontro el estandar o no esta autorizado", + ],404); + } + + } + + public function deleteEstandar($id){ + $id_user = auth()->user()->id; + if(Estandar::where(["id"=>$id,"id_user"=>$id_user])->exists()){ + $estandar = Estandar::where(["id"=>$id,"id_user"=>$id_user])->first(); + $estandar->delete(); + return response([ + "status" => 1, + "msg" => "!Estandar eliminado", + ]); + } + else{ + return response([ + "status" => 0, + "msg" => "!No se encontro el estandar o no esta autorizado", + ],404); + } + } +} diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index a439d96..49173bc 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -12,12 +12,14 @@ class UserController extends Controller public function register(Request $request){ $request->validate([ 'name'=>'required', + 'lastname'=>'required', 'email'=>'required|email|unique:users', 'password'=>'required|confirmed' ]); $user = new User(); $user->name = $request->name; + $user->lastname = $request->lastname; $user->email = $request->email; $user->password = Hash::make($request->password); $user->save(); @@ -42,18 +44,18 @@ class UserController extends Controller return response()->json([ "message" => "Usuario logueado", "access_token" => $token - ]); + ]); }else{ return response()->json([ "message" => "La password es incorrecta", - ], 404); + ], 404); } }else{ return response()->json([ "status" => 0, "message" => "Usuario no registrado", - ], 404); + ], 404); } } @@ -62,15 +64,15 @@ class UserController extends Controller "status" => 0, "message" => "Perfil de usuario", "data" => auth()->user() - ]); + ]); } public function logout(){ auth()->user()->tokens()->delete(); return response()->json([ "status" => 1, - "message" => "Cierre de Sesión", - ]); + "message" => "Cierre de Sesión", + ]); } - + } diff --git a/app/Models/Estandar.php b/app/Models/Estandar.php index 9508406..31bc854 100644 --- a/app/Models/Estandar.php +++ b/app/Models/Estandar.php @@ -7,5 +7,23 @@ use Illuminate\Database\Eloquent\Model; class Estandar extends Model { + use HasFactory; + public $timestamps = false; + + protected $table ='estandars'; + protected $fillable = [ + 'name', + ]; + + + public function users(){ + return $this->belongsTo(User::class,'id_user'); + } + public function plans(){ + return $this->hasMany(Plan::class,'id'); + } + public function evidencias(){ + return $this->hasMany(Evidencia::class,'id'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index bb9807d..736249b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,10 +17,21 @@ class User extends Authenticatable protected $fillable = [ 'name', + 'lastname', 'email', 'password', ]; public $timestamps = false; + public function estandars(){ + return $this->hasMany(Estandar::class,'id'); + } + public function plans(){ + return $this->hasMany(Plan::class,'id'); + } + public function evidencias(){ + return $this->hasMany(Evidencia::class,'id'); + } + } diff --git a/app/Models/evidencia.php b/app/Models/evidencia.php new file mode 100644 index 0000000..c53d8ae --- /dev/null +++ b/app/Models/evidencia.php @@ -0,0 +1,30 @@ +belongsTo(User::class,'id_user'); + } + public function estandars(){ + return $this->belongsTo(Estandar::class,'id_estandar'); + } + +} diff --git a/app/Models/plan.php b/app/Models/plan.php new file mode 100644 index 0000000..5beb005 --- /dev/null +++ b/app/Models/plan.php @@ -0,0 +1,34 @@ +belongsTo(User::class,'id_user'); + } + public function estandars(){ + return $this->belongsTo(Estandar::class,'id_estandar'); + } + +} diff --git a/app/Models/role.php b/app/Models/role.php new file mode 100644 index 0000000..aa72606 --- /dev/null +++ b/app/Models/role.php @@ -0,0 +1,11 @@ +id(); $table->string('name'); + $table->string('lastname'); $table->string('email')->unique(); $table->string('password'); }); diff --git a/database/migrations/2022_06_14_000526_create_estandars_table.php b/database/migrations/2022_06_14_000526_create_estandars_table.php index be00af4..630002a 100644 --- a/database/migrations/2022_06_14_000526_create_estandars_table.php +++ b/database/migrations/2022_06_14_000526_create_estandars_table.php @@ -16,13 +16,13 @@ return new class extends Migration Schema::create('estandars', function (Blueprint $table) { $table->id(); $table->string('name'); - - - $table->timestamps(); + //$table->foreign('id_user')->references('id')->on('users'); + $table->foreignId('id_user') + ->constrained('users'); }); } - + public function down() { Schema::dropIfExists('estandars'); diff --git a/database/migrations/2022_07_06_025121_create_roles_table.php b/database/migrations/2022_07_06_025121_create_roles_table.php new file mode 100644 index 0000000..e24b65c --- /dev/null +++ b/database/migrations/2022_07_06_025121_create_roles_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('roles'); + } +}; diff --git a/database/migrations/2022_07_07_012118_create_plans_table.php b/database/migrations/2022_07_07_012118_create_plans_table.php new file mode 100644 index 0000000..1213777 --- /dev/null +++ b/database/migrations/2022_07_07_012118_create_plans_table.php @@ -0,0 +1,41 @@ +id(); + $table->string('codigo', 11); + $table->string('name'); + $table->string('oportunidad'); + $table->string('semestre', 6); + $table->integer('duracion'); + $table->string('estado', 20); + $table->boolean('eficacia'); + $table->foreignId('id_estandar') + ->constrained('estandars'); + $table->foreignId('id_user') + ->constrained('users'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('plans'); + } +}; diff --git a/database/migrations/2022_07_08_220043_create_evidencias_table.php b/database/migrations/2022_07_08_220043_create_evidencias_table.php new file mode 100644 index 0000000..d0d7b06 --- /dev/null +++ b/database/migrations/2022_07_08_220043_create_evidencias_table.php @@ -0,0 +1,38 @@ +id(); + $table->string('codigo', 16); + $table->string('denominacion'); + $table->string('oportunidad'); + $table->foreignId('id_user') + ->constrained('users'); + $table->foreignId('id_estandar') + ->constrained('estandars'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('evidencias'); + } +}; diff --git a/routes/api.php b/routes/api.php index 46c5a01..76c740c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,13 +3,30 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\Api\UserController; +use App\Http\Controllers\Api\EstandarController; Route::post('register', [UserController::class, 'register']); Route::post('login', [UserController::class, 'login']); Route::middleware("auth:sanctum")->group (function(){ + //rutas auth Route::get('user-profile', [UserController::class,'userProfile']); Route::get('logout', [UserController::class, 'logout']); + + //rutas estandar + Route::post('estandar', [EstandarController::class,'createEstandar']); + Route::get('estandar', [EstandarController::class,'listEstandar']); + Route::get('estandar/{id}', [EstandarController::class,'showEstandar']); + Route::put('estandar/{id}', [EstandarController::class,'updateEstandar']); + Route::delete('estandar/{id}', [EstandarController::class,'deleteEstandar']); + + /*Route::controller(EstandarController::class)->group(function(){ + Route::post('estandar/create', 'createEstandar'); + Route::get('estandar/list', 'listEstandar'); + Route::get('estandar/{id}', 'showEstandar'); + Route::put('estandar/update/{id}', 'updateEstandar'); + Route::delete('estandar/delete/{id}', 'deleteEstandar'); + });*/ }); Route::middleware('auth:sanctum')->get('/user', function (Request $request) {