feat: userProfile

This commit is contained in:
Michael 2025-07-18 14:10:37 +02:00
parent 8f24453eff
commit 13a3de9709
16 changed files with 492 additions and 284 deletions

View file

@ -56,34 +56,38 @@ class UserController extends Controller
public function userProfile()
{
return response()->json(auth()->user());
$user =auth()->user();
$user->role = $user->roles()->value('name');
return response()->json($user);
}
public function update(Request $request, User $user, UpdateUserProfileInformation $updater)
{
$authenticatedUser = auth()->user();
if ($authenticatedUser->id !== $user->id && ! $authenticatedUser->hasPermissionTo('user.manageAll')) {
if ($authenticatedUser->id !== $user->id && !$authenticatedUser->hasPermissionTo('user.manageAll')) {
return response()->json(['message' => 'You do not have permission to edit other users.'], 403);
}
if ($authenticatedUser->id === $user->id && ! $authenticatedUser->hasPermissionTo('users.manageOwn')) {
if ($authenticatedUser->id === $user->id && !$authenticatedUser->hasPermissionTo('users.manageOwn')) {
return response()->json(['message' => 'You do not have permission to edit your own profile.'], 403);
}
try {
(new UpdateUserProfileInformation())->update($user, $request->all());
$updater->update($user, $request->all());
$user->load('preferences');
return response()->json($user);
} catch (\Throwable $e) {
Log::error($e->getMessage());
if ($e instanceof \Illuminate\Validation\ValidationException) {
return response()->json(['message' => $e->getMessage(), 'errors' => $e->errors()], 422);
}
return response()->json(['message' => 'Failed to update user'], 500);
}
}
public function destroy(Request $request)
{
try {