88 lines
2.4 KiB
PHP
88 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Show;
|
|
|
|
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\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 ShowController extends Controller
|
|
{
|
|
use ShowTrait;
|
|
use ShowDaysTrait;
|
|
use ShowInstancesTrait;
|
|
use ShowDjTrait;
|
|
use ScheduleTrait;
|
|
|
|
public function index(ShowFilters $filters)
|
|
{
|
|
if ( ! isset($filters->per_page) || is_null($filters)) {
|
|
$pagination = 20;
|
|
} else {
|
|
$pagination = $filters->per_page;
|
|
}
|
|
|
|
return Show::searchFilter($filters)->cursorPaginate($pagination)->toJson();
|
|
}
|
|
|
|
/**
|
|
* @throws \Exception
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
try {
|
|
$showData = $request->all();
|
|
$showDays = $showData['show_days'];
|
|
$showDJs = $showData['show_djs'];
|
|
$this->createShow($showData, $showDays, $showDJs);
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'message' => 'Show saved successfully!'
|
|
]);
|
|
} catch (Exception $e) {
|
|
return response()->json(['message' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|