Feat: Organize videos by sector
This commit is contained in:
@@ -105,16 +105,33 @@ class AuthController extends Controller
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$userId = $user->id;
|
$userId = $user->id;
|
||||||
$role = $user->role_id;
|
$role = $user->role_id;
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
|
||||||
if ($role !== 1) {
|
if ($role !== 1) {
|
||||||
|
$stats = Video::query()
|
||||||
|
->where('is_active', true)
|
||||||
|
->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
})
|
||||||
|
->selectRaw('
|
||||||
|
COUNT(*) as active_count,
|
||||||
|
COUNT(CASE WHEN EXISTS (
|
||||||
|
SELECT 1 FROM video_views
|
||||||
|
WHERE video_views.video_id = videos.id
|
||||||
|
AND video_views.user_id = ?
|
||||||
|
) THEN 1 END) as watched_count
|
||||||
|
', [$userId])
|
||||||
|
->first();
|
||||||
|
} else {
|
||||||
$stats = Video::selectRaw('
|
$stats = Video::selectRaw('
|
||||||
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
||||||
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
||||||
SELECT 1 FROM video_views
|
SELECT 1 FROM video_views
|
||||||
WHERE video_views.video_id = videos.id
|
WHERE video_views.video_id = videos.id
|
||||||
AND video_views.user_id = ?
|
AND video_views.user_id = ?
|
||||||
) THEN 1 END) as watched_count
|
) THEN 1 END) as watched_count
|
||||||
', [$userId])
|
', [$userId])
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,17 @@ class DashboardController extends Controller
|
|||||||
|
|
||||||
$userId = $user->id;
|
$userId = $user->id;
|
||||||
$role = $user->role_id;
|
$role = $user->role_id;
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
|
||||||
$videos = Video::select('id', 'title', 'thumbnail', 'is_active', 'order')
|
$videos = Video::select('id', 'title', 'thumbnail', 'is_active', 'order')
|
||||||
->where('is_active', true)
|
->where('is_active', true)
|
||||||
->whereDoesntHave('views', function ($q) use ($user) {
|
->whereDoesntHave('views', function ($q) use ($user) {
|
||||||
$q->where('user_id', $user->id);
|
$q->where('user_id', $user->id);
|
||||||
})
|
})
|
||||||
|
->when($role !== 1, fn($q) => $q->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
}))
|
||||||
->orderBy('order', 'asc')
|
->orderBy('order', 'asc')
|
||||||
->limit(3)
|
->limit(3)
|
||||||
->get()
|
->get()
|
||||||
@@ -41,19 +46,33 @@ class DashboardController extends Controller
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($role === 1) {
|
if ($role !== 1) {
|
||||||
$stats = Video::selectRaw('COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count')->first();
|
$stats = Video::query()
|
||||||
} else {
|
->where('is_active', true)
|
||||||
$stats = Video::selectRaw('
|
->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
$s->where('sectors.id', $userSector)
|
||||||
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
->orWhere('sectors.slug', "global");
|
||||||
SELECT 1 FROM video_views
|
})
|
||||||
WHERE video_views.video_id = videos.id
|
->selectRaw('
|
||||||
AND video_views.user_id = ?
|
COUNT(*) as active_count,
|
||||||
) THEN 1 END) as watched_count
|
COUNT(CASE WHEN EXISTS (
|
||||||
', [$userId])
|
SELECT 1 FROM video_views
|
||||||
->first();
|
WHERE video_views.video_id = videos.id
|
||||||
}
|
AND video_views.user_id = ?
|
||||||
|
) THEN 1 END) as watched_count
|
||||||
|
', [$userId])
|
||||||
|
->first();
|
||||||
|
} else {
|
||||||
|
$stats = Video::selectRaw('
|
||||||
|
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
||||||
|
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
||||||
|
SELECT 1 FROM video_views
|
||||||
|
WHERE video_views.video_id = videos.id
|
||||||
|
AND video_views.user_id = ?
|
||||||
|
) THEN 1 END) as watched_count
|
||||||
|
', [$userId])
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
$workshops = Workshop::select(['id', 'title', 'image', 'date', 'time_start', 'time_end', 'status'])
|
$workshops = Workshop::select(['id', 'title', 'image', 'date', 'time_start', 'time_end', 'status'])
|
||||||
->with(['users:id'])
|
->with(['users:id'])
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Sector;
|
||||||
|
use App\Http\Requests\CreateSectorRequest;
|
||||||
|
|
||||||
|
class SectorController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$sectors = Sector::select('id', 'name', 'slug', 'is_active')->get();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Setores obtidos com sucesso',
|
||||||
|
'data' => $sectors,
|
||||||
|
'errors' => null,
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(CreateSectorRequest $request)
|
||||||
|
{
|
||||||
|
$sector = Sector::create($request->validated());
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Setor criado com sucesso',
|
||||||
|
'data' => $sector,
|
||||||
|
'errors' => null,
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -74,12 +74,27 @@ class UserController extends Controller
|
|||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sectorName = $user->sector?->name;
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
$role = $user->role_id;
|
||||||
|
|
||||||
$videosWatched = Video::select('id')
|
$videosWatched = Video::select('id')
|
||||||
->whereHas('views', function ($query) use ($user) {
|
->whereHas('views', function ($query) use ($user) {
|
||||||
$query->where('user_id', $user->id);
|
$query->where('user_id', $user->id);
|
||||||
})->count();
|
})
|
||||||
|
->when($role !== 1, fn($q) => $q->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
}))
|
||||||
|
->count();
|
||||||
|
|
||||||
$videosCount = Video::select('id')->where('is_active', true)->count();
|
$videosCount = Video::select('id')
|
||||||
|
->when($role !== 1, fn($q) => $q->where('is_active', true))
|
||||||
|
->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
})
|
||||||
|
->count();
|
||||||
|
|
||||||
$workshopsCount = Workshop::select('id')->where('status', 'pending')->count();
|
$workshopsCount = Workshop::select('id')->where('status', 'pending')->count();
|
||||||
|
|
||||||
@@ -98,6 +113,7 @@ class UserController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Utilizador obtido com sucesso',
|
'message' => 'Utilizador obtido com sucesso',
|
||||||
'data' => $user,
|
'data' => $user,
|
||||||
|
'sectorName' => $sectorName,
|
||||||
'errors' => null,
|
'errors' => null,
|
||||||
'videosWatched' => $videosWatched,
|
'videosWatched' => $videosWatched,
|
||||||
'videosCount' => $videosCount,
|
'videosCount' => $videosCount,
|
||||||
@@ -122,6 +138,7 @@ class UserController extends Controller
|
|||||||
|
|
||||||
$role = $user->role_id;
|
$role = $user->role_id;
|
||||||
$userId = $user->id;
|
$userId = $user->id;
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
|
||||||
if ($role === 1) {
|
if ($role === 1) {
|
||||||
$nextWorkshops = Workshop::select('id', 'title', 'image', 'date', 'time_start', 'time_end', 'status')->where('status', 'pending')->orderBy('date', 'asc')->orderBy('time_start', 'asc')->limit(3)->get();
|
$nextWorkshops = Workshop::select('id', 'title', 'image', 'date', 'time_start', 'time_end', 'status')->where('status', 'pending')->orderBy('date', 'asc')->orderBy('time_start', 'asc')->limit(3)->get();
|
||||||
@@ -144,6 +161,10 @@ class UserController extends Controller
|
|||||||
->whereDoesntHave('views', function ($q) use ($user) {
|
->whereDoesntHave('views', function ($q) use ($user) {
|
||||||
$q->where('user_id', $user->id);
|
$q->where('user_id', $user->id);
|
||||||
})
|
})
|
||||||
|
->when($role !== 1, fn($q) => $q->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
}))
|
||||||
->orderBy('order', 'asc')
|
->orderBy('order', 'asc')
|
||||||
->limit(3)
|
->limit(3)
|
||||||
->get()
|
->get()
|
||||||
@@ -157,20 +178,26 @@ class UserController extends Controller
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
$videosCount = Video::select('id')->where('is_active', true)->count();
|
$videosCount = Video::select('id')->where('is_active', true)->when($role !== 1, fn($q) => $q->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
}))->count();
|
||||||
|
|
||||||
$videosWatched = Video::select('id')
|
$videosWatched = Video::select('id')
|
||||||
->where('is_active', true)
|
->where('is_active', true)
|
||||||
->whereHas('views', function ($query) use ($user) {
|
->whereHas('views', function ($query) use ($user) {
|
||||||
$query->where('user_id', $user->id);
|
$query->where('user_id', $user->id);
|
||||||
})->count();
|
})->when($role !== 1, fn($q) => $q->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
}))->count();
|
||||||
|
|
||||||
$workshopsInscribed = Workshop::select('id', 'title', 'image', 'date', 'time_start', 'time_end', 'status')->with('users:id')->where('status', 'pending')->whereHas('users', function ($query) use ($user) {
|
$workshopsInscribed = Workshop::select('id', 'title', 'image', 'date', 'time_start', 'time_end', 'status')->with('users:id')->where('status', 'pending')->whereHas('users', function ($query) use ($user) {
|
||||||
$query->where('users.id', $user->id);
|
$query->where('users.id', $user->id);
|
||||||
})
|
})
|
||||||
->orderBy('date', 'asc')
|
->orderBy('date', 'asc')
|
||||||
->orderBy('time_start', 'asc')
|
->orderBy('time_start', 'asc')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$workshopsCount = Workshop::select('id')->where('status', 'pending')->count();
|
$workshopsCount = Workshop::select('id')->where('status', 'pending')->count();
|
||||||
}
|
}
|
||||||
@@ -200,6 +227,7 @@ class UserController extends Controller
|
|||||||
'email' => $validated['email'],
|
'email' => $validated['email'],
|
||||||
'password' => Hash::make($validated['password']),
|
'password' => Hash::make($validated['password']),
|
||||||
'role_id' => $validated['role_id'],
|
'role_id' => $validated['role_id'],
|
||||||
|
'sector_id' => $validated['sector_id'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -253,6 +281,7 @@ class UserController extends Controller
|
|||||||
'name' => $request->name ?: $userToUpdate->name,
|
'name' => $request->name ?: $userToUpdate->name,
|
||||||
'email' => $request->email ?: $userToUpdate->email,
|
'email' => $request->email ?: $userToUpdate->email,
|
||||||
'role_id' => $request->role_id ?: $userToUpdate->role_id,
|
'role_id' => $request->role_id ?: $userToUpdate->role_id,
|
||||||
|
'sector_id' => $request->sector_id ?: $userToUpdate->sector_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($request->filled('novaPassword')) {
|
if ($request->filled('novaPassword')) {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class VideosController extends Controller
|
|||||||
|
|
||||||
$userId = $user->id;
|
$userId = $user->id;
|
||||||
$role = $user->role_id;
|
$role = $user->role_id;
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
|
||||||
$search = trim((string) $request->query('search', ''));
|
$search = trim((string) $request->query('search', ''));
|
||||||
$categoryId = $request->query('category');
|
$categoryId = $request->query('category');
|
||||||
@@ -45,9 +46,7 @@ class VideosController extends Controller
|
|||||||
|
|
||||||
$query = Video::select(['id', 'title', 'thumbnail', 'is_active'])
|
$query = Video::select(['id', 'title', 'thumbnail', 'is_active'])
|
||||||
->with('categories:id,name')
|
->with('categories:id,name')
|
||||||
->withCount([
|
->with('sectors:id')
|
||||||
'views as watched' => fn($q) => $q->where('user_id', $userId)
|
|
||||||
])
|
|
||||||
|
|
||||||
->when($search !== '', function ($q) use ($search) {
|
->when($search !== '', function ($q) use ($search) {
|
||||||
$q->where(function ($sub) use ($search) {
|
$q->where(function ($sub) use ($search) {
|
||||||
@@ -64,6 +63,11 @@ class VideosController extends Controller
|
|||||||
|
|
||||||
->when($role !== 1, fn($q) => $q->where('is_active', true))
|
->when($role !== 1, fn($q) => $q->where('is_active', true))
|
||||||
|
|
||||||
|
->when($role !== 1, fn($q) => $q->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
}))
|
||||||
|
|
||||||
->when(
|
->when(
|
||||||
$role === 1 && $status === 'active',
|
$role === 1 && $status === 'active',
|
||||||
fn($q) =>
|
fn($q) =>
|
||||||
@@ -85,25 +89,43 @@ class VideosController extends Controller
|
|||||||
// left join para trazer os vídeos vistos pelo utilizador
|
// left join para trazer os vídeos vistos pelo utilizador
|
||||||
->leftJoin('video_views as vv', function ($join) use ($userId) {
|
->leftJoin('video_views as vv', function ($join) use ($userId) {
|
||||||
$join->on('vv.video_id', '=', 'videos.id')
|
$join->on('vv.video_id', '=', 'videos.id')
|
||||||
->where('vv.user_id', '=', $userId);
|
->where('vv.user_id', '=', $userId);
|
||||||
})
|
})
|
||||||
|
|
||||||
->orderByRaw('CASE WHEN vv.id IS NOT NULL THEN 1 ELSE 0 END ASC')
|
->orderByRaw('CASE WHEN vv.id IS NOT NULL THEN 1 ELSE 0 END ASC')
|
||||||
->orderBy('videos.order', 'ASC')
|
->orderBy('videos.order', 'ASC')
|
||||||
->select(['videos.id', 'videos.title', 'videos.thumbnail', 'videos.is_active'])
|
->select(['videos.id', 'videos.title', 'videos.thumbnail', 'videos.is_active', 'vv.id as user_view_id'])
|
||||||
|
|
||||||
->paginate($perPage);
|
->paginate($perPage);
|
||||||
|
|
||||||
// 1 única query para obter o número de vídeos ativos e vistos
|
// 1 única query para obter o número de vídeos ativos e vistos
|
||||||
$stats = Video::selectRaw('
|
if ($role !== 1) {
|
||||||
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
$stats = Video::query()
|
||||||
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
->where('is_active', true)
|
||||||
SELECT 1 FROM video_views
|
->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
WHERE video_views.video_id = videos.id
|
$s->where('sectors.id', $userSector)
|
||||||
AND video_views.user_id = ?
|
->orWhere('sectors.slug', "global");
|
||||||
) THEN 1 END) as watched_count
|
})
|
||||||
', [$userId])
|
->selectRaw('
|
||||||
->first();
|
COUNT(*) as active_count,
|
||||||
|
COUNT(CASE WHEN EXISTS (
|
||||||
|
SELECT 1 FROM video_views
|
||||||
|
WHERE video_views.video_id = videos.id
|
||||||
|
AND video_views.user_id = ?
|
||||||
|
) THEN 1 END) as watched_count
|
||||||
|
', [$userId])
|
||||||
|
->first();
|
||||||
|
} else {
|
||||||
|
$stats = Video::selectRaw('
|
||||||
|
COUNT(CASE WHEN is_active = 1 THEN 1 END) as active_count,
|
||||||
|
COUNT(CASE WHEN is_active = 1 AND EXISTS (
|
||||||
|
SELECT 1 FROM video_views
|
||||||
|
WHERE video_views.video_id = videos.id
|
||||||
|
AND video_views.user_id = ?
|
||||||
|
) THEN 1 END) as watched_count
|
||||||
|
', [$userId])
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
$query->getCollection()->transform(function ($video) {
|
$query->getCollection()->transform(function ($video) {
|
||||||
return [
|
return [
|
||||||
@@ -112,21 +134,38 @@ class VideosController extends Controller
|
|||||||
'thumbnail' => $video->thumbnail,
|
'thumbnail' => $video->thumbnail,
|
||||||
'is_active' => $video->is_active,
|
'is_active' => $video->is_active,
|
||||||
'categories' => $video->categories,
|
'categories' => $video->categories,
|
||||||
'watched' => $video->views->isNotEmpty(),
|
'watched' => $video->user_view_id !== null,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Guarda as categorias em cache durante 1 minuto para evitar consultas repetidas
|
// Guarda as categorias em cache durante 1 minuto para evitar consultas repetidas
|
||||||
$categories = cache()->remember(
|
if ($role !== 1) {
|
||||||
'active_categories_with_videos',
|
$categories = cache()->remember(
|
||||||
60,
|
'active_categories_with_videos',
|
||||||
fn() =>
|
60,
|
||||||
Category::select('id', 'name')
|
fn() =>
|
||||||
->where('is_active', true)
|
Category::select('id', 'name')
|
||||||
->whereHas('videos')
|
->where('is_active', true)
|
||||||
->orderBy('name')
|
->whereHas('videos')
|
||||||
->get()
|
->whereHas('videos.sectors', function ($s) use ($userSector) {
|
||||||
);
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
})
|
||||||
|
->orderBy('name')
|
||||||
|
->get()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$categories = cache()->remember(
|
||||||
|
'active_categories_with_videos_admin',
|
||||||
|
60,
|
||||||
|
fn() =>
|
||||||
|
Category::select('id', 'name')
|
||||||
|
->where('is_active', true)
|
||||||
|
->whereHas('videos')
|
||||||
|
->orderBy('name')
|
||||||
|
->get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Vídeos obtidos com sucesso',
|
'message' => 'Vídeos obtidos com sucesso',
|
||||||
@@ -148,6 +187,7 @@ class VideosController extends Controller
|
|||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
|
||||||
$search = trim((string) $request->query('search', ''));
|
$search = trim((string) $request->query('search', ''));
|
||||||
|
|
||||||
@@ -159,8 +199,12 @@ class VideosController extends Controller
|
|||||||
->where('user_id', $user->id);
|
->where('user_id', $user->id);
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
->when($user->role_id !== 1, function ($query) {
|
->when($user->role_id !== 1, function ($query) use ($userSector) {
|
||||||
$query->where('is_active', true);
|
$query->where('is_active', true)
|
||||||
|
->whereHas('sectors', function ($s) use ($userSector) {
|
||||||
|
$s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global");
|
||||||
|
});
|
||||||
})
|
})
|
||||||
->where(function ($query) use ($search) {
|
->where(function ($query) use ($search) {
|
||||||
$query->where('title', 'like', "%{$search}%")
|
$query->where('title', 'like', "%{$search}%")
|
||||||
@@ -198,67 +242,106 @@ class VideosController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$userID = $user->id;
|
$userID = $user->id;
|
||||||
|
$userSector = $user->sector_id;
|
||||||
|
$isAdmin = $user->role_id === 1;
|
||||||
|
|
||||||
if ($user->role_id !== 1) {
|
$video = Video::with([
|
||||||
/* $video = Video::with('categories')->where('is_active', true)->find($id); */
|
'categories' => function ($query) use ($isAdmin) {
|
||||||
$video = Video::with([
|
if (!$isAdmin) {
|
||||||
'categories' => function ($query) use ($userID) {
|
|
||||||
$query->where('is_active', true);
|
$query->where('is_active', true);
|
||||||
},
|
|
||||||
'views' => function ($query) use ($userID) {
|
|
||||||
$query->where('user_id', $userID);
|
|
||||||
}
|
}
|
||||||
])->find($id);
|
},
|
||||||
|
'sectors',
|
||||||
|
'views' => function ($query) use ($userID) {
|
||||||
|
$query->where('user_id', $userID);
|
||||||
|
},
|
||||||
|
])->find($id);
|
||||||
|
|
||||||
$nextVideo = Video::select('id')->where('order', '>', $video->order)->where('is_active', true)->orderBy('order', 'asc')->first();
|
if (!$video) {
|
||||||
$previousVideo = Video::select('id')->where('order', '<', $video->order)->where('is_active', true)->orderBy('order', 'desc')->first();
|
|
||||||
|
|
||||||
/* Para não mostrar vídeos inactivos para utilizadores não administradores */
|
|
||||||
if (!$video || $video->is_active === false) {
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Acesso negado',
|
|
||||||
'data' => null,
|
|
||||||
'errors' => null,
|
|
||||||
], 404);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$video = Video::with('categories')->find($id);
|
|
||||||
|
|
||||||
if ($video) {
|
|
||||||
$video->url = Storage::url($video->url);
|
|
||||||
$video->thumbnail = Storage::url($video->thumbnail);
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Vídeo obtido com sucesso',
|
|
||||||
'data' => [
|
|
||||||
'id' => $video->id,
|
|
||||||
'title' => $video->title,
|
|
||||||
'description' => $video->description,
|
|
||||||
'url' => $video->url,
|
|
||||||
'thumbnail' => $video->thumbnail,
|
|
||||||
'duration' => $video->duration,
|
|
||||||
'tags' => $video->tags,
|
|
||||||
'order' => $video->order,
|
|
||||||
'categories' => $video->categories->map(function ($category) {
|
|
||||||
return [
|
|
||||||
'id' => $category->id,
|
|
||||||
'name' => $category->name,
|
|
||||||
];
|
|
||||||
})->values(),
|
|
||||||
'is_active' => $video->is_active,
|
|
||||||
'watched' => $video->views->isNotEmpty(),
|
|
||||||
],
|
|
||||||
'errors' => null,
|
|
||||||
'nextVideo' => $nextVideo->id ?? null,
|
|
||||||
'previousVideo' => $previousVideo->id ?? null,
|
|
||||||
], 200);
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Vídeo não encontrado',
|
'message' => 'Vídeo não encontrado',
|
||||||
'data' => null,
|
'data' => null,
|
||||||
'errors' => null,
|
'errors' => null,
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$isAdmin) {
|
||||||
|
if (!$video->is_active) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Acesso negado',
|
||||||
|
'data' => null,
|
||||||
|
'errors' => null,
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$video->sectors->contains(fn ($sector) => $sector->id === $userSector || $sector->slug === 'global')) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Acesso negado',
|
||||||
|
'data' => null,
|
||||||
|
'errors' => null,
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextVideo = Video::select('id')
|
||||||
|
->where('order', '>', $video->order)
|
||||||
|
->where('is_active', true)
|
||||||
|
->whereHas('sectors', fn($s) => $s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global"))
|
||||||
|
->orderBy('order', 'asc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$previousVideo = Video::select('id')
|
||||||
|
->where('order', '<', $video->order)
|
||||||
|
->where('is_active', true)
|
||||||
|
->whereHas('sectors', fn($s) => $s->where('sectors.id', $userSector)
|
||||||
|
->orWhere('sectors.slug', "global"))
|
||||||
|
->orderBy('order', 'desc')
|
||||||
|
->first();
|
||||||
|
} else {
|
||||||
|
$nextVideo = Video::select('id')
|
||||||
|
->where('order', '>', $video->order)
|
||||||
|
->orderBy('order', 'asc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$previousVideo = Video::select('id')
|
||||||
|
->where('order', '<', $video->order)
|
||||||
|
->orderBy('order', 'desc')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
$video->url = Storage::url($video->url);
|
||||||
|
$video->thumbnail = Storage::url($video->thumbnail);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Vídeo obtido com sucesso',
|
||||||
|
'data' => [
|
||||||
|
'id' => $video->id,
|
||||||
|
'title' => $video->title,
|
||||||
|
'description' => $video->description,
|
||||||
|
'url' => $video->url,
|
||||||
|
'thumbnail' => $video->thumbnail,
|
||||||
|
'duration' => $video->duration,
|
||||||
|
'tags' => $video->tags,
|
||||||
|
'order' => $video->order,
|
||||||
|
'categories' => $video->categories->map(function ($category) {
|
||||||
|
return [
|
||||||
|
'id' => $category->id,
|
||||||
|
'name' => $category->name,
|
||||||
|
];
|
||||||
|
})->values(),
|
||||||
|
'sectors' => $video->sectors->map(function ($sector) {
|
||||||
|
return [
|
||||||
|
'id' => $sector->id,
|
||||||
|
'name' => $sector->name,
|
||||||
|
];
|
||||||
|
})->values(),
|
||||||
|
'is_active' => $video->is_active,
|
||||||
|
'watched' => $video->views->isNotEmpty(),
|
||||||
|
],
|
||||||
|
'errors' => null,
|
||||||
|
'nextVideo' => $nextVideo->id ?? null,
|
||||||
|
'previousVideo' => $previousVideo->id ?? null,
|
||||||
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -290,6 +373,7 @@ class VideosController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$video->categories()->sync($request->input('category_ids', []));
|
$video->categories()->sync($request->input('category_ids', []));
|
||||||
|
$video->sectors()->sync($request->input('sector_ids', []));
|
||||||
|
|
||||||
$baseUrl = $request->getSchemeAndHttpHost();
|
$baseUrl = $request->getSchemeAndHttpHost();
|
||||||
|
|
||||||
@@ -305,6 +389,7 @@ class VideosController extends Controller
|
|||||||
'tags' => $video->tags,
|
'tags' => $video->tags,
|
||||||
'order' => $video->order,
|
'order' => $video->order,
|
||||||
'categories' => $video->categories->pluck('name'),
|
'categories' => $video->categories->pluck('name'),
|
||||||
|
'sectors' => $video->sectors->pluck('name'),
|
||||||
'is_active' => $video->is_active,
|
'is_active' => $video->is_active,
|
||||||
],
|
],
|
||||||
'errors' => null,
|
'errors' => null,
|
||||||
@@ -355,10 +440,11 @@ class VideosController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$videoToUpdate->categories()->sync($request->input('category_ids', []));
|
$videoToUpdate->categories()->sync($request->input('category_ids', []));
|
||||||
|
$videoToUpdate->sectors()->sync($request->input('sector_ids', []));
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Dados do vídeo atualizados com sucesso',
|
'message' => 'Dados do vídeo atualizados com sucesso',
|
||||||
'data' => $videoToUpdate->load('categories'),
|
'data' => $videoToUpdate->load(['categories', 'sectors']),
|
||||||
'errors' => null,
|
'errors' => null,
|
||||||
], 200);
|
], 200);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ class JwtMiddleware
|
|||||||
try {
|
try {
|
||||||
JWTAuth::parseToken()->authenticate();
|
JWTAuth::parseToken()->authenticate();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return redirect()->route('login');
|
return response()->json([
|
||||||
|
'message' => 'Utilizador não autenticado',
|
||||||
|
'data' => null,
|
||||||
|
'errors' => null,
|
||||||
|
], 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class CreateSectorRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|string|max:50|unique:sectors,name',
|
||||||
|
'slug' => 'sometimes|string|max:50|unique:sectors,slug',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name.required' => 'O nome do setor é obrigatório',
|
||||||
|
'name.max' => 'O nome do setor deve ter no máximo 50 caracteres',
|
||||||
|
'slug.required' => 'O slug é obrigatório',
|
||||||
|
'slug.max' => 'O slug deve ter no máximo 50 caracteres',
|
||||||
|
'slug.unique' => 'O slug já existe',
|
||||||
|
'name.unique' => 'O setor já existe',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ class CreateUserRequest extends FormRequest
|
|||||||
'email' => 'required|email|unique:users,email',
|
'email' => 'required|email|unique:users,email',
|
||||||
'password' => 'required|string|min:6|confirmed',
|
'password' => 'required|string|min:6|confirmed',
|
||||||
'role_id' => 'required|exists:roles,id',
|
'role_id' => 'required|exists:roles,id',
|
||||||
|
'sector_id' => 'required|exists:sectors,id',
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -44,6 +45,8 @@ class CreateUserRequest extends FormRequest
|
|||||||
'password.required' => 'A password é obrigatória',
|
'password.required' => 'A password é obrigatória',
|
||||||
'password.min' => 'A password deve ter pelo menos 6 caracteres',
|
'password.min' => 'A password deve ter pelo menos 6 caracteres',
|
||||||
'password.confirmed' => 'As passwords não coincidem',
|
'password.confirmed' => 'As passwords não coincidem',
|
||||||
|
'sector_id.required' => 'Obrigatório selecionar um setor',
|
||||||
|
'sector_id.exists' => 'Setor não encontrado',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ class CreateVideoRequest extends FormRequest
|
|||||||
'duration' => 'nullable|string|max:10',
|
'duration' => 'nullable|string|max:10',
|
||||||
'tags' => 'nullable|string|max:255', // nullable para não ser obrigatório
|
'tags' => 'nullable|string|max:255', // nullable para não ser obrigatório
|
||||||
'category_ids' => 'nullable|array|exists:categories,id', // nullable caso não selecione
|
'category_ids' => 'nullable|array|exists:categories,id', // nullable caso não selecione
|
||||||
|
'sector_ids' => 'nullable|array|exists:sectors,id', // nullable caso não selecione
|
||||||
'order' => 'nullable|integer|min:0',
|
'order' => 'nullable|integer|min:0',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class UpdateUserRequest extends FormRequest
|
|||||||
Rule::unique('users', 'email')->ignore($userId),
|
Rule::unique('users', 'email')->ignore($userId),
|
||||||
],
|
],
|
||||||
'role_id' => 'sometimes|exists:roles,id',
|
'role_id' => 'sometimes|exists:roles,id',
|
||||||
|
'sector_id' => 'sometimes|exists:sectors,id',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ class UpdateUserRequest extends FormRequest
|
|||||||
'email.email' => 'O email deve ser um email válido',
|
'email.email' => 'O email deve ser um email válido',
|
||||||
'email.unique' => 'O email já está em uso',
|
'email.unique' => 'O email já está em uso',
|
||||||
'role_id.exists' => 'Cargo não encontrado',
|
'role_id.exists' => 'Cargo não encontrado',
|
||||||
|
'sector_id.exists' => 'Setor não encontrado',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ class UpdateVideoRequest extends FormRequest
|
|||||||
'tags' => 'sometimes|string|max:100',
|
'tags' => 'sometimes|string|max:100',
|
||||||
'category_ids' => 'sometimes|array',
|
'category_ids' => 'sometimes|array',
|
||||||
'category_ids.*' => 'exists:categories,id',
|
'category_ids.*' => 'exists:categories,id',
|
||||||
|
'sector_ids' => 'sometimes|array',
|
||||||
|
'sector_ids.*' => 'exists:sectors,id',
|
||||||
'is_active' => 'sometimes|boolean',
|
'is_active' => 'sometimes|boolean',
|
||||||
'order' => 'sometimes|integer|min:0',
|
'order' => 'sometimes|integer|min:0',
|
||||||
];
|
];
|
||||||
|
|||||||
29
plataforma-tutorias/app/Models/Sector.php
Normal file
29
plataforma-tutorias/app/Models/Sector.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use App\Models\Video;
|
||||||
|
|
||||||
|
class Sector extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'slug',
|
||||||
|
'is_active',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function videos()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Video::class, 'video_sector');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function users()
|
||||||
|
{
|
||||||
|
return $this->hasMany(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||||
|
use App\Models\Sector;
|
||||||
|
|
||||||
class User extends Authenticatable implements JWTSubject
|
class User extends Authenticatable implements JWTSubject
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,7 @@ class User extends Authenticatable implements JWTSubject
|
|||||||
'email',
|
'email',
|
||||||
'password',
|
'password',
|
||||||
'role_id',
|
'role_id',
|
||||||
|
'sector_id',
|
||||||
'created_at',
|
'created_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -47,4 +49,9 @@ class User extends Authenticatable implements JWTSubject
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(Workshop::class, 'user_workshop')->withTimestamps();
|
return $this->belongsToMany(Workshop::class, 'user_workshop')->withTimestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sector()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Sector::class, 'sector_id', 'id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
use App\Models\Sector;
|
||||||
|
|
||||||
class Video extends Model
|
class Video extends Model
|
||||||
{
|
{
|
||||||
@@ -84,4 +85,8 @@ class Video extends Model
|
|||||||
return $this->views()->where('user_id', $user->id)->exists();
|
return $this->views()->where('user_id', $user->id)->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sectors()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Sector::class, 'video_sector');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'ttl' => env('JWT_TTL', 15),
|
'ttl' => env('JWT_TTL', 1),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -120,7 +120,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'refresh_ttl' => env('JWT_REFRESH_TTL', 20160),
|
'refresh_ttl' => env('JWT_REFRESH_TTL', 1),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -11,13 +11,12 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::create('refresh_tokens', function (Blueprint $table) {
|
Schema::create('sectors', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('user_id')->constrained('users');
|
$table->string('name');
|
||||||
$table->string('token_hash');
|
$table->string('slug');
|
||||||
$table->dateTime('revoked_at')->nullable();
|
|
||||||
$table->dateTime('expires_at');
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
$table->boolean('is_active')->default(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +25,6 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('refresh_tokens');
|
Schema::dropIfExists('sectors');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->foreignId('sector_id')->nullable()->constrained('sectors');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['sector_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('video_sector', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('video_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('sector_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('video_sector');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -17,6 +17,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
$this->call([
|
$this->call([
|
||||||
RoleSeeder::class,
|
RoleSeeder::class,
|
||||||
UserSeeder::class,
|
UserSeeder::class,
|
||||||
|
SectorsTableSeeder::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
plataforma-tutorias/database/seeders/SectorsTableSeeder.php
Normal file
24
plataforma-tutorias/database/seeders/SectorsTableSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class SectorsTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
DB::table('sectors')->insert([
|
||||||
|
'name' => 'Global',
|
||||||
|
'slug' => 'global',
|
||||||
|
'is_active' => true,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ use App\Http\Controllers\WorkshopsController;
|
|||||||
use App\Http\Middleware\JwtMiddleware;
|
use App\Http\Middleware\JwtMiddleware;
|
||||||
use App\Http\Controllers\VideoViewController;
|
use App\Http\Controllers\VideoViewController;
|
||||||
use App\Http\Controllers\DashboardController;
|
use App\Http\Controllers\DashboardController;
|
||||||
|
use App\Http\Controllers\SectorController;
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| API Routes
|
| API Routes
|
||||||
@@ -40,6 +41,10 @@ Route::middleware([JwtMiddleware::class])->group(function () {
|
|||||||
Route::get('/next-videos', [VideosController::class, 'nextVideos']);
|
Route::get('/next-videos', [VideosController::class, 'nextVideos']);
|
||||||
|
|
||||||
Route::get('/categories', [CategoryController::class, 'index']);
|
Route::get('/categories', [CategoryController::class, 'index']);
|
||||||
|
Route::post('/categories', [CategoryController::class, 'create']);
|
||||||
|
|
||||||
|
Route::get('/sectors', [SectorController::class, 'index']);
|
||||||
|
Route::post('/sectors', [SectorController::class, 'create']);
|
||||||
|
|
||||||
Route::get('/workshops', [WorkshopsController::class, 'index']);
|
Route::get('/workshops', [WorkshopsController::class, 'index']);
|
||||||
Route::get('/workshop/{id}', [WorkshopsController::class, 'getWorkshop']);
|
Route::get('/workshop/{id}', [WorkshopsController::class, 'getWorkshop']);
|
||||||
@@ -47,7 +52,6 @@ Route::middleware([JwtMiddleware::class])->group(function () {
|
|||||||
Route::get('/workshops-search', [WorkshopsController::class, 'search']);
|
Route::get('/workshops-search', [WorkshopsController::class, 'search']);
|
||||||
Route::get('/next-workshops', [WorkshopsController::class, 'nextWorkshops']);
|
Route::get('/next-workshops', [WorkshopsController::class, 'nextWorkshops']);
|
||||||
|
|
||||||
Route::post('/categories', [CategoryController::class, 'create']);
|
|
||||||
|
|
||||||
Route::post('/inscrever/{id}', [WorkshopsController::class, 'inscrever']);
|
Route::post('/inscrever/{id}', [WorkshopsController::class, 'inscrever']);
|
||||||
Route::delete('/cancelar-inscricao/{id}', [WorkshopsController::class, 'cancelarInscricao']);
|
Route::delete('/cancelar-inscricao/{id}', [WorkshopsController::class, 'cancelarInscricao']);
|
||||||
|
|||||||
Reference in New Issue
Block a user