mirror of
https://github.com/koel/koel
synced 2024-12-12 13:42:27 +00:00
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Requests\API\UserStoreRequest;
|
|
use App\Http\Requests\API\UserUpdateRequest;
|
|
use App\Http\Resources\UserResource;
|
|
use App\Models\User;
|
|
use App\Repositories\UserRepository;
|
|
use App\Services\UserService;
|
|
|
|
class UserController extends Controller
|
|
{
|
|
public function __construct(private UserRepository $userRepository, private UserService $userService)
|
|
{
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->authorize('admin', User::class);
|
|
|
|
return UserResource::collection($this->userRepository->getAll());
|
|
}
|
|
|
|
public function store(UserStoreRequest $request)
|
|
{
|
|
$this->authorize('admin', User::class);
|
|
|
|
return UserResource::make($this->userService->createUser(
|
|
$request->name,
|
|
$request->email,
|
|
$request->password,
|
|
$request->get('is_admin') ?: false
|
|
));
|
|
}
|
|
|
|
public function update(UserUpdateRequest $request, User $user)
|
|
{
|
|
$this->authorize('admin', User::class);
|
|
|
|
return UserResource::make($this->userService->updateUser(
|
|
$user,
|
|
$request->name,
|
|
$request->email,
|
|
$request->password,
|
|
$request->get('is_admin') ?: false
|
|
));
|
|
}
|
|
|
|
public function destroy(User $user)
|
|
{
|
|
$this->authorize('destroy', $user);
|
|
$this->userService->deleteUser($user);
|
|
|
|
return response()->noContent();
|
|
}
|
|
}
|