Skip to content

Commit

Permalink
Endpoint para el cambio de estado de los usuarios
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresC1 committed Jul 29, 2023
1 parent 0a6705e commit 834084e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Http\Resources\User\UserInfoResource;
use App\Models\User;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand All @@ -25,4 +26,24 @@ public function show()
], 500);
}
}
public function change_status(User $user){
try{
$user->status = $user->status == 'active' ? 'inactive' : 'active';
$user->save();
if($user->status == 'inactive'){
$user->tokens()->delete();
}
return response()->json([
'usuario' => UserInfoResource::make($user),
'mensaje' => 'El estado del usuario cambio',
'estado' => 200
], 200);
} catch(Exception $e) {
return response()->json([
'mensaje' => 'Error al cambiar el estado del usuario',
'error' => $e->getMessage(),
'estado' => 500
], 500);
}
}
}
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
Route::middleware('auth:sanctum')->group(function () {
Route::post('/auth/logout', [AuthController::class, "logout"]);
Route::get('/user/info', [UserController::class, "show"]);
// Estados de los usuarios
Route::get('/user/{user}/change_status', [UserController::class, "change_status"]);
});
});

0 comments on commit 834084e

Please sign in to comment.