59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Show;
|
|
|
|
use App\Filters\ShowFilters;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\ShowRequest;
|
|
use App\Http\Resources\ShowHostsResource;
|
|
use App\Http\Resources\ShowResource;
|
|
use App\Models\Show\Show;
|
|
use App\Models\Show\ShowDays;
|
|
use App\Models\Show\ShowHosts;
|
|
|
|
class ShowController extends Controller
|
|
{
|
|
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();
|
|
}
|
|
|
|
public function store(ShowRequest $request)
|
|
{
|
|
// We create a show
|
|
$showResource = new ShowResource(Show::create($request->validated()));
|
|
// We then set the rules for the future show instances within cc_show_days
|
|
$showDaysResource = new showDaysResource(ShowDays::create($request->validated()));
|
|
// We create those instances following the saved rules
|
|
// custom, can't do much about
|
|
// We handle show hosts
|
|
$showHostResource = new ShowHostsResource(ShowHosts::create($request->validated()));
|
|
}
|
|
|
|
public function show(ShowResource $show)
|
|
{
|
|
return new ShowResource($show);
|
|
}
|
|
|
|
public function update(ShowRequest $request, Show $show)
|
|
{
|
|
//Check if instances have to be resized
|
|
$show->update($request->validated());
|
|
|
|
return new ShowResource($show);
|
|
}
|
|
|
|
public function destroy(ShowRequest $showRequest)
|
|
{
|
|
// TODO Delete show instances and hosts too
|
|
$showRequest->delete();
|
|
|
|
return response()->json();
|
|
}
|
|
}
|