fix(routes | controller show): delete

This commit is contained in:
Michael 2025-03-26 10:32:44 +01:00
parent 5879540d69
commit ca005ebb0b
2 changed files with 25 additions and 13 deletions

View file

@ -13,6 +13,7 @@ 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
@ -26,7 +27,7 @@ class ShowController extends Controller
public function index(ShowFilters $filters)
{
if (!isset($filters->per_page) || is_null($filters)) {
if ( ! isset($filters->per_page) || is_null($filters)) {
$pagination = 20;
} else {
$pagination = $filters->per_page;
@ -40,12 +41,17 @@ class ShowController extends Controller
*/
public function store(Request $request)
{
$showInfos = $request->show;
$showDaysRules = $request->showDaysRules;
$showDjs = $request->showDjs;
$show = Show::firstOrCreate($showInfos);
$this->manageShowDays($show, $showDaysRules);
$this->manageShowDjs($showDjs, $show);
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)
@ -55,21 +61,26 @@ class ShowController extends Controller
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)
public function destroy(Request $request)
{
// TODO Delete show instances and hosts too
$showRequest->delete();
try {
$showIds = $request->input('showIds');
Show::destroy($showIds);
$responseMessage = 'Shows deleted';
} catch (Exception $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
return response()->json();
return response()->json(['message' => $responseMessage]);
}
public function testSchedule(int $showId){
public function testSchedule(int $showId)
{
$show = Show::find($showId);
$this->manageShowSchedule($show);
}

View file

@ -36,6 +36,7 @@ Route::resources([
'except' => 'create'
]);
Route::delete('/show', [ShowController::class, 'destroy']);
/**
* Custom file route
*/