feat: userProfile

This commit is contained in:
Michael 2025-07-16 11:36:10 +02:00
parent 4e8664ee31
commit 8f24453eff
28 changed files with 457 additions and 113 deletions

View file

@ -2,30 +2,25 @@
namespace App\Http\Controllers;
use App\Filters\Show\ShowFilters;
use App\Http\Controllers\Controller;
use App\Http\Requests\ShowRequest;
use App\Http\Resources\ShowResource;
use App\Actions\Fortify\UpdateUserProfileInformation;
use App\Models\Show\Show;
use App\Models\User;
use App\Traits\ScheduleTrait;
use App\Traits\Show\ShowDaysTrait;
use App\Traits\Show\ShowDjTrait;
use App\Traits\Show\ShowInstancesTrait;
use App\Traits\Show\ShowTrait;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Exception;
use Log;
# TODO Expose the show instance generation for user interaction and pypo queue
# When pypo requests the schedule up to a certain date, generate the shows up to that date
class UserController extends Controller
{
public function index(Request $request)
{
$queryParams = collect($request->except('withShow'));
$userFilter = (new User())->searchFilter($queryParams);
if($request->withShow) $userFilter = $userFilter->with('showDjs');
$userFilter = (new User())->searchFilter($queryParams);
if ($request->withShow) {
$userFilter = $userFilter->with('showDjs');
}
return response()->json($userFilter->get());
}
@ -41,24 +36,54 @@ class UserController extends Controller
$show = Show::firstOrCreate($showInfos);
$this->manageShowDays($show, $showDaysRules);
$this->manageShowDjs($showDjs, $show);
}catch(Exception $e){
} catch (Exception $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
return response()->json(['message' => 'Show created successfully']);
}
public function show(ShowResource $show)
public function show(User $user)
{
return new ShowResource($show);
$allowedRoles = ['admin', 'editor'];
$authenticatedUser = auth()->user();
if ( ! $authenticatedUser && ! in_array($authenticatedUser->type, $allowedRoles)) {
return response()->json(['message' => 'Forbidden'], 403);
}
return response()->json($user);
}
public function update(ShowRequest $request, Show $show)
public function userProfile()
{
$show->update($request->validated());
return new ShowResource($show);
return response()->json(auth()->user());
}
public function update(Request $request, User $user, UpdateUserProfileInformation $updater)
{
$authenticatedUser = auth()->user();
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')) {
return response()->json(['message' => 'You do not have permission to edit your own profile.'], 403);
}
try {
(new UpdateUserProfileInformation())->update($user, $request->all());
$user->load('preferences');
return response()->json($user);
} catch (\Throwable $e) {
Log::error($e->getMessage());
return response()->json(['message' => 'Failed to update user'], 500);
}
}
public function destroy(Request $request)
{
try {
@ -71,10 +96,4 @@ class UserController extends Controller
return response()->json(['message' => $responseMessage]);
}
public function testSchedule(int $showId)
{
$show = Show::find($showId);
$this->manageShowSchedule($show);
}
}