67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Traits\Show;
|
|
|
|
use App\Http\Resources\ShowResource;
|
|
use App\Lib\RabbitMQSender;
|
|
use App\Models\Show\Show;
|
|
use App\Models\Show\ShowHosts;
|
|
use App\Models\Spot\SpotShow;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
trait ShowTrait
|
|
{
|
|
/**
|
|
* @param array $showData
|
|
* @param ShowDays[] $showDays
|
|
* @param ShowHosts[] $showDJs
|
|
*
|
|
* @return string|void
|
|
* @throws Exception
|
|
*/
|
|
public function createShow(array $showData, array $showDays, array|null $showDJs)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
$show = Show::create($showData);
|
|
$this->createShowDays($show, $showDays);
|
|
if (isset($showDJs)) {
|
|
$this->manageShowDjs($show, $showDJs);
|
|
}
|
|
$this->manageShowInstances($show);
|
|
$show->save();
|
|
## TODO Add show to table of spots
|
|
if($showData['show_type'] === 'spot') {
|
|
$show->spotShow()->create();
|
|
}
|
|
DB::commit();
|
|
} catch (Exception $e) {
|
|
DB::rollBack();
|
|
throw new Exception($e->getMessage());
|
|
} catch (Throwable $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function updateShow(array $showData, int $showId, array|null $showDJs){
|
|
try {
|
|
DB::beginTransaction();
|
|
$show = Show::findOrFail($showData['id']);
|
|
$show->update($showData);
|
|
if (isset($showDJs)) {
|
|
$this->manageShowDjs($show, $showDJs);
|
|
}
|
|
DB::commit();
|
|
} catch (Exception $e) {
|
|
DB::rollBack();
|
|
throw new Exception($e->getMessage());
|
|
} catch (Throwable $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
}
|
|
}
|