2024-10-16 21:53:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-10-16 23:26:41 +03:00
|
|
|
use App\Models\User;
|
2024-10-16 21:53:02 +03:00
|
|
|
use Illuminate\Http\Request;
|
2024-10-17 19:15:24 +03:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
2024-10-16 21:53:02 +03:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
2024-10-16 23:26:41 +03:00
|
|
|
// GET /user
|
2024-10-16 21:53:02 +03:00
|
|
|
public function index()
|
|
|
|
{
|
2024-10-16 23:26:41 +03:00
|
|
|
return response(User::all());
|
2024-10-16 21:53:02 +03:00
|
|
|
}
|
|
|
|
|
2024-10-16 23:26:41 +03:00
|
|
|
// GET /user/{id}
|
|
|
|
public function show(string $id)
|
2024-10-16 21:53:02 +03:00
|
|
|
{
|
2024-10-17 19:15:24 +03:00
|
|
|
// FIXME: is there more shorter
|
|
|
|
// validation solution
|
|
|
|
$v = Validator::make(["id" => $id], [
|
|
|
|
"id" => 'integer'
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($v->fails())
|
|
|
|
throw new BadRequestException();
|
|
|
|
|
2024-10-17 18:34:22 +03:00
|
|
|
$user = User::query()->findOrFail($id);
|
2024-10-16 23:26:41 +03:00
|
|
|
|
|
|
|
return response($user);
|
2024-10-16 21:53:02 +03:00
|
|
|
}
|
|
|
|
|
2024-10-16 23:26:41 +03:00
|
|
|
// POST /user
|
|
|
|
public function store(Request $request)
|
2024-10-16 21:53:02 +03:00
|
|
|
{
|
2024-10-16 23:26:41 +03:00
|
|
|
return response("Create user");
|
2024-10-16 21:53:02 +03:00
|
|
|
}
|
|
|
|
|
2024-10-16 23:26:41 +03:00
|
|
|
// PUT /user/{id}
|
2024-10-16 21:53:02 +03:00
|
|
|
public function update(Request $request, string $id)
|
|
|
|
{
|
|
|
|
return response("Update user " . $id);
|
|
|
|
}
|
|
|
|
|
2024-10-16 23:26:41 +03:00
|
|
|
// DELETE /user/{id}
|
2024-10-16 21:53:02 +03:00
|
|
|
public function destroy(string $id)
|
|
|
|
{
|
|
|
|
return response("Destroy user " . $id);
|
|
|
|
}
|
|
|
|
}
|