añadido crd para Song y transladada la logica de /gallery a un controller
This commit is contained in:
14
app/Http/Controllers/GalleryController.php
Normal file
14
app/Http/Controllers/GalleryController.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class GalleryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Gallery');
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,17 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
|
||||
class RootController extends Controller
|
||||
{
|
||||
// Muestra Login
|
||||
public function index()
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('Auth/Login', [
|
||||
'canResetPassword' => false,
|
||||
'status' => session('status'),
|
||||
]); }
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,44 +2,80 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Song;
|
||||
use App\Policies\SongPolicy;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class SongController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{ use AuthorizesRequests;
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
// render page
|
||||
Inertia::render('Songs/Index', [
|
||||
'songs' => Song::all()
|
||||
return Inertia::render('Songs/Index', [
|
||||
'songs' => Song::where('user_id', auth()->id())->paginate(10),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Store a new song
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
Gate::authorize("create", Song::class);
|
||||
|
||||
}
|
||||
$validated = $request->validate([
|
||||
'song' => 'max:108826630',
|
||||
]);
|
||||
$song = new Song();
|
||||
$song->user_id = auth()->id();
|
||||
|
||||
public function update(Request $request, $id)
|
||||
$file = $request->song;
|
||||
$path = $file->store('songs');
|
||||
$song->title = $file->getClientOriginalName();
|
||||
$song->path = $path;
|
||||
$song->artist = $file->getClientOriginalName();
|
||||
|
||||
$ret = $song->save();
|
||||
|
||||
return response()->json([
|
||||
'data' => $ret ? "Guardado " . $song->title : 'sin archivo'
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function update(Request $request, $id):void
|
||||
{
|
||||
// Update specified song
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
// Delete specified song
|
||||
$this->authorize('delete', Song::class);
|
||||
|
||||
$song = Song::find($id);
|
||||
if ($song) {
|
||||
$song->delete();
|
||||
}
|
||||
}
|
||||
$user = User::find(auth()->id());
|
||||
|
||||
public function stream($id)
|
||||
//Gate::authorize('delete', $user , $song);
|
||||
$this->authorize('delete', $song);
|
||||
|
||||
if ($song) {
|
||||
// Delete the related file
|
||||
if (Storage::exists($song->path)) {
|
||||
Storage::delete($song->path);
|
||||
}
|
||||
Song::destroy($id);
|
||||
}
|
||||
return response()->noContent(200);
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function stream($id):void
|
||||
{
|
||||
// Stream specified song
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user