2023-10-18 01:11:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Course\Actions;
|
|
|
|
|
|
|
|
use App\Course\Models\CourseMember;
|
|
|
|
use App\Lib\JobMiddleware\JobChannels;
|
|
|
|
use App\Lib\JobMiddleware\WithJobState;
|
|
|
|
use App\Lib\Queue\TracksJob;
|
|
|
|
use App\Setting\NamiSettings;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class CourseDestroyAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
use TracksJob;
|
|
|
|
|
2023-10-18 13:41:24 +02:00
|
|
|
public function handle(int $courseId): void
|
2023-10-18 01:11:36 +02:00
|
|
|
{
|
2023-10-18 13:41:24 +02:00
|
|
|
$course = CourseMember::find($courseId);
|
2023-10-18 01:11:36 +02:00
|
|
|
app(NamiSettings::class)->login()->deleteCourse($course->member->nami_id, $course->nami_id);
|
|
|
|
|
|
|
|
$course->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function asController(CourseMember $course): JsonResponse
|
|
|
|
{
|
2023-10-18 13:41:24 +02:00
|
|
|
$this->startJob($course->id, $course->member->fullname);
|
2023-10-18 01:11:36 +02:00
|
|
|
|
|
|
|
return response()->json([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $parameters
|
|
|
|
*/
|
|
|
|
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
|
|
|
|
{
|
2023-10-18 13:41:24 +02:00
|
|
|
$memberFullname = $parameters[1];
|
2023-10-18 01:11:36 +02:00
|
|
|
|
|
|
|
return $jobState
|
2023-10-18 13:41:24 +02:00
|
|
|
->before('Ausbildung für ' . $memberFullname . ' wird gelöscht')
|
|
|
|
->after('Ausbildung für ' . $memberFullname . ' gelöscht')
|
|
|
|
->failed('Fehler beim Löschen der Ausbildung für ' . $memberFullname)
|
2023-10-18 01:11:36 +02:00
|
|
|
->shouldReload(JobChannels::make()->add('member')->add('course'));
|
|
|
|
}
|
|
|
|
}
|