80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
|
|
|
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\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\Request;
|
|
use Exception;
|
|
|
|
# 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');
|
|
return response()->json($userFilter->get());
|
|
}
|
|
|
|
/**
|
|
* @throws \Exception
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
try {
|
|
$showInfos = $request->show;
|
|
$showDaysRules = $request->showDaysRules;
|
|
$showDjs = $request->showDjs;
|
|
$show = Show::firstOrCreate($showInfos);
|
|
$this->manageShowDays($show, $showDaysRules);
|
|
$this->manageShowDjs($showDjs, $show);
|
|
}catch(Exception $e){
|
|
return response()->json(['message' => $e->getMessage()], 500);
|
|
}
|
|
return response()->json(['message' => 'Show created successfully']);
|
|
}
|
|
|
|
public function show(ShowResource $show)
|
|
{
|
|
return new ShowResource($show);
|
|
}
|
|
|
|
public function update(ShowRequest $request, Show $show)
|
|
{
|
|
$show->update($request->validated());
|
|
|
|
return new ShowResource($show);
|
|
}
|
|
|
|
public function destroy(Request $request)
|
|
{
|
|
try {
|
|
$showIds = $request->input('showIds');
|
|
Show::destroy($showIds);
|
|
$responseMessage = 'Shows deleted';
|
|
} catch (Exception $e) {
|
|
return response()->json(['message' => $e->getMessage()], 500);
|
|
}
|
|
|
|
return response()->json(['message' => $responseMessage]);
|
|
}
|
|
|
|
public function testSchedule(int $showId)
|
|
{
|
|
$show = Show::find($showId);
|
|
$this->manageShowSchedule($show);
|
|
}
|
|
}
|