feat(BE): spot

This commit is contained in:
Michael 2025-07-04 00:16:09 +02:00
parent 5af0b32634
commit ba56bccc35
12 changed files with 193 additions and 73 deletions

View file

@ -14,6 +14,7 @@ use http\Exception\BadMethodCallException;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class SmartBlockController extends Controller
{
@ -71,37 +72,37 @@ class SmartBlockController extends Controller
* @return mixed string
*/
public function save(Request $request) {
$user = Auth::user();
//dd($user);
$request->validate([
'name' => 'required|string',
'type' => 'required|string',
'criteria' => 'required|array'
]);
try {
$user = Auth::user();//dd($user);
$request->validate([
'name' => 'required|string',
'type' => 'required|string',
'criteria' => 'required|array'
]);
$criteria = $this->createCriteria($request);
$length = 0;
$dbSmartBlock = SmartBlock::firstOrNew(['id' => $request->id]);
$dbSmartBlock->fill([
'name' => $request->name,
'creator_id' => $user->id,
'description' => $request->description,
'length' => $request->length,
])->save();
if ($request['smart_block_type'] === 'spot') {
$dbSmartBlock->spotSmartBlock()->create();
}
$this->saveCriteria($dbSmartBlock, $criteria);//ToDo: save content
if (is_array($request->tracks) && count($request->tracks) > 0) {
SmartBlockContent::where('block_id', '=', $dbSmartBlock->id)->delete();
foreach ($request->tracks as $key => $track) {
$this->saveContent($track['file'], $dbSmartBlock->id, $key);
}
}
$criteria = $this->createCriteria($request);
$length = 0;
$dbSmartBlock = SmartBlock::firstOrNew(['id' => $request->id]);
$dbSmartBlock->fill([
'name' => $request->name,
'creator_id' => $user->id,
'description' => $request->description,
'length' => $request->length,
])->save();
$this->saveCriteria($dbSmartBlock, $criteria);
//ToDo: save content
if (is_array($request->tracks) && count($request->tracks) > 0) {
SmartBlockContent::where('block_id','=',$dbSmartBlock->id)->delete();
foreach ($request->tracks as $key => $track) {
$this->saveContent($track['file'], $dbSmartBlock->id, $key);
}
}
return $dbSmartBlock->toJson();
return $dbSmartBlock->toJson();
} catch (\Exception $e) {
Log::error($e);
}
}
/**