feat(BE): spot
This commit is contained in:
parent
5af0b32634
commit
ba56bccc35
12 changed files with 193 additions and 73 deletions
15
app/Filters/FiltersType/SpotFilter.php
Normal file
15
app/Filters/FiltersType/SpotFilter.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filters\FiltersType;
|
||||
|
||||
use Log;
|
||||
class SpotFilter
|
||||
{
|
||||
function __invoke($query, $spotTableName, $idColumnName) {
|
||||
try {
|
||||
return $query->whereIn('id', $spotTableName::select($idColumnName));
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,44 +2,38 @@
|
|||
|
||||
namespace App\Filters\Show;
|
||||
|
||||
use App\Filters\FiltersType\AllFilter;
|
||||
use App\Filters\FiltersType\LikeFilter;
|
||||
use App\Models\Spot\SpotPlaylist;
|
||||
|
||||
class ShowFilters
|
||||
{
|
||||
protected $filters = [
|
||||
'name' => LikeFilter::class,
|
||||
'dj' => LikeFilter::class,
|
||||
'genre' => LikeFilter::class,
|
||||
'description' => LikeFilter::class,
|
||||
'color' => LikeFilter::class,
|
||||
'background_color' => LikeFilter::class,
|
||||
'live_stream_using_airtime_auth' => LikeFilter::class,
|
||||
'live_stream_using_custom_auth' => LikeFilter::class,
|
||||
'live_stream_user' => LikeFilter::class,
|
||||
'live_stream_pass' => LikeFilter::class,
|
||||
'linked' => LikeFilter::class,
|
||||
'is_linkable' => LikeFilter::class,
|
||||
'image_path' => LikeFilter::class,
|
||||
'has_autoplaylist' => LikeFilter::class,
|
||||
'autoplaylist_id' => LikeFilter::class,
|
||||
'autoplaylist_repeat' => LikeFilter::class,
|
||||
'all' => AllFilter::class,
|
||||
];
|
||||
|
||||
public function apply($query)
|
||||
public function apply($query, $filters)
|
||||
{
|
||||
foreach ($this->receivedFilters() as $name => $value) {
|
||||
if ($name != 'per_page') {
|
||||
foreach ($this->receivedFilters($filters) as $name => $value) {
|
||||
switch ($name) {
|
||||
case 'all':
|
||||
$name = array_diff(array_keys($this->filters), ['all']);
|
||||
$filterInstance = new $this->filters['all'];
|
||||
break;
|
||||
default:
|
||||
$filterInstance = new $this->filters[$name];
|
||||
$query = $filterInstance($query, $name, $value);
|
||||
break;
|
||||
}
|
||||
$query = $filterInstance($query, $name, $value);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function receivedFilters()
|
||||
public function receivedFilters($filters)
|
||||
{
|
||||
return request()->only(array_keys($this->filters));
|
||||
return $filters->only(array_keys($this->filters));
|
||||
}
|
||||
}
|
|
@ -8,11 +8,13 @@ use App\Models\File;
|
|||
use App\Models\Playlist;
|
||||
use App\Models\PlaylistContent;
|
||||
use App\Models\SmartBlock;
|
||||
use App\Models\Spot\SpotPlaylist;
|
||||
use App\Models\Webstream;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PlaylistController extends Controller
|
||||
{
|
||||
|
@ -22,6 +24,7 @@ class PlaylistController extends Controller
|
|||
* @return string
|
||||
*/
|
||||
public function index(Request $request) {
|
||||
try {
|
||||
if ( ! isset($request->per_page) || is_null($request)) {
|
||||
$pagination = 5;
|
||||
} else {
|
||||
|
@ -29,10 +32,21 @@ class PlaylistController extends Controller
|
|||
}
|
||||
|
||||
return Playlist::searchFilter($request)
|
||||
->with(['creator', 'tracks.file', 'tracks.block', 'tracks.block.criteria', 'tracks.block.creator'])
|
||||
->with(
|
||||
[
|
||||
'creator',
|
||||
'tracks.file',
|
||||
'tracks.block',
|
||||
'tracks.block.criteria',
|
||||
'tracks.block.creator'
|
||||
]
|
||||
)
|
||||
->orderBy('name')
|
||||
->paginate($pagination)
|
||||
->toJson();
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,6 +70,9 @@ class PlaylistController extends Controller
|
|||
'creator_id' => $user->id,
|
||||
'description' => $request->description,
|
||||
]);
|
||||
if($request['playlist_type'] === 'spot') {
|
||||
$dbPlaylist->spotPlaylist()->create();
|
||||
}
|
||||
// dd($request->tracks);
|
||||
foreach($request->tracks as $key => $file) {
|
||||
if (!isset($file['id'])) {
|
||||
|
|
|
@ -25,15 +25,17 @@ class ShowController extends Controller
|
|||
use ShowInstancesTrait;
|
||||
use ShowDjTrait;
|
||||
|
||||
public function index(ShowFilters $filters)
|
||||
public function index(Request $request)
|
||||
{
|
||||
if ( ! isset($filters->per_page) || is_null($filters)) {
|
||||
$pagination = 20;
|
||||
} else {
|
||||
$pagination = $filters->per_page;
|
||||
}
|
||||
|
||||
return Show::searchFilter($filters)->cursorPaginate($pagination)->toJson();
|
||||
if(isset($request->per_page) || is_null($request)) {
|
||||
$pagination = $request->per_page;
|
||||
}
|
||||
return Show::searchFilter($request)
|
||||
->orderBy('name')
|
||||
->paginate($pagination)
|
||||
->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,29 +72,26 @@ class SmartBlockController extends Controller
|
|||
* @return mixed string
|
||||
*/
|
||||
public function save(Request $request) {
|
||||
$user = Auth::user();
|
||||
//dd($user);
|
||||
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();
|
||||
|
||||
$this->saveCriteria($dbSmartBlock, $criteria);
|
||||
//ToDo: save content
|
||||
|
||||
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) {
|
||||
|
@ -102,6 +100,9 @@ class SmartBlockController extends Controller
|
|||
}
|
||||
|
||||
return $dbSmartBlock->toJson();
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Filters\PlaylistFilter;
|
||||
use App\Models\Spot\SpotPlaylist;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use MusicBrainz\Value\Track;
|
||||
|
@ -30,6 +31,10 @@ class Playlist extends Model
|
|||
return $this->hasMany(PlaylistContent::class);
|
||||
}
|
||||
|
||||
public function spotPlaylist(){
|
||||
return $this->hasOne(SpotPlaylist::class, 'playlist_id');
|
||||
}
|
||||
|
||||
public function scopeSearchFilter($query, $request) {
|
||||
$filters = new PlaylistFilter();
|
||||
return $filters->apply($query, $request);
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace App\Models\Show;
|
||||
|
||||
use App\Filters\Show\ShowFilters;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\ShowInstances\ShowInstances;
|
||||
use App\Models\SmartBlock;
|
||||
use App\Models\Spot\SpotShow;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Show extends Model
|
||||
{
|
||||
|
@ -66,13 +66,18 @@ class Show extends Model
|
|||
return $this->hasMany(ShowInstances::class, 'show_id');
|
||||
}
|
||||
|
||||
public function scopeSearchFilter($query, $filters)
|
||||
public function scopeSearchFilter($query, $request)
|
||||
{
|
||||
return $filters->apply($query);
|
||||
$filters = new ShowFilters();
|
||||
return $filters->apply($query, $request);
|
||||
}
|
||||
|
||||
public function playlist()
|
||||
{
|
||||
return $this->belongsTo(Playlist::class, 'autoplaylist_id', 'id');
|
||||
}
|
||||
|
||||
public function spotShow(){
|
||||
return $this->hasOne(SpotShow::class, 'show_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Filters\PlaylistFilter;
|
||||
use App\Models\Spot\SpotSmartBlock;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
@ -41,4 +42,8 @@ class SmartBlock extends Model
|
|||
$filters = new PlaylistFilter();
|
||||
return $filters->apply($query, $request);
|
||||
}
|
||||
|
||||
public function spotSmartBlock(){
|
||||
return $this->hasOne(SpotSmartBlock::class, 'block_id');
|
||||
}
|
||||
}
|
||||
|
|
23
app/Models/Spot/SpotPlaylist.php
Normal file
23
app/Models/Spot/SpotPlaylist.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Spot;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SpotPlaylist extends Model
|
||||
{
|
||||
protected $table = 'wa_spot_playlist';
|
||||
|
||||
protected $fillable = [
|
||||
'playlist_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the playlist associated with this spot.
|
||||
*/
|
||||
public function playlist(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Playlist::class, 'playlist_id');
|
||||
}
|
||||
}
|
24
app/Models/Spot/SpotShow.php
Normal file
24
app/Models/Spot/SpotShow.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Spot;
|
||||
|
||||
use App\Models\Show\Show;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SpotShow extends Model
|
||||
{
|
||||
protected $table = 'wa_spot_show';
|
||||
|
||||
protected $fillable = [
|
||||
'show_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the show associated with this spot.
|
||||
*/
|
||||
public function show(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Show::class, 'show_id');
|
||||
}
|
||||
}
|
24
app/Models/Spot/SpotSmartBlock.php
Normal file
24
app/Models/Spot/SpotSmartBlock.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Spot;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use PhpParser\Node\Stmt\Block;
|
||||
|
||||
class SpotSmartBlock extends Model
|
||||
{
|
||||
protected $table = 'wa_spot_block';
|
||||
|
||||
protected $fillable = [
|
||||
'block_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the block associated with this spot.
|
||||
*/
|
||||
public function block(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Block::class, 'block_id');
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
@ -31,6 +32,10 @@ trait ShowTrait
|
|||
}
|
||||
$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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue