feat: paginate workshops and videos pages
This commit is contained in:
26
plataforma-tutorias/.gitattributes
vendored
26
plataforma-tutorias/.gitattributes
vendored
@@ -1,11 +1,27 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
# Diffs
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
*.ts diff=typescript
|
||||
*.tsx diff=typescript
|
||||
|
||||
/.github export-ignore
|
||||
# Exports
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
||||
# Binary files - no conversion
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.gif binary
|
||||
*.ico binary
|
||||
*.svg binary
|
||||
*.woff binary
|
||||
*.woff2 binary
|
||||
*.ttf binary
|
||||
*.eot binary
|
||||
@@ -108,8 +108,6 @@ class AuthController extends Controller
|
||||
'message' => 'Utilizador obtido com sucesso',
|
||||
'data' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'role_id' => $user->role_id,
|
||||
],
|
||||
'errors' => null,
|
||||
|
||||
@@ -10,7 +10,7 @@ class CategoryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$categories = Category::all();
|
||||
$categories = Category::select('id', 'name', 'is_active')->orderBy('name', 'asc')->get();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Categorias obtidas com sucesso',
|
||||
@@ -21,7 +21,7 @@ class CategoryController extends Controller
|
||||
|
||||
public function create(CreateCategoryRequest $request)
|
||||
{
|
||||
$category = Category::create($request->all());
|
||||
$category = Category::create($request->validated());
|
||||
return response()->json([
|
||||
'message' => 'Categoria criada com sucesso',
|
||||
'data' => $category,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Video;
|
||||
use App\Models\VideoView;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class VideoViewController extends Controller
|
||||
{
|
||||
public function store(Video $video) {
|
||||
$user = auth()->user();
|
||||
|
||||
//firstOrCreate só cria se não existir, se existir, atualiza o watched_at
|
||||
VideoView::firstOrCreate([
|
||||
'user_id' => $user->id,
|
||||
'video_id' => $video->id,
|
||||
], [
|
||||
'watched_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['watched' => true]);
|
||||
}
|
||||
}
|
||||
@@ -25,42 +25,196 @@ class VideosController extends Controller
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'message' => 'Utilizador não autenticado',
|
||||
'data' => null,
|
||||
'errors' => null,
|
||||
], 404);
|
||||
], 401);
|
||||
}
|
||||
|
||||
|
||||
$search = trim((string) $request->query('search', ''));
|
||||
$videosQuery = Video::with('categories');
|
||||
$categoryId = $request->query('category');
|
||||
$watched = $request->query('watched');
|
||||
$perPage = $request->query('per_page', 9);
|
||||
|
||||
$query = Video::select(['id', 'title', 'thumbnail', 'is_active'])
|
||||
->with([
|
||||
'categories:id,name',
|
||||
'views' => function ($q) use ($user) {
|
||||
$q->select('id', 'video_id', 'user_id')
|
||||
->where('user_id', $user->id);
|
||||
}
|
||||
])
|
||||
|
||||
->when($search !== '', function ($q) use ($search) {
|
||||
$q->where(function ($sub) use ($search) {
|
||||
$sub->where('title', 'like', "%{$search}%")
|
||||
->orWhere('tags', 'like', "%{$search}%");
|
||||
});
|
||||
})
|
||||
|
||||
->when($categoryId, function ($q) use ($categoryId) {
|
||||
$q->whereHas('categories', function ($c) use ($categoryId) {
|
||||
$c->where('categories.id', $categoryId);
|
||||
});
|
||||
})
|
||||
|
||||
->when($user->role_id !== 1, function ($q) {
|
||||
$q->where('is_active', true);
|
||||
})
|
||||
|
||||
->when($watched !== null, function ($q) use ($watched, $user) {
|
||||
|
||||
if ((int) $watched === 1) {
|
||||
$q->whereHas('views', function ($v) use ($user) {
|
||||
$v->where('user_id', $user->id);
|
||||
});
|
||||
}
|
||||
|
||||
if ((int) $watched === 0) {
|
||||
$q->whereDoesntHave('views', function ($v) use ($user) {
|
||||
$v->where('user_id', $user->id);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
->orderByRaw('
|
||||
CASE WHEN EXISTS (
|
||||
SELECT 1 FROM video_views
|
||||
WHERE video_views.video_id = videos.id
|
||||
AND video_views.user_id = ?
|
||||
) THEN 1 ELSE 0 END ASC,
|
||||
videos.order ASC
|
||||
', [$user->id])
|
||||
->paginate($perPage);
|
||||
|
||||
$query->getCollection()->transform(function ($video) {
|
||||
return [
|
||||
'id' => $video->id,
|
||||
'title' => $video->title,
|
||||
'thumbnail' => $video->thumbnail,
|
||||
'is_active' => $video->is_active,
|
||||
'categories' => $video->categories,
|
||||
'watched' => $video->views->isNotEmpty(),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Vídeos obtidos com sucesso',
|
||||
'data' => $query->items(),
|
||||
'meta' => [
|
||||
'current_page' => $query->currentPage(),
|
||||
'last_page' => $query->lastPage(),
|
||||
'per_page' => $query->perPage(),
|
||||
'total' => $query->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($search !== '') {
|
||||
$videosQuery->where(function ($query) use ($search) {
|
||||
$query->where('title', 'like', "%{$search}%")
|
||||
->orWhere('tags', 'like', "%{$search}%");
|
||||
});
|
||||
public function nextVideos()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'message' => 'Não autenticado',
|
||||
], 401);
|
||||
}
|
||||
|
||||
$videos = Video::select(['id', 'title', 'thumbnail', 'is_active', 'order'])
|
||||
->with(['categories:id,name'])
|
||||
|
||||
// 👇 regra base: vídeos não vistos
|
||||
->whereDoesntHave('views', function ($q) use ($user) {
|
||||
$q->where('user_id', $user->id);
|
||||
})
|
||||
|
||||
// 👇 users normais não veem inativos
|
||||
->when($user->role_id !== 1, function ($q) {
|
||||
$q->where('is_active', true);
|
||||
})
|
||||
|
||||
->orderBy('order', 'asc')
|
||||
->limit(3)
|
||||
->get()
|
||||
->map(function ($video) {
|
||||
return [
|
||||
'id' => $video->id,
|
||||
'title' => $video->title,
|
||||
'thumbnail' => $video->thumbnail,
|
||||
'is_active' => $video->is_active,
|
||||
'categories' => $video->categories,
|
||||
'watched' => false, // aqui já sabes que não foram vistos
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Dashboard videos',
|
||||
'data' => $videos,
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$search = trim((string) $request->query('search', ''));
|
||||
|
||||
$videos = Video::select(['id', 'title', 'thumbnail', 'is_active'])
|
||||
->with([
|
||||
'categories:id,name',
|
||||
'views' => function ($query) use ($user) {
|
||||
$query->select('id', 'video_id', 'user_id')
|
||||
->where('user_id', $user->id);
|
||||
}
|
||||
])
|
||||
->when($user->role_id !== 1, function ($query) {
|
||||
$query->where('is_active', true);
|
||||
})
|
||||
->where(function ($query) use ($search) {
|
||||
$query->where('title', 'like', "%{$search}%")
|
||||
->orWhere('tags', 'like', "%{$search}%");
|
||||
})
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(function ($video) {
|
||||
return [
|
||||
'id' => $video->id,
|
||||
'title' => $video->title,
|
||||
'thumbnail' => $video->thumbnail,
|
||||
'is_active' => $video->is_active,
|
||||
'categories' => $video->categories,
|
||||
'watched' => $video->views->isNotEmpty(),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Resultados obtidos com sucesso',
|
||||
'data' => $videos,
|
||||
]);
|
||||
}
|
||||
|
||||
public function videosLength()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$userID = $user->id;
|
||||
|
||||
if ($user->role_id !== 1) {
|
||||
$videosQuery->where('is_active', true);
|
||||
}
|
||||
|
||||
$videos = $videosQuery->get();
|
||||
|
||||
if ($videos->isEmpty()) {
|
||||
return response()->json([
|
||||
'message' => $search !== '' ? 'Sem resultados para a pesquisa' : 'Não foram encontrados vídeos',
|
||||
'data' => [],
|
||||
'errors' => null,
|
||||
], $search !== '' ? 200 : 404); // 200 se for pesquisa, 404 se for listagem normal
|
||||
$videos = Video::select('id')->with('views')->where('is_active', true)->count();
|
||||
$videosWatched = Video::with('views')->where('is_active', true)->whereHas('views', function ($query) use ($userID) {
|
||||
$query->where('user_id', $userID);
|
||||
})->count();
|
||||
} else {
|
||||
$videos = Video::select('id')->with('views')->where('is_active', true)->count();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Vídeos obtidos com sucesso',
|
||||
'data' => $videos,
|
||||
'message' => 'Vídeos ativos obtidos com sucesso',
|
||||
'data' => [
|
||||
'videos' => $videos,
|
||||
'videosWatched' => $videosWatched ?? 0,
|
||||
],
|
||||
'errors' => null,
|
||||
], 200);
|
||||
}
|
||||
@@ -77,8 +231,18 @@ class VideosController extends Controller
|
||||
], 404);
|
||||
}
|
||||
|
||||
$userID = $user->id;
|
||||
|
||||
if ($user->role_id !== 1) {
|
||||
$video = Video::with('categories')->where('is_active', true)->find($id);
|
||||
/* $video = Video::with('categories')->where('is_active', true)->find($id); */
|
||||
$video = Video::with([
|
||||
'categories' => function ($query) use ($userID) {
|
||||
$query->where('is_active', true);
|
||||
},
|
||||
'views' => function ($query) use ($userID) {
|
||||
$query->where('user_id', $userID);
|
||||
}
|
||||
])->find($id);
|
||||
|
||||
/* Para não mostrar vídeos inactivos para utilizadores não administradores */
|
||||
if (!$video || $video->is_active === false) {
|
||||
@@ -106,6 +270,7 @@ class VideosController extends Controller
|
||||
'thumbnail' => $video->thumbnail,
|
||||
'duration' => $video->duration,
|
||||
'tags' => $video->tags,
|
||||
'order' => $video->order,
|
||||
'categories' => $video->categories->map(function ($category) {
|
||||
return [
|
||||
'id' => $category->id,
|
||||
@@ -113,6 +278,7 @@ class VideosController extends Controller
|
||||
];
|
||||
})->values(),
|
||||
'is_active' => $video->is_active,
|
||||
'watched' => $video->views->isNotEmpty(),
|
||||
],
|
||||
'errors' => null,
|
||||
], 200);
|
||||
@@ -150,6 +316,7 @@ class VideosController extends Controller
|
||||
'thumbnail' => $thumbnailPath,
|
||||
'duration' => $validated['duration'] ?? '00:00',
|
||||
'tags' => $validated['tags'],
|
||||
'order' => $validated['order'],
|
||||
]);
|
||||
|
||||
if ($request->filled('category_ids')) {
|
||||
@@ -159,7 +326,7 @@ class VideosController extends Controller
|
||||
$baseUrl = $request->getSchemeAndHttpHost();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Vídeo criado com sucesso',
|
||||
'message' => 'Vídeo adicionado com sucesso',
|
||||
'data' => [
|
||||
'id' => $video->id,
|
||||
'title' => $video->title,
|
||||
@@ -168,6 +335,7 @@ class VideosController extends Controller
|
||||
'thumbnail' => $baseUrl . Storage::url($video->thumbnail),
|
||||
'duration' => $video->duration,
|
||||
'tags' => $video->tags,
|
||||
'order' => $video->order,
|
||||
'categories' => $video->categories->pluck('name'),
|
||||
'is_active' => $video->is_active,
|
||||
],
|
||||
@@ -215,6 +383,7 @@ class VideosController extends Controller
|
||||
'tags' => $validated['tags'] ?? $videoToUpdate->tags,
|
||||
'thumbnail' => $validated['thumbnail'] ?? $videoToUpdate->thumbnail,
|
||||
'is_active' => array_key_exists('is_active', $validated) ? $validated['is_active'] : $videoToUpdate->is_active,
|
||||
'order' => $validated['order'] ?? $videoToUpdate->order,
|
||||
]);
|
||||
|
||||
if ($request->has('category_ids')) {
|
||||
|
||||
@@ -24,49 +24,153 @@ class WorkshopsController extends Controller
|
||||
|
||||
$search = trim((string) $request->query('search', ''));
|
||||
$status = trim((string) $request->query('status', ''));
|
||||
$workshopsQuery = Workshop::with('users');
|
||||
|
||||
if ($search !== '') {
|
||||
$workshopsQuery->where('title', 'like', "%{$search}%")->where('status', 'pending');
|
||||
}
|
||||
|
||||
if ($user->role_id !== 1) {
|
||||
$workshopsQuery->where(function ($query) use ($user) {
|
||||
$query->where('status', 'pending')
|
||||
->orWhere(function ($q) use ($user) {
|
||||
$q->whereIn('status', ['pending'])
|
||||
->whereHas('users', function ($q2) use ($user) {
|
||||
$q2->where('users.id', $user->id);
|
||||
});
|
||||
})
|
||||
->orWhere(function ($q) use ($user) {
|
||||
$q->whereIn('status', ['realized', 'canceled'])
|
||||
->whereHas('users', function ($q2) use ($user) {
|
||||
$q2->where('users.id', $user->id);
|
||||
});
|
||||
});
|
||||
$perPage = $request->query('per_page', 9);
|
||||
$query = Workshop::select('id', 'title', 'image', 'date', 'time_start', 'time_end', 'status')->with('users:id')
|
||||
->when($search !== '', function ($q) use ($search) {
|
||||
$q->where('title', 'like', "%{$search}%");
|
||||
})
|
||||
->when($status !== '' && $status !== 'inscrito', function ($q) use ($status) {
|
||||
$q->where('status', $status);
|
||||
})
|
||||
->when($status === 'inscrito', function ($q) use ($user) {
|
||||
$q->where('status', 'pending')
|
||||
->whereHas('users', function ($q2) use ($user) {
|
||||
$q2->where('users.id', $user->id);
|
||||
});
|
||||
}
|
||||
})
|
||||
->when($user->role_id !== 1, function ($q) use ($user, $status) {
|
||||
if($status === 'pending'){
|
||||
|
||||
$workshops = $workshopsQuery->orderBy('date', 'asc')->orderBy('time_start', 'asc')->get();
|
||||
} else {
|
||||
$q->whereHas('users', function ($q2) use ($user) {
|
||||
$q2->where('users.id', $user->id);
|
||||
});
|
||||
};
|
||||
})
|
||||
->orderBy('date', 'asc')
|
||||
->orderBy('time_start', 'asc')
|
||||
->paginate($perPage);
|
||||
|
||||
/* Os workshops são atualizados automaticamente pelo command (app->Console->Commands->UpdateWorkshopStatus.php) 'workshops:update-status' de pending para realized se for uma data passada */
|
||||
|
||||
if($workshops->isEmpty()) {
|
||||
return response()->json([
|
||||
'message' => $search !== '' ? 'Sem resultados para a pesquisa' : 'Não foram encontrados vídeos',
|
||||
'data' => [],
|
||||
'errors' => null,
|
||||
], $search !== '' ? 200 : 404); // 200 se for pesquisa, 404 se for listagem normal
|
||||
}
|
||||
$query->getCollection()->transform(function ($workshop) {
|
||||
return [
|
||||
'id' => $workshop->id,
|
||||
'title' => $workshop->title,
|
||||
'image' => $workshop->image,
|
||||
'date' => $workshop->date,
|
||||
'time_start' => $workshop->time_start,
|
||||
'time_end' => $workshop->time_end,
|
||||
'status' => $workshop->status,
|
||||
'users' => $workshop->users,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Workshops obtidos com sucesso',
|
||||
'data' => $query->items(),
|
||||
'meta' => [
|
||||
'current_page' => $query->currentPage(),
|
||||
'last_page' => $query->lastPage(),
|
||||
'per_page' => $query->perPage(),
|
||||
'total' => $query->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$search = trim((string) $request->query('search', ''));
|
||||
|
||||
$workshops = Workshop::select(['id', 'title', 'image', 'date', 'time_start', 'time_end', 'status'])
|
||||
->when($user->role_id !== 1, function ($query) {
|
||||
$query->where('status', 'pending');
|
||||
})
|
||||
->where(function ($query) use ($search) {
|
||||
$query->where('title', 'like', "%{$search}%");
|
||||
})
|
||||
->orderBy('date', 'asc')
|
||||
->orderBy('time_start', 'asc')
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(function ($workshop) {
|
||||
return [
|
||||
'id' => $workshop->id,
|
||||
'title' => $workshop->title,
|
||||
'image' => $workshop->image,
|
||||
'date' => $workshop->date,
|
||||
'time_start' => $workshop->time_start,
|
||||
'time_end' => $workshop->time_end,
|
||||
'status' => $workshop->status,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Resultados obtidos com sucesso',
|
||||
'data' => $workshops,
|
||||
]);
|
||||
}
|
||||
|
||||
public function workshopsLength()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$userID = $user->id;
|
||||
|
||||
if ($user->role_id !== 1) {
|
||||
$workshops = Workshop::select('id')->where('status', 'pending')->count();
|
||||
$workshopsInscribed = Workshop::with('users')->where('status', 'pending')->whereHas('users', function ($query) use ($userID) {
|
||||
$query->where('user_id', $userID);
|
||||
})->count();
|
||||
} else {
|
||||
$workshops = Workshop::select('id')->where('status', 'pending')->count();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Vídeos ativos obtidos com sucesso',
|
||||
'data' => [
|
||||
'workshops' => $workshops,
|
||||
'workshopsInscribed' => $workshopsInscribed ?? 0,
|
||||
],
|
||||
'errors' => null,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function nextWorkshops()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'message' => 'Não autenticado',
|
||||
], 401);
|
||||
}
|
||||
|
||||
$workshops = Workshop::select(['id', 'title', 'image', 'date', 'time_start', 'time_end', 'status'])
|
||||
->with(['users:id'])
|
||||
->where('status', 'pending')
|
||||
->orderBy('date', 'asc')
|
||||
->orderBy('time_start', 'asc')
|
||||
->limit(3)
|
||||
->get()
|
||||
->map(function ($workshop) {
|
||||
return [
|
||||
'id' => $workshop->id,
|
||||
'title' => $workshop->title,
|
||||
'image' => $workshop->image,
|
||||
'date' => $workshop->date,
|
||||
'time_start' => $workshop->time_start,
|
||||
'time_end' => $workshop->time_end,
|
||||
'status' => $workshop->status,
|
||||
'users' => $workshop->users->pluck('id'),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Dashboard workshops',
|
||||
'data' => $workshops,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getWorkshop($id)
|
||||
{
|
||||
$workshop = Workshop::with('users')->find($id);
|
||||
@@ -98,10 +202,9 @@ class WorkshopsController extends Controller
|
||||
}
|
||||
|
||||
$validated = $request->validated();
|
||||
try {
|
||||
|
||||
$imagePath = $request->file('image')->store('imageWorkshops', 'public');
|
||||
|
||||
try {
|
||||
$workshop = Workshop::create([
|
||||
'title' => $validated['title'],
|
||||
'description' => $validated['description'],
|
||||
|
||||
@@ -19,6 +19,16 @@ class CreateVideoRequest extends FormRequest
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('order')) {
|
||||
$this->merge([
|
||||
'order' => (int) $this->order
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
@@ -29,6 +39,7 @@ class CreateVideoRequest extends FormRequest
|
||||
'duration' => 'nullable|string|max:10',
|
||||
'tags' => 'nullable|string|max:255', // nullable para não ser obrigatório
|
||||
'category_ids' => 'nullable|array|exists:categories,id', // nullable caso não selecione
|
||||
'order' => 'nullable|integer|min:0',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,6 +58,8 @@ class CreateVideoRequest extends FormRequest
|
||||
'thumbnail.max' => 'A thumbnail deve ter no máximo 4MB',
|
||||
'tags.max' => 'As tags devem ter no máximo 50 caracteres',
|
||||
'category_id.exists' => 'A categoria não existe',
|
||||
'order.integer' => 'O ordem deve ser um número inteiro',
|
||||
'order.min' => 'A ordem deve ser maior ou igual a 0',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CreateWorkshopRequest extends FormRequest
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'required|string|max:3000',
|
||||
'image' => 'required|image|mimes:jpg,jpeg,png,webp|max:2048',
|
||||
'image' => 'required|image|mimes:jpg,jpeg,png,webp|max:4000',
|
||||
'date' => 'required|date',
|
||||
'time_start' => 'required|date_format:H:i',
|
||||
'time_end' => 'required|date_format:H:i',
|
||||
@@ -38,7 +38,7 @@ class CreateWorkshopRequest extends FormRequest
|
||||
'title.max' => 'O título deve ter no máximo 255 caracteres',
|
||||
'description.max' => 'A descrição deve ter no máximo 3000 caracteres',
|
||||
'image.mimes' => 'O ficheiro deve ser do formato jpg, jpeg, png ou webp',
|
||||
'image.max' => 'A imagem deve ter no máximo 2MB',
|
||||
'image.max' => 'A imagem deve ter no máximo 4MB',
|
||||
'date.required' => 'A data é obrigatória',
|
||||
'date.date' => 'A data deve ser uma data válida',
|
||||
'time_start.required' => 'A hora de início é obrigatória',
|
||||
|
||||
@@ -19,6 +19,16 @@ class UpdateVideoRequest extends FormRequest
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('order')) {
|
||||
$this->merge([
|
||||
'order' => (int) $this->order
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
@@ -30,6 +40,7 @@ class UpdateVideoRequest extends FormRequest
|
||||
'category_ids' => 'sometimes|array',
|
||||
'category_ids.*' => 'exists:categories,id',
|
||||
'is_active' => 'sometimes|boolean',
|
||||
'order' => 'sometimes|integer|min:0',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,6 +53,8 @@ class UpdateVideoRequest extends FormRequest
|
||||
'thumbnail.mimes' => 'O ficheiro deve ser do formato jpg, jpeg, png ou webp',
|
||||
'thumbnail.max' => 'A thumbnail deve ter no máximo 4MB',
|
||||
'category_id.exists' => 'A categoria não existe',
|
||||
'order.integer' => 'A ordem deve ser um número inteiro',
|
||||
'order.min' => 'A ordem deve ser maior ou igual a 0',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class UpdateWorkshopRequest extends FormRequest
|
||||
return [
|
||||
'title' => 'sometimes|string|max:255',
|
||||
'description' => 'sometimes|string|max:3000',
|
||||
'image' => 'sometimes|image|mimes:jpg,jpeg,png,webp|max:2048',
|
||||
'image' => 'sometimes|image|mimes:jpg,jpeg,png,webp|max:4000',
|
||||
'date' => 'sometimes|date',
|
||||
'time_start' => 'sometimes|date_format:H:i',
|
||||
'time_end' => 'sometimes|date_format:H:i',
|
||||
@@ -39,7 +39,7 @@ class UpdateWorkshopRequest extends FormRequest
|
||||
'title.max' => 'O título deve ter no máximo 255 caracteres',
|
||||
'description.max' => 'A descrição deve ter no máximo 3000 caracteres',
|
||||
'image.mimes' => 'O ficheiro deve ser do formato jpg, jpeg, png ou webp',
|
||||
'image.max' => 'A imagem deve ter no máximo 2MB',
|
||||
'image.max' => 'A imagem deve ter no máximo 4MB',
|
||||
'date.date' => 'A data deve ser uma data válida',
|
||||
'time_start.date_format' => 'A hora de início deve ser uma hora válida',
|
||||
'time_end.date_format' => 'A hora de término deve ser uma hora válida',
|
||||
|
||||
@@ -10,6 +10,8 @@ class Video extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'videos';
|
||||
|
||||
// Campos que podem ser preenchidos
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'description',
|
||||
@@ -18,14 +20,68 @@ class Video extends Model
|
||||
'duration',
|
||||
'tags',
|
||||
'is_active',
|
||||
'order',
|
||||
];
|
||||
|
||||
// Ordem dos vídeos
|
||||
protected static function booted() {
|
||||
static::creating(function ($video) {
|
||||
if(!$video->order){
|
||||
$video->order = static::max('order') + 1;
|
||||
} else {
|
||||
// Se definiu uma ordem já ocupada, empurra os outros
|
||||
static::where('order', '>=', $video->order)
|
||||
->increment('order');
|
||||
}
|
||||
});
|
||||
|
||||
static::updating(function ($video) {
|
||||
if ($video->isDirty('order')) { // ← só age se a ordem foi alterada
|
||||
$oldOrder = $video->getOriginal('order'); // ← ordem antiga
|
||||
$newOrder = $video->order; // ← ordem nova
|
||||
|
||||
// Se a ordem for menor que 1, define como 1
|
||||
if ($newOrder < 1) {
|
||||
$video->order = 1;
|
||||
$newOrder = 1;
|
||||
}
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
// Moveu para baixo — fecha o espaço antigo
|
||||
static::where('order', '>', $oldOrder)
|
||||
->where('order', '<=', $newOrder)
|
||||
->decrement('order');
|
||||
} else {
|
||||
// Moveu para cima — abre espaço na nova posição
|
||||
static::where('order', '>=', $newOrder)
|
||||
->where('order', '<', $oldOrder)
|
||||
->increment('order');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Converte o campo is_active para boolean
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
// Um vídeo pode ter várias categorias
|
||||
public function categories()
|
||||
{
|
||||
return $this->belongsToMany(Category::class, 'video_category');
|
||||
}
|
||||
|
||||
// Um vídeo pode ter várias visualizações
|
||||
public function views()
|
||||
{
|
||||
return $this->hasMany(VideoView::class);
|
||||
}
|
||||
|
||||
// Verifica se um vídeo foi assistido por um utilizador
|
||||
public function isWatchedBy(User $user): bool
|
||||
{
|
||||
return $this->views()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
11
plataforma-tutorias/app/Models/VideoView.php
Normal file
11
plataforma-tutorias/app/Models/VideoView.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VideoView extends Model
|
||||
{
|
||||
protected $fillable = ['user_id', 'video_id', 'watched_at'];
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Telescope\IncomingEntry;
|
||||
use Laravel\Telescope\Telescope;
|
||||
use Laravel\Telescope\TelescopeApplicationServiceProvider;
|
||||
|
||||
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
// Telescope::night();
|
||||
|
||||
$this->hideSensitiveRequestDetails();
|
||||
|
||||
$isLocal = $this->app->environment('local');
|
||||
|
||||
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
|
||||
return $isLocal ||
|
||||
$entry->isReportableException() ||
|
||||
$entry->isFailedRequest() ||
|
||||
$entry->isFailedJob() ||
|
||||
$entry->isScheduledTask() ||
|
||||
$entry->hasMonitoredTag();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent sensitive request details from being logged by Telescope.
|
||||
*/
|
||||
protected function hideSensitiveRequestDetails(): void
|
||||
{
|
||||
if ($this->app->environment('local')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Telescope::hideRequestParameters(['_token']);
|
||||
|
||||
Telescope::hideRequestHeaders([
|
||||
'cookie',
|
||||
'x-csrf-token',
|
||||
'x-xsrf-token',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Telescope gate.
|
||||
*
|
||||
* This gate determines who can access Telescope in non-local environments.
|
||||
*/
|
||||
protected function gate(): void
|
||||
{
|
||||
Gate::define('viewTelescope', function (User $user) {
|
||||
return in_array($user->email, [
|
||||
//
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
"laravel/telescope": "^5.20",
|
||||
"laravel/tinker": "^2.8",
|
||||
"php-ffmpeg/php-ffmpeg": "^1.4",
|
||||
"tymon/jwt-auth": "^2.3"
|
||||
|
||||
127
plataforma-tutorias/composer.lock
generated
127
plataforma-tutorias/composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "39a1d2002974ed4a149001079ae3c3fc",
|
||||
"content-hash": "18cd2b7643efb6f57fa98ea174f4f60c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@@ -1432,6 +1432,62 @@
|
||||
},
|
||||
"time": "2023-12-19T18:44:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/sentinel",
|
||||
"version": "v1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/sentinel.git",
|
||||
"reference": "972d9885d9d14312a118e9565c4e6ecc5e751ea1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/sentinel/zipball/972d9885d9d14312a118e9565c4e6ecc5e751ea1",
|
||||
"reference": "972d9885d9d14312a118e9565c4e6ecc5e751ea1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"illuminate/container": "^8.37|^9.0|^10.0|^11.0|^12.0|^13.0",
|
||||
"php": "^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "^1.27",
|
||||
"orchestra/testbench": "^6.47.1|^7.56|^8.37|^9.16|^10.9|^11.0",
|
||||
"phpstan/phpstan": "^2.1.33"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Laravel\\Sentinel\\SentinelServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Sentinel\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
},
|
||||
{
|
||||
"name": "Mior Muhammad Zaki",
|
||||
"email": "mior@laravel.com"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/laravel/sentinel/tree/v1.1.0"
|
||||
},
|
||||
"time": "2026-03-24T14:03:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/serializable-closure",
|
||||
"version": "v1.3.7",
|
||||
@@ -1493,6 +1549,75 @@
|
||||
},
|
||||
"time": "2024-11-14T18:34:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/telescope",
|
||||
"version": "v5.20.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/telescope.git",
|
||||
"reference": "38ec6e6006a67e05e0c476c5f8ef3550b72e43d8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/telescope/zipball/38ec6e6006a67e05e0c476c5f8ef3550b72e43d8",
|
||||
"reference": "38ec6e6006a67e05e0c476c5f8ef3550b72e43d8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"laravel/framework": "^8.37|^9.0|^10.0|^11.0|^12.0|^13.0",
|
||||
"laravel/sentinel": "^1.0",
|
||||
"php": "^8.0",
|
||||
"symfony/console": "^5.3|^6.0|^7.0|^8.0",
|
||||
"symfony/var-dumper": "^5.0|^6.0|^7.0|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-gd": "*",
|
||||
"guzzlehttp/guzzle": "^6.0|^7.0",
|
||||
"laravel/octane": "^1.4|^2.0",
|
||||
"orchestra/testbench": "^6.47.1|^7.55|^8.36|^9.15|^10.8|^11.0",
|
||||
"phpstan/phpstan": "^1.10"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Laravel\\Telescope\\TelescopeServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Telescope\\": "src/",
|
||||
"Laravel\\Telescope\\Database\\Factories\\": "database/factories/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
},
|
||||
{
|
||||
"name": "Mohamed Said",
|
||||
"email": "mohamed@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "An elegant debug assistant for the Laravel framework.",
|
||||
"keywords": [
|
||||
"debugging",
|
||||
"laravel",
|
||||
"monitoring"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/telescope/issues",
|
||||
"source": "https://github.com/laravel/telescope/tree/v5.20.0"
|
||||
},
|
||||
"time": "2026-04-06T12:52:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/tinker",
|
||||
"version": "v2.11.1",
|
||||
|
||||
@@ -168,6 +168,7 @@ return [
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
App\Providers\TelescopeServiceProvider::class,
|
||||
])->toArray(),
|
||||
|
||||
/*
|
||||
|
||||
212
plataforma-tutorias/config/telescope.php
Normal file
212
plataforma-tutorias/config/telescope.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Telescope\Http\Middleware\Authorize;
|
||||
use Laravel\Telescope\Watchers;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Master Switch
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option may be used to disable all Telescope watchers regardless
|
||||
| of their individual configuration, which simply provides a single
|
||||
| and convenient way to enable or disable Telescope data storage.
|
||||
|
|
||||
*/
|
||||
|
||||
'enabled' => env('TELESCOPE_ENABLED', true),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the subdomain where Telescope will be accessible from. If the
|
||||
| setting is null, Telescope will reside under the same domain as the
|
||||
| application. Otherwise, this value will be used as the subdomain.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('TELESCOPE_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the URI path where Telescope will be accessible from. Feel free
|
||||
| to change this path to anything you like. Note that the URI will not
|
||||
| affect the paths of its internal API that aren't exposed to users.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => env('TELESCOPE_PATH', 'telescope'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Storage Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This configuration options determines the storage driver that will
|
||||
| be used to store Telescope's data. In addition, you may set any
|
||||
| custom options as needed by the particular driver you choose.
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('TELESCOPE_DRIVER', 'database'),
|
||||
|
||||
'storage' => [
|
||||
'database' => [
|
||||
'connection' => env('DB_CONNECTION', 'mysql'),
|
||||
'chunk' => 1000,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Queue
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This configuration options determines the queue connection and queue
|
||||
| which will be used to process ProcessPendingUpdate jobs. This can
|
||||
| be changed if you would prefer to use a non-default connection.
|
||||
|
|
||||
*/
|
||||
|
||||
'queue' => [
|
||||
'connection' => env('TELESCOPE_QUEUE_CONNECTION'),
|
||||
'queue' => env('TELESCOPE_QUEUE'),
|
||||
'delay' => env('TELESCOPE_QUEUE_DELAY', 10),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Route Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These middleware will be assigned to every Telescope route, giving you
|
||||
| the chance to add your own middleware to this list or change any of
|
||||
| the existing middleware. Or, you can simply stick with this list.
|
||||
|
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'web',
|
||||
Authorize::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed / Ignored Paths & Commands
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following array lists the URI paths and Artisan commands that will
|
||||
| not be watched by Telescope. In addition to this list, some Laravel
|
||||
| commands, like migrations and queue commands, are always ignored.
|
||||
|
|
||||
*/
|
||||
|
||||
'only_paths' => [
|
||||
// 'api/*'
|
||||
],
|
||||
|
||||
'ignore_paths' => [
|
||||
'livewire*',
|
||||
'nova-api*',
|
||||
'pulse*',
|
||||
'_boost*',
|
||||
'.well-known*',
|
||||
],
|
||||
|
||||
'ignore_commands' => [
|
||||
//
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telescope Watchers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following array lists the "watchers" that will be registered with
|
||||
| Telescope. The watchers gather the application's profile data when
|
||||
| a request or task is executed. Feel free to customize this list.
|
||||
|
|
||||
*/
|
||||
|
||||
'watchers' => [
|
||||
Watchers\BatchWatcher::class => env('TELESCOPE_BATCH_WATCHER', true),
|
||||
|
||||
Watchers\CacheWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_CACHE_WATCHER', true),
|
||||
'hidden' => [],
|
||||
'ignore' => [],
|
||||
],
|
||||
|
||||
Watchers\ClientRequestWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_CLIENT_REQUEST_WATCHER', true),
|
||||
'ignore_hosts' => [],
|
||||
],
|
||||
|
||||
Watchers\CommandWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_COMMAND_WATCHER', true),
|
||||
'ignore' => [],
|
||||
],
|
||||
|
||||
Watchers\DumpWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_DUMP_WATCHER', true),
|
||||
'always' => env('TELESCOPE_DUMP_WATCHER_ALWAYS', false),
|
||||
],
|
||||
|
||||
Watchers\EventWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_EVENT_WATCHER', true),
|
||||
'ignore' => [],
|
||||
],
|
||||
|
||||
Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true),
|
||||
|
||||
Watchers\GateWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_GATE_WATCHER', true),
|
||||
'ignore_abilities' => [],
|
||||
'ignore_packages' => true,
|
||||
'ignore_paths' => [],
|
||||
],
|
||||
|
||||
Watchers\JobWatcher::class => env('TELESCOPE_JOB_WATCHER', true),
|
||||
|
||||
Watchers\LogWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_LOG_WATCHER', true),
|
||||
'level' => 'error',
|
||||
],
|
||||
|
||||
Watchers\MailWatcher::class => env('TELESCOPE_MAIL_WATCHER', true),
|
||||
|
||||
Watchers\ModelWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_MODEL_WATCHER', true),
|
||||
'events' => ['eloquent.*'],
|
||||
'hydrations' => true,
|
||||
],
|
||||
|
||||
Watchers\NotificationWatcher::class => env('TELESCOPE_NOTIFICATION_WATCHER', true),
|
||||
|
||||
Watchers\QueryWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_QUERY_WATCHER', true),
|
||||
'ignore_packages' => true,
|
||||
'ignore_paths' => [],
|
||||
'slow' => 100,
|
||||
],
|
||||
|
||||
Watchers\RedisWatcher::class => env('TELESCOPE_REDIS_WATCHER', true),
|
||||
|
||||
Watchers\RequestWatcher::class => [
|
||||
'enabled' => env('TELESCOPE_REQUEST_WATCHER', true),
|
||||
'size_limit' => env('TELESCOPE_RESPONSE_SIZE_LIMIT', 64),
|
||||
'ignore_http_methods' => [],
|
||||
'ignore_status_codes' => [],
|
||||
],
|
||||
|
||||
Watchers\ScheduleWatcher::class => env('TELESCOPE_SCHEDULE_WATCHER', true),
|
||||
Watchers\ViewWatcher::class => env('TELESCOPE_VIEW_WATCHER', true),
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Get the migration connection name.
|
||||
*/
|
||||
public function getConnection(): ?string
|
||||
{
|
||||
return config('telescope.storage.database.connection');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$schema = Schema::connection($this->getConnection());
|
||||
|
||||
$schema->create('telescope_entries', function (Blueprint $table) {
|
||||
$table->bigIncrements('sequence');
|
||||
$table->uuid('uuid');
|
||||
$table->uuid('batch_id');
|
||||
$table->string('family_hash')->nullable();
|
||||
$table->boolean('should_display_on_index')->default(true);
|
||||
$table->string('type', 20);
|
||||
$table->longText('content');
|
||||
$table->dateTime('created_at')->nullable();
|
||||
|
||||
$table->unique('uuid');
|
||||
$table->index('batch_id');
|
||||
$table->index('family_hash');
|
||||
$table->index('created_at');
|
||||
$table->index(['type', 'should_display_on_index']);
|
||||
});
|
||||
|
||||
$schema->create('telescope_entries_tags', function (Blueprint $table) {
|
||||
$table->uuid('entry_uuid');
|
||||
$table->string('tag');
|
||||
|
||||
$table->primary(['entry_uuid', 'tag']);
|
||||
$table->index('tag');
|
||||
|
||||
$table->foreign('entry_uuid')
|
||||
->references('uuid')
|
||||
->on('telescope_entries')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
$schema->create('telescope_monitoring', function (Blueprint $table) {
|
||||
$table->string('tag')->primary();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$schema = Schema::connection($this->getConnection());
|
||||
|
||||
$schema->dropIfExists('telescope_entries_tags');
|
||||
$schema->dropIfExists('telescope_entries');
|
||||
$schema->dropIfExists('telescope_monitoring');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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_views', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||
$table->foreignId('video_id')->constrained()->onDelete('cascade');
|
||||
$table->timestamp('watched_at')->useCurrent();
|
||||
$table->unique(['user_id', 'video_id']);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('video_views');
|
||||
}
|
||||
};
|
||||
@@ -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('videos', function (Blueprint $table) {
|
||||
$table->integer('order')->after('tags')->default('0');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('videos', function (Blueprint $table) {
|
||||
$table->dropColumn('order');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -9,6 +9,7 @@ use App\Http\Controllers\UserController;
|
||||
use App\Http\Controllers\VideosController;
|
||||
use App\Http\Controllers\WorkshopsController;
|
||||
use App\Http\Middleware\JwtMiddleware;
|
||||
use App\Http\Controllers\VideoViewController;
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
@@ -32,11 +33,18 @@ Route::middleware([JwtMiddleware::class])->group(function () {
|
||||
|
||||
Route::get('/videos', [VideosController::class, 'index']);
|
||||
Route::get('/video/{id}', [VideosController::class, 'getVideo']);
|
||||
Route::post('/video/{video}/watch', [VideoViewController::class, 'store']);
|
||||
Route::get('/videos-length', [VideosController::class, 'videosLength']);
|
||||
Route::get('/videos-search', [VideosController::class, 'search']);
|
||||
Route::get('/next-videos', [VideosController::class, 'nextVideos']);
|
||||
|
||||
Route::get('/categories', [CategoryController::class, 'index']);
|
||||
|
||||
Route::get('/workshops', [WorkshopsController::class, 'index']);
|
||||
Route::get('/workshop/{id}', [WorkshopsController::class, 'getWorkshop']);
|
||||
Route::get('/workshops-length', [WorkshopsController::class, 'workshopsLength']);
|
||||
Route::get('/workshops-search', [WorkshopsController::class, 'search']);
|
||||
Route::get('/next-workshops', [WorkshopsController::class, 'nextWorkshops']);
|
||||
|
||||
Route::post('/categories', [CategoryController::class, 'create']);
|
||||
|
||||
@@ -58,7 +66,7 @@ Route::middleware([JwtMiddleware::class])->group(function () {
|
||||
Route::post('/create-video', [VideosController::class, 'create']);
|
||||
Route::get('/edit-video/{id}', [VideosController::class, 'getVideo']);
|
||||
Route::patch('/edit-video/{id}', [VideosController::class, 'update']);
|
||||
Route::delete('/video/{id}', [VideosController::class, 'destroy']);
|
||||
Route::delete('/delete-video/{id}', [VideosController::class, 'destroy']);
|
||||
|
||||
Route::post('/create-workshop', [WorkshopsController::class, 'create']);
|
||||
Route::get('/edit-workshop/{id}', [WorkshopsController::class, 'getWorkshop']);
|
||||
|
||||
2
plataforma-tutorias/storage/debugbar/.gitignore
vendored
Normal file
2
plataforma-tutorias/storage/debugbar/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user