Compare commits
55
Commits
2fd5b262a6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f3b5b1d69 | ||
|
|
f505180237 | ||
|
|
ff946959a5 | ||
|
|
b2da21e99c | ||
|
|
5c6a771d7a | ||
|
|
ffdae46038 | ||
|
|
27413ae827 | ||
|
|
b97ce2dcef | ||
|
|
7b5c23c3e1 | ||
|
|
d50e134b1c | ||
|
|
094f02e460 | ||
|
|
7b10a5f6f3 | ||
|
|
4a0a19fdff | ||
|
|
2b5a7c9b1b | ||
|
|
706b349130 | ||
|
|
40b7efac2f | ||
|
|
b24af706a0 | ||
|
|
a6f41ed6f8 | ||
|
|
1a0645daef | ||
|
|
7c1da7d5d7 | ||
|
|
b5a2501f4b | ||
|
|
3d9c7abd38 | ||
|
|
dbefdccc68 | ||
|
|
f3f05958a6 | ||
|
|
42f3808343 | ||
|
|
81ac4a896f | ||
|
|
191e5597c0 | ||
|
|
15dc009ae1 | ||
|
|
059e97bdd7 | ||
|
|
1cf1ba1c67 | ||
|
|
0ac28ea776 | ||
|
|
a9bf567764 | ||
|
|
6293c7aa6e | ||
|
|
a7e3f2cbd8 | ||
|
|
81a7d19222 | ||
|
|
b1e39dfabf | ||
|
|
fb17f4c08b | ||
|
|
5ec95f539b | ||
|
|
65bd416599 | ||
|
|
f097a1e50c | ||
|
|
ab10f03afe | ||
|
|
3a2a27be98 | ||
|
|
12fc305045 | ||
|
|
1ffd920e89 | ||
|
|
57ca732917 | ||
|
|
33a23962c8 | ||
|
|
00d8b9687b | ||
|
|
eca1756e76 | ||
|
|
81aba7232a | ||
|
|
b3ce699159 | ||
|
|
f2e9adf7f1 | ||
|
|
3a2ed286b6 | ||
|
|
934a3884ad | ||
|
|
a1a858abbf | ||
|
|
c0ff35c0a8 |
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class SyncSurveyUsers extends Command
|
||||
{
|
||||
protected $signature = 'survey:sync-users {--token= : Approagency admin token}';
|
||||
protected $description = 'Sync user profile fields (name, age, gender) from approagency for all meditation users with missing data';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$token = $this->option('token') ?: config('services.approagency.token');
|
||||
|
||||
if (empty($token)) {
|
||||
$this->error('Provide --token=<approagency_admin_token> or set APPROAGENCY_ADMIN_TOKEN in .env');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$users = User::whereNull('first_name')
|
||||
->whereNotNull('mobile')
|
||||
->get();
|
||||
|
||||
$this->info("Found {$users->count()} users with missing first_name. Syncing...");
|
||||
|
||||
$synced = 0;
|
||||
$failed = 0;
|
||||
|
||||
foreach ($users as $user) {
|
||||
$retries = 0;
|
||||
while ($retries <= 3) {
|
||||
try {
|
||||
$response = Http::withToken($token)
|
||||
->retry(2, 2000)
|
||||
->get('https://api.approagency.ir/api/admin/users', [
|
||||
'mobile' => $user->mobile,
|
||||
'per_page' => 1,
|
||||
]);
|
||||
|
||||
if ($response->status() === 429) {
|
||||
$retries++;
|
||||
$wait = $retries * 3;
|
||||
$this->warn(" rate limited on {$user->mobile}, waiting {$wait}s...");
|
||||
sleep($wait);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($response->successful()) {
|
||||
$data = $response->json('data.0');
|
||||
if ($data) {
|
||||
$user->update([
|
||||
'first_name' => $data['first_name'] ?? $user->first_name,
|
||||
'last_name' => $data['last_name'] ?? $user->last_name,
|
||||
'age' => $data['age'] ?? $user->age,
|
||||
'gender' => $data['gender'] ?? $user->gender,
|
||||
'birthday' => $data['birthday'] ?? $user->birthday,
|
||||
'identifier' => $data['uuid'] ?? $user->identifier,
|
||||
]);
|
||||
$name = $data['first_name'] ?? 'null';
|
||||
$this->line(" synced: {$user->mobile} → {$name}");
|
||||
$synced++;
|
||||
}
|
||||
} else {
|
||||
$this->warn(" skip: {$user->mobile} (HTTP {$response->status()})");
|
||||
$failed++;
|
||||
}
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
$retries++;
|
||||
if ($retries > 3) {
|
||||
$this->error(" failed: {$user->mobile} — {$e->getMessage()}");
|
||||
$failed++;
|
||||
} else {
|
||||
sleep($retries * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sleep(3); // 3s between requests
|
||||
}
|
||||
|
||||
$this->info("Done. Synced: {$synced}, Failed: {$failed}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Announcement;
|
||||
use App\Traits\HandlesImageUpload;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AnnouncementController extends Controller
|
||||
{
|
||||
use HandlesImageUpload;
|
||||
|
||||
// Admin list — every announcement, newest first.
|
||||
public function index()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => Announcement::with('image')->latest()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
// App side: only the single latest currently-active announcement (or null).
|
||||
public function latest()
|
||||
{
|
||||
$announcement = Announcement::with('image')
|
||||
->active()
|
||||
->orderByDesc('start_date')
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
return response()->json(['data' => $announcement]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'link' => 'nullable|string|max:500',
|
||||
'button_text' => 'nullable|string|max:255',
|
||||
'start_date' => 'nullable|date',
|
||||
'end_date' => 'nullable|date|after_or_equal:start_date',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
$data['image_id'] = $this->uploadedImageId($request) ?? ($data['image_id'] ?? null);
|
||||
|
||||
$announcement = Announcement::create($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Announcement created successfully',
|
||||
'data' => $announcement->load('image'),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(
|
||||
Announcement::with('image')->findOrFail($id)
|
||||
);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$announcement = Announcement::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'title' => 'sometimes|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'link' => 'nullable|string|max:500',
|
||||
'button_text' => 'nullable|string|max:255',
|
||||
'start_date' => 'nullable|date',
|
||||
'end_date' => 'nullable|date|after_or_equal:start_date',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
if (($uploadedImageId = $this->uploadedImageId($request)) !== null) {
|
||||
$data['image_id'] = $uploadedImageId;
|
||||
}
|
||||
|
||||
$announcement->update($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Announcement updated successfully',
|
||||
'data' => $announcement->load('image'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$announcement = Announcement::findOrFail($id);
|
||||
$announcement->delete();
|
||||
|
||||
return response()->json(['message' => 'Announcement deleted successfully']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\AppVersion;
|
||||
use App\Traits\HandlesImageUpload;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AppVersionController extends Controller
|
||||
{
|
||||
use HandlesImageUpload;
|
||||
|
||||
// Admin list — every version, highest version_code first.
|
||||
public function index()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => AppVersion::with('image')->orderByDesc('version_code')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
// App side: the newest version (highest version_code) for update checks.
|
||||
public function latest()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => AppVersion::with('image')->orderByDesc('version_code')->first(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'version_name' => 'required|string|max:255',
|
||||
'version_code' => 'required|integer|min:0',
|
||||
'link' => 'nullable|string|max:500',
|
||||
'button_text' => 'nullable|string|max:255',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
$data['image_id'] = $this->uploadedImageId($request) ?? ($data['image_id'] ?? null);
|
||||
|
||||
$version = AppVersion::create($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Version created successfully',
|
||||
'data' => $version->load('image'),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(
|
||||
AppVersion::with('image')->findOrFail($id)
|
||||
);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$version = AppVersion::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'title' => 'sometimes|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'version_name' => 'sometimes|string|max:255',
|
||||
'version_code' => 'sometimes|integer|min:0',
|
||||
'link' => 'nullable|string|max:500',
|
||||
'button_text' => 'nullable|string|max:255',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
if (($uploadedImageId = $this->uploadedImageId($request)) !== null) {
|
||||
$data['image_id'] = $uploadedImageId;
|
||||
}
|
||||
|
||||
$version->update($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Version updated successfully',
|
||||
'data' => $version->load('image'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$version = AppVersion::findOrFail($id);
|
||||
$version->delete();
|
||||
|
||||
return response()->json(['message' => 'Version deleted successfully']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\BreathingColor;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BreathingColorController extends Controller
|
||||
{
|
||||
// Palette the app shows when creating a breathing template.
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = BreathingColor::query();
|
||||
|
||||
if (!$request->boolean('include_inactive')) {
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
return response()->json($query->orderBy('order')->get());
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(BreathingColor::findOrFail($id));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $this->validateData($request, true);
|
||||
|
||||
$color = BreathingColor::create($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Color created successfully',
|
||||
'color' => $color,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$color = BreathingColor::findOrFail($id);
|
||||
|
||||
$color->update($this->validateData($request, false));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Color updated successfully',
|
||||
'color' => $color,
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
BreathingColor::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(['message' => 'Color deleted successfully']);
|
||||
}
|
||||
|
||||
private function validateData(Request $request, bool $creating): array
|
||||
{
|
||||
return $request->validate([
|
||||
'name' => 'nullable|string|max:255',
|
||||
'colors' => ($creating ? 'required' : 'sometimes') . '|array|min:1',
|
||||
'colors.*' => ['string', 'regex:/^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/'],
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,9 @@ public function createTemplate(Request $request)
|
||||
'duration' => 'sometimes|integer|min:0',
|
||||
'description' => 'sometimes|string|nullable',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'source' => 'nullable|string'
|
||||
'source' => 'nullable|string',
|
||||
// The chosen color from the /breathing-colors palette.
|
||||
'breathing_color_id' => 'nullable|exists:breathing_colors,id',
|
||||
]);
|
||||
|
||||
$template = BreathingTemplate::create([
|
||||
@@ -31,16 +33,20 @@ public function createTemplate(Request $request)
|
||||
'duration'=> $data['duration'] ?? 60,
|
||||
'description' => $data['description'] ?? null,
|
||||
'image_id' => $data['image_id'] ?? null,
|
||||
'source' => 'nullable|string'
|
||||
'source' => $data['source'] ?? null,
|
||||
'breathing_color_id' => $data['breathing_color_id'] ?? null,
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'Template created', 'template' => $template->load('image')]);
|
||||
return response()->json(['message' => 'Template created', 'template' => $template->load('image', 'breathingColor')]);
|
||||
}
|
||||
|
||||
public function updateTemplate(Request $request, $id)
|
||||
{
|
||||
// Editable: the user's own templates OR the shared/global ones (user_id null).
|
||||
$template = BreathingTemplate::where('id', $id)
|
||||
->where('user_id', auth()->id())
|
||||
->where(function ($q) {
|
||||
$q->where('user_id', auth()->id())->orWhereNull('user_id');
|
||||
})
|
||||
->firstOrFail();
|
||||
|
||||
$data = $request->validate([
|
||||
@@ -51,17 +57,20 @@ public function updateTemplate(Request $request, $id)
|
||||
'duration' => 'sometimes|integer|min:0',
|
||||
'description' => 'sometimes|string|nullable',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'source' => 'nullable|string'
|
||||
'source' => 'nullable|string',
|
||||
'breathing_color_id' => 'nullable|exists:breathing_colors,id',
|
||||
]);
|
||||
|
||||
$template->update($data);
|
||||
|
||||
return response()->json(['message' => 'Template updated', 'template' => $template->load('image')]);
|
||||
return response()->json(['message' => 'Template updated', 'template' => $template->load('image', 'breathingColor')]);
|
||||
}
|
||||
public function deleteTemplate($id)
|
||||
{
|
||||
$template = BreathingTemplate::where('id', $id)
|
||||
->where('user_id', auth()->id())
|
||||
->where(function ($q) {
|
||||
$q->where('user_id', auth()->id())->orWhereNull('user_id');
|
||||
})
|
||||
->firstOrFail();
|
||||
|
||||
$template->delete();
|
||||
@@ -75,7 +84,7 @@ public function getTemplates()
|
||||
|
||||
$templates = BreathingTemplate::whereNull('user_id')
|
||||
->orWhere('user_id', $userId)
|
||||
->with('image') // eager load image
|
||||
->with(['image', 'breathingColor']) // eager load image + color
|
||||
->get()
|
||||
->map(function ($template) {
|
||||
if ($template->image) {
|
||||
@@ -83,6 +92,8 @@ public function getTemplates()
|
||||
} else {
|
||||
$template->image_url = null;
|
||||
}
|
||||
// Old app expects a non-null description string.
|
||||
$template->description = $template->description ?? '';
|
||||
return $template;
|
||||
});
|
||||
|
||||
@@ -92,7 +103,7 @@ public function getTemplates()
|
||||
public function getUserTemplates()
|
||||
{
|
||||
$templates = BreathingTemplate::where('user_id', auth()->id())
|
||||
->with('image') // eager load image
|
||||
->with(['image', 'breathingColor']) // eager load image + color
|
||||
->get()
|
||||
->map(function ($template) {
|
||||
if ($template->image) {
|
||||
@@ -100,6 +111,8 @@ public function getUserTemplates()
|
||||
} else {
|
||||
$template->image_url = null;
|
||||
}
|
||||
// Old app expects a non-null description string.
|
||||
$template->description = $template->description ?? '';
|
||||
return $template;
|
||||
});
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\MusicCategory;
|
||||
use App\Traits\StoresUploads;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
@@ -13,27 +15,88 @@ class CategoryController extends Controller
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$type = $request->input('type');
|
||||
|
||||
// Playlist categories live in their own table (music_categories); serve
|
||||
// them here too so the front has one /categories entry point.
|
||||
if ($type === Category::TYPE_PLAYLIST) {
|
||||
return response()->json($this->playlistCategories($request)->values());
|
||||
}
|
||||
|
||||
$query = Category::query()->withCount('subcategories');
|
||||
|
||||
if ($request->filled('type')) {
|
||||
$query->where('type', $type);
|
||||
}
|
||||
|
||||
if ($request->boolean('with_subcategories')) {
|
||||
$query->with('subcategories');
|
||||
}
|
||||
|
||||
return response()->json(
|
||||
$query->orderBy('name')->get()
|
||||
);
|
||||
$categories = $query->orderBy('order')->orderBy('name')->get();
|
||||
|
||||
// No type filter → also fold in the playlist (music) categories so the
|
||||
// response contains every category across both tables.
|
||||
if (!$request->filled('type')) {
|
||||
$categories = $categories
|
||||
->concat($this->playlistCategories($request))
|
||||
->sortBy([['order', 'asc'], ['name', 'asc']])
|
||||
->values();
|
||||
}
|
||||
|
||||
return response()->json($categories);
|
||||
}
|
||||
|
||||
// Music categories normalized to the generic category shape.
|
||||
private function playlistCategories(Request $request)
|
||||
{
|
||||
$query = MusicCategory::query()->with('image')->withCount('subcategories');
|
||||
|
||||
if (!$request->boolean('include_inactive')) {
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
if ($request->boolean('with_subcategories')) {
|
||||
$query->with('subcategories.image');
|
||||
}
|
||||
|
||||
return $query->orderBy('order')->get()->map(function ($c) use ($request) {
|
||||
return [
|
||||
'id' => $c->id,
|
||||
'name' => $c->name,
|
||||
'type' => Category::TYPE_PLAYLIST,
|
||||
'description' => $c->description,
|
||||
'icon' => $c->image?->path,
|
||||
'icon_url' => $c->image?->url,
|
||||
'order' => $c->order,
|
||||
'is_active' => $c->is_active,
|
||||
'subcategories_count' => $c->subcategories_count,
|
||||
'subcategories' => $request->boolean('with_subcategories') ? $c->subcategories : null,
|
||||
'created_at' => $c->created_at,
|
||||
'updated_at' => $c->updated_at,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255|unique:categories,name',
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('categories', 'name')->where('type', $request->input('type', Category::TYPE_MEDIA)),
|
||||
],
|
||||
'type' => ['nullable', Rule::in(Category::TYPES)],
|
||||
'order' => 'nullable|integer',
|
||||
'description' => 'nullable|string',
|
||||
'icon' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
$category = Category::create([
|
||||
'name' => $data['name'],
|
||||
'type' => $data['type'] ?? Category::TYPE_MEDIA,
|
||||
'order' => $data['order'] ?? 0,
|
||||
'description' => $data['description'] ?? null,
|
||||
'icon' => $request->hasFile('icon')
|
||||
? $this->storeUpload($request->file('icon'), 'categories/icons')
|
||||
@@ -53,16 +116,61 @@ public function show($id)
|
||||
return response()->json($category);
|
||||
}
|
||||
|
||||
// Category with each of its sub-categories and that sub-category's medias.
|
||||
public function grouped($id)
|
||||
{
|
||||
$category = Category::with(['subcategories' => function ($q) {
|
||||
$q->orderBy('name')->with(['media' => function ($m) {
|
||||
$m->with(['image', 'detailImage', 'tags'])->latest();
|
||||
}]);
|
||||
}])->findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'category' => [
|
||||
'id' => $category->id,
|
||||
'name' => $category->name,
|
||||
'description' => $category->description,
|
||||
'icon_url' => $category->icon_url,
|
||||
'type' => $category->type,
|
||||
],
|
||||
'sub_categories' => $category->subcategories->map(fn ($sub) => [
|
||||
'sub_category' => [
|
||||
'id' => $sub->id,
|
||||
'name' => $sub->name,
|
||||
'description' => $sub->description,
|
||||
],
|
||||
'medias' => $sub->media,
|
||||
])->values(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$category = Category::findOrFail($id);
|
||||
|
||||
$targetType = $request->input('type', $category->type);
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => 'sometimes|string|max:255|unique:categories,name,' . $category->id,
|
||||
'name' => [
|
||||
'sometimes',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('categories', 'name')
|
||||
->where('type', $targetType)
|
||||
->ignore($category->id),
|
||||
],
|
||||
'type' => ['nullable', Rule::in(Category::TYPES)],
|
||||
'order' => 'nullable|integer',
|
||||
'description' => 'nullable|string',
|
||||
'icon' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
if (array_key_exists('type', $data) && $data['type'] !== null) {
|
||||
$category->type = $data['type'];
|
||||
}
|
||||
if (array_key_exists('order', $data) && $data['order'] !== null) {
|
||||
$category->order = $data['order'];
|
||||
}
|
||||
if (array_key_exists('name', $data)) {
|
||||
$category->name = $data['name'];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\FaqCategory;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FaqCategoryController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = FaqCategory::query()->withCount('faqs');
|
||||
|
||||
if (!$request->boolean('include_inactive')) {
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
return response()->json($query->orderBy('order')->get());
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(FaqCategory::with('faqs')->withCount('faqs')->findOrFail($id));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$category = FaqCategory::create($data);
|
||||
|
||||
return response()->json(['message' => 'FAQ category created', 'category' => $category], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$category = FaqCategory::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => 'sometimes|string|max:255',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$category->update($data);
|
||||
|
||||
return response()->json(['message' => 'FAQ category updated', 'category' => $category]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
FaqCategory::findOrFail($id)->delete(); // faqs cascade
|
||||
|
||||
return response()->json(['message' => 'FAQ category deleted']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Faq;
|
||||
use App\Models\FaqCategory;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FaqController extends Controller
|
||||
{
|
||||
// APP: active FAQ categories, each with their active questions (grouped).
|
||||
// Pass ?include_inactive=1 (admin) to get everything.
|
||||
public function index(Request $request)
|
||||
{
|
||||
$includeInactive = $request->boolean('include_inactive');
|
||||
|
||||
$categories = FaqCategory::query()
|
||||
->with(['faqs' => function ($q) use ($includeInactive) {
|
||||
if (!$includeInactive) {
|
||||
$q->where('is_active', true);
|
||||
}
|
||||
$q->orderBy('order');
|
||||
}])
|
||||
->when(!$includeInactive, fn ($q) => $q->where('is_active', true))
|
||||
->orderBy('order')
|
||||
->get();
|
||||
|
||||
return response()->json($categories);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(Faq::with('category')->findOrFail($id));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'faq_category_id' => 'required|exists:faq_categories,id',
|
||||
'question' => 'required|string|max:500',
|
||||
'answer' => 'required|string',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$faq = Faq::create($data);
|
||||
|
||||
return response()->json(['message' => 'FAQ created', 'faq' => $faq->load('category')], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$faq = Faq::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'faq_category_id' => 'sometimes|exists:faq_categories,id',
|
||||
'question' => 'sometimes|string|max:500',
|
||||
'answer' => 'sometimes|string',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$faq->update($data);
|
||||
|
||||
return response()->json(['message' => 'FAQ updated', 'faq' => $faq->load('category')]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
Faq::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(['message' => 'FAQ deleted']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class InteractionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Comment and/or rate an item in a single request.
|
||||
* Body: { content?: string, stars?: int (1-5) }
|
||||
* - content → adds a comment
|
||||
* - stars → sets/updates this user's rating
|
||||
* At least one is required.
|
||||
*/
|
||||
public function store(Request $request, $type, $id)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'content' => 'nullable|string|max:1000',
|
||||
'stars' => 'nullable|integer|min:1|max:5',
|
||||
]);
|
||||
|
||||
if (!$request->filled('content') && !$request->filled('stars')) {
|
||||
throw ValidationException::withMessages([
|
||||
'content' => ['Provide a comment (content) and/or a rating (stars).'],
|
||||
]);
|
||||
}
|
||||
|
||||
$model = $this->getModel($type, $id);
|
||||
if (!$model) {
|
||||
return response()->json(['message' => 'Item not found'], 404);
|
||||
}
|
||||
|
||||
$comment = null;
|
||||
if ($request->filled('content')) {
|
||||
$comment = $model->comments()->create([
|
||||
'user_id' => auth()->id(),
|
||||
'content' => $data['content'],
|
||||
])->load('user');
|
||||
}
|
||||
|
||||
$rating = null;
|
||||
if ($request->filled('stars')) {
|
||||
$rating = $model->ratings()->updateOrCreate(
|
||||
['user_id' => auth()->id()],
|
||||
['stars' => $data['stars']]
|
||||
);
|
||||
}
|
||||
|
||||
$model = $model->fresh();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Interaction saved successfully',
|
||||
'comment' => $comment,
|
||||
'your_rating' => $rating?->stars,
|
||||
'average_rating' => $model->average_rating,
|
||||
'ratings_count' => $model->ratings_count,
|
||||
'comments_count' => $model->comments_count,
|
||||
]);
|
||||
}
|
||||
|
||||
private function getModel($type, $id)
|
||||
{
|
||||
// media, music and playlist all support comments + ratings.
|
||||
$models = [
|
||||
'music' => \App\Models\Music::class,
|
||||
'media' => \App\Models\Media::class,
|
||||
'playlist' => \App\Models\MusicPlaylist::class,
|
||||
];
|
||||
|
||||
$class = $models[$type] ?? null;
|
||||
|
||||
return $class ? $class::find($id) : null;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
use App\Models\Like;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class LikeController extends Controller
|
||||
{
|
||||
@@ -94,7 +95,11 @@ public function myLikedItems(Request $request)
|
||||
{
|
||||
$type = $request->get('type'); // Optional filter by type (music or media)
|
||||
|
||||
$query = Like::with('likeable')
|
||||
$query = Like::with(['likeable' => fn (MorphTo $m) => $m->morphWith([
|
||||
\App\Models\Media::class => ['image', 'detailImage', 'categories', 'subCategories', 'tags'],
|
||||
\App\Models\Music::class => ['image', 'playlists', 'tags'],
|
||||
\App\Models\MusicPlaylist::class => ['image', 'detailImage', 'categories', 'subcategories'],
|
||||
])])
|
||||
->where('user_id', auth()->id());
|
||||
|
||||
if ($type) {
|
||||
|
||||
@@ -95,12 +95,29 @@ public function index(Request $request)
|
||||
->orWhere('user_id', auth()->id());
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 1️⃣ Multi Category
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$this->applyMediaFilters($query, $request);
|
||||
|
||||
$query->orderBy('created_at', 'desc');
|
||||
|
||||
// Optional cap: ?count=10 returns only the first 10 items.
|
||||
if ($request->filled('count')) {
|
||||
$query->limit(max(1, (int) $request->input('count')));
|
||||
}
|
||||
|
||||
$media = $query->get();
|
||||
|
||||
// Old app expects a non-null external_url; fall back to the playable url.
|
||||
$media->each(function ($m) {
|
||||
$m->external_url = $m->external_url ?: ($m->url ?? '');
|
||||
});
|
||||
|
||||
return response()->json($media);
|
||||
}
|
||||
|
||||
// Apply the category / subcategory / duration / tag / search filters shared by
|
||||
// the media list (index) and the filters screen.
|
||||
private function applyMediaFilters($query, Request $request)
|
||||
{
|
||||
if ($request->filled('categories')) {
|
||||
$categories = explode(',', $request->categories);
|
||||
$query->whereHas('categories', function ($q) use ($categories) {
|
||||
@@ -115,77 +132,39 @@ public function index(Request $request)
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 2️⃣ Multi Duration Ranges
|
||||
|--------------------------------------------------------------------------
|
||||
| duration stored in minutes (integer)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Duration ranges (duration stored in minutes). Keys come from durationRanges().
|
||||
if ($request->filled('durations')) {
|
||||
$defs = $this->durationRanges();
|
||||
// Keep only known range keys so an unknown value can't produce an empty
|
||||
// (match-everything) WHERE group.
|
||||
$ranges = array_filter(
|
||||
explode(',', $request->durations),
|
||||
fn ($r) => $r === '120-' || isset($defs[$r])
|
||||
);
|
||||
|
||||
$ranges = explode(',', $request->durations);
|
||||
|
||||
$query->where(function ($q) use ($ranges) {
|
||||
|
||||
foreach ($ranges as $range) {
|
||||
|
||||
if ($range === '1-2') {
|
||||
$q->orWhereBetween('duration', [1, 2]);
|
||||
if (!empty($ranges)) {
|
||||
$query->where(function ($q) use ($ranges, $defs) {
|
||||
foreach ($ranges as $range) {
|
||||
if ($range === '120-') {
|
||||
$q->orWhere('duration', '>', $this->durationOtherMin());
|
||||
} else {
|
||||
$q->orWhereBetween('duration', $defs[$range]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($range === '2-5') {
|
||||
$q->orWhereBetween('duration', [3, 5]);
|
||||
}
|
||||
|
||||
if ($range === '5-10') {
|
||||
$q->orWhereBetween('duration', [6, 10]);
|
||||
}
|
||||
if ($range === '10-30') {
|
||||
$q->orWhereBetween('duration', [10, 30]);
|
||||
}
|
||||
if ($range === '30-60') {
|
||||
$q->orWhereBetween('duration', [30, 60]);
|
||||
}
|
||||
if ($range === '60-120') {
|
||||
$q->orWhereBetween('duration', [60, 120]);
|
||||
}
|
||||
|
||||
if ($range === 'other') {
|
||||
$q->orWhere('duration', '>', 120);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 3️⃣ Tags
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if ($request->filled('tags')) {
|
||||
$tags = explode(',', $request->tags);
|
||||
|
||||
$query->whereHas('tags', function ($q) use ($tags) {
|
||||
$q->whereIn('name', $tags);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 4️⃣ Search
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if ($request->filled('search')) {
|
||||
|
||||
$search = $request->search;
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
|
||||
$q->where('title', 'LIKE', "%$search%")
|
||||
->orWhere('caption', 'LIKE', "%$search%")
|
||||
->orWhereHas('categories', function ($c) use ($search) {
|
||||
@@ -197,13 +176,47 @@ public function index(Request $request)
|
||||
->orWhereHas('tags', function ($t) use ($search) {
|
||||
$t->where('name', 'LIKE', "%$search%");
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json(
|
||||
$query->orderBy('created_at', 'desc')->get()
|
||||
);
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Single source of truth for duration buckets (minutes), used by both the
|
||||
// filter facet (/media/filters) and the search filter. Non-overlapping.
|
||||
// Anything above durationOtherMin() falls into the 'other' bucket.
|
||||
private function durationRanges(): array
|
||||
{
|
||||
return [
|
||||
'1-2' => [1, 2],
|
||||
'2-5' => [3, 5],
|
||||
'5-10' => [6, 10],
|
||||
'10-30' => [11, 30],
|
||||
'30-60' => [31, 60],
|
||||
'60-120' => [61, 120],
|
||||
];
|
||||
}
|
||||
|
||||
private function durationOtherMin(): int
|
||||
{
|
||||
return 120;
|
||||
}
|
||||
|
||||
// NEWEST media, paginated (?per_page=, ?page=). Same visibility scope as index.
|
||||
public function newest(Request $request)
|
||||
{
|
||||
$perPage = (int) $request->input('per_page', 20);
|
||||
$perPage = max(1, min($perPage, 100));
|
||||
|
||||
$media = Media::with(['image', 'detailImage', 'categories', 'subCategories', 'myNote', 'tags'])
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
})
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($perPage);
|
||||
|
||||
return response()->json($media);
|
||||
}
|
||||
|
||||
public function submitFeedback(Request $request, $mediaId)
|
||||
@@ -325,27 +338,33 @@ public function filters(Request $request)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
$durations = Media::select(
|
||||
DB::raw("
|
||||
CASE
|
||||
WHEN duration BETWEEN 1 AND 2 THEN '1-2'
|
||||
WHEN duration BETWEEN 3 AND 5 THEN '2-5'
|
||||
WHEN duration BETWEEN 5 AND 10 THEN '5-10'
|
||||
WHEN duration BETWEEN 10 AND 20 THEN '10-20'
|
||||
WHEN duration BETWEEN 20 AND 30 THEN '20-30'
|
||||
WHEN duration BETWEEN 60 AND 120 THEN '60-120'
|
||||
ELSE 'other'
|
||||
END as duration_range
|
||||
"),
|
||||
DB::raw('COUNT(*) as total')
|
||||
)
|
||||
->whereNotNull('duration')
|
||||
// Build the CASE from the same range definitions the search filter uses,
|
||||
// so the facet keys (e.g. "10-30") always match what /media/search accepts.
|
||||
$caseSql = 'CASE ';
|
||||
foreach ($this->durationRanges() as $key => [$min, $max]) {
|
||||
$caseSql .= "WHEN duration BETWEEN {$min} AND {$max} THEN '{$key}' ";
|
||||
}
|
||||
$caseSql .= "WHEN duration > {$this->durationOtherMin()} THEN '120-' END";
|
||||
|
||||
// Counts only for buckets that currently have media.
|
||||
$counts = Media::query()
|
||||
->select(DB::raw("{$caseSql} as duration_range"), DB::raw('COUNT(*) as total'))
|
||||
->where('duration', '>', 0)
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
})
|
||||
->groupBy('duration_range')
|
||||
->get();
|
||||
->pluck('total', 'duration_range');
|
||||
|
||||
// Always return every range (the UI needs all of them), with 0 when empty.
|
||||
$durations = collect(array_keys($this->durationRanges()))
|
||||
->push('120-')
|
||||
->map(fn ($key) => [
|
||||
'duration_range' => $key,
|
||||
'total' => (int) ($counts[$key] ?? 0),
|
||||
])
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'categories' => $categories,
|
||||
@@ -354,6 +373,28 @@ public function filters(Request $request)
|
||||
]);
|
||||
}
|
||||
|
||||
// SEARCH/filter results — paginated. Accepts the same filters as /media
|
||||
// (categories, subcategories, durations, tags, search) plus ?page= & ?per_page=.
|
||||
public function search(Request $request)
|
||||
{
|
||||
$query = Media::with(['image', 'detailImage', 'categories', 'subCategories', 'myNote', 'tags'])
|
||||
->where(function ($q) {
|
||||
$q->where('visibility', 'public')
|
||||
->orWhere('user_id', auth()->id());
|
||||
});
|
||||
|
||||
$this->applyMediaFilters($query, $request);
|
||||
|
||||
$perPage = (int) $request->input('per_page', 20);
|
||||
$perPage = max(1, min($perPage, 100));
|
||||
|
||||
$results = $query->orderBy('created_at', 'desc')
|
||||
->paginate($perPage)
|
||||
->withQueryString();
|
||||
|
||||
return response()->json($results);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$media = Media::with([
|
||||
@@ -384,6 +425,8 @@ public function show($id)
|
||||
->latest()
|
||||
->paginate(15);
|
||||
|
||||
$similarMedia = $this->similarMedia($media);
|
||||
|
||||
return response()->json([
|
||||
'id' => $media->id,
|
||||
'title' => $media->title,
|
||||
@@ -403,10 +446,15 @@ public function show($id)
|
||||
'tags' => $media->tags,
|
||||
'myNote' => $media->myNote,
|
||||
'is_saved' => $media->is_saved,
|
||||
'saved_count' => $media->saved_count,
|
||||
'is_liked' => $media->is_liked,
|
||||
'likes_count' => $media->likes_count,
|
||||
'statistics' => [
|
||||
'average_rating' => $media->average_rating,
|
||||
'total_ratings' => $media->ratings_count,
|
||||
'total_comments' => $media->comments_count,
|
||||
'total_likes' => $media->likes_count,
|
||||
'total_saves' => $media->saved_count,
|
||||
'rating_distribution' => $media->rating_distribution,
|
||||
],
|
||||
'user_interaction' => [
|
||||
@@ -415,10 +463,61 @@ public function show($id)
|
||||
'has_commented' => $media->has_user_commented,
|
||||
'user_comment' => $media->user_comment,
|
||||
'user_comment_id' => $media->user_comment_id,
|
||||
'has_liked' => $media->is_liked,
|
||||
'has_saved' => $media->is_saved,
|
||||
],
|
||||
'comments' => $comments,
|
||||
'similar_media' => $similarMedia,
|
||||
]);
|
||||
}
|
||||
|
||||
// Media that shares categories / subcategories / tags with the given one,
|
||||
// ranked by how much they overlap. Excludes the media itself.
|
||||
private function similarMedia(Media $media, int $limit = 5)
|
||||
{
|
||||
$categoryIds = $media->categories->pluck('id')->all();
|
||||
$subCategoryIds = $media->subCategories->pluck('id')->all();
|
||||
$tagIds = $media->tags->pluck('id')->all();
|
||||
|
||||
if (!$categoryIds && !$subCategoryIds && !$tagIds) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$userId = auth()->id();
|
||||
|
||||
return Media::query()
|
||||
->where('media.id', '!=', $media->id)
|
||||
->where('media.type', $media->type)
|
||||
->where(function ($q) use ($userId) {
|
||||
$q->where('visibility', 'public')->orWhere('user_id', $userId);
|
||||
})
|
||||
->where(function ($q) use ($categoryIds, $subCategoryIds, $tagIds) {
|
||||
if ($categoryIds) {
|
||||
$q->orWhereHas('categories', fn ($c) => $c->whereIn('categories.id', $categoryIds));
|
||||
}
|
||||
if ($subCategoryIds) {
|
||||
$q->orWhereHas('subCategories', fn ($s) => $s->whereIn('sub_categories.id', $subCategoryIds));
|
||||
}
|
||||
if ($tagIds) {
|
||||
$q->orWhereHas('tags', fn ($t) => $t->whereIn('tags.id', $tagIds));
|
||||
}
|
||||
})
|
||||
->withCount([
|
||||
'categories as category_matches' => fn ($c) => $c->whereIn('categories.id', $categoryIds ?: [0]),
|
||||
'subCategories as subcategory_matches' => fn ($s) => $s->whereIn('sub_categories.id', $subCategoryIds ?: [0]),
|
||||
'tags as tag_matches' => fn ($t) => $t->whereIn('tags.id', $tagIds ?: [0]),
|
||||
])
|
||||
->with(['image', 'detailImage', 'categories', 'subCategories', 'tags'])
|
||||
// Pull a recent candidate pool (portable; Postgres can't ORDER BY alias
|
||||
// expressions), then rank by overlap in PHP.
|
||||
->orderByDesc('created_at')
|
||||
->limit(60)
|
||||
->get()
|
||||
->sortByDesc(fn ($m) => $m->category_matches + $m->subcategory_matches + $m->tag_matches)
|
||||
->take($limit)
|
||||
->values();
|
||||
}
|
||||
|
||||
public function rate(Request $request, $mediaId)
|
||||
{
|
||||
$request->validate([
|
||||
@@ -586,26 +685,27 @@ public function destroy($id)
|
||||
return response()->json(['message' => 'Media deleted']);
|
||||
}
|
||||
|
||||
// SAVE media
|
||||
// SAVE media — uses the shared saved_items system (HasSaves), same as /saves/*.
|
||||
public function toggleSaveMedia($id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$media = Media::findOrFail($id);
|
||||
|
||||
if ($user->savedMedia()->where('media_id', $id)->exists()) {
|
||||
// already saved → unsave
|
||||
$user->savedMedia()->detach($id);
|
||||
return response()->json(['message' => 'Unsaved!']);
|
||||
} else {
|
||||
// not saved → save
|
||||
$user->savedMedia()->attach($id);
|
||||
return response()->json(['message' => 'Saved!']);
|
||||
}
|
||||
$media->toggleSaveStatus();
|
||||
|
||||
return response()->json([
|
||||
'message' => $media->is_saved ? 'Saved!' : 'Unsaved!',
|
||||
'is_saved' => $media->is_saved,
|
||||
'saved_count' => $media->saved_count,
|
||||
]);
|
||||
}
|
||||
|
||||
// GET saved
|
||||
// GET saved — media the user saved via saved_items.
|
||||
public function saved()
|
||||
{
|
||||
return auth()->user()->savedMedia()->with(['image','detailImage','categories', 'subCategories', 'myNote' , 'tags'])->get();
|
||||
return Media::whereHas('saves', fn ($q) => $q->where('user_id', auth()->id()))
|
||||
->with(['image','detailImage','categories', 'subCategories', 'myNote' , 'tags'])
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
|
||||
// RECORD a play for the current user (feeds popular + recently played).
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
namespace App\Http\Controllers;
|
||||
use App\Models\MusicPlaylist;
|
||||
use App\Models\MusicCategory;
|
||||
use App\Traits\HandlesImageUpload;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MusicCategoryController extends Controller
|
||||
{
|
||||
use HandlesImageUpload;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$categories = MusicCategory::with(['image', 'playlists' => function($q) {
|
||||
@@ -24,10 +27,14 @@ public function store(Request $request)
|
||||
'name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
$data['image_id'] = $this->uploadedImageId($request) ?? ($data['image_id'] ?? null);
|
||||
|
||||
// Check for duplicate name
|
||||
$slug = Str::slug($data['name']);
|
||||
$existingCategory = MusicCategory::where('slug', $slug)->first();
|
||||
@@ -89,6 +96,41 @@ public function show($id)
|
||||
return response()->json($category);
|
||||
}
|
||||
|
||||
// Category with each of its sub-categories and that sub-category's playlists.
|
||||
public function grouped($id)
|
||||
{
|
||||
$category = MusicCategory::with([
|
||||
'image',
|
||||
'subcategories' => function ($q) {
|
||||
$q->orderBy('order')->with([
|
||||
'image',
|
||||
'playlists' => function ($p) {
|
||||
$p->where('is_active', true)->with('image')->orderBy('order');
|
||||
},
|
||||
]);
|
||||
},
|
||||
])->findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'category' => [
|
||||
'id' => $category->id,
|
||||
'name' => $category->name,
|
||||
'description' => $category->description,
|
||||
'icon_url' => $category->image?->url,
|
||||
'type' => 'playlist',
|
||||
],
|
||||
'sub_categories' => $category->subcategories->map(fn ($sub) => [
|
||||
'sub_category' => [
|
||||
'id' => $sub->id,
|
||||
'name' => $sub->name,
|
||||
'description' => $sub->description,
|
||||
'image_url' => $sub->image?->url,
|
||||
],
|
||||
'playlists' => $sub->playlists->each(fn ($p) => $p->append('duration')),
|
||||
])->values(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$category = MusicCategory::findOrFail($id);
|
||||
@@ -97,6 +139,7 @@ public function update(Request $request, $id)
|
||||
'name' => 'sometimes|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
]);
|
||||
@@ -105,6 +148,11 @@ public function update(Request $request, $id)
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
}
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
if (($uploadedImageId = $this->uploadedImageId($request)) !== null) {
|
||||
$data['image_id'] = $uploadedImageId;
|
||||
}
|
||||
|
||||
$category->update($data);
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -32,23 +32,29 @@ public function getAllMusic()
|
||||
return response()->json($music);
|
||||
}
|
||||
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$userId = auth()->id();
|
||||
|
||||
// Paginated so clients don't pull the whole library at once.
|
||||
$perPage = (int) $request->input('per_page', 20);
|
||||
$perPage = max(1, min($perPage, 100));
|
||||
|
||||
// (public) OR (private AND owned by me) — grouped so it stays correct.
|
||||
$music = Music::with(['image', 'playlists'])
|
||||
->where('type', 'public')
|
||||
->orWhere(function($query) use ($userId) {
|
||||
$query->where('type', 'private')
|
||||
->where('user_id', $userId);
|
||||
->where(function ($query) use ($userId) {
|
||||
$query->where('type', 'public')
|
||||
->orWhere(function ($q) use ($userId) {
|
||||
$q->where('type', 'private')
|
||||
->where('user_id', $userId);
|
||||
});
|
||||
})
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
->paginate($perPage);
|
||||
|
||||
return response()->json([
|
||||
'data' => $music,
|
||||
'total' => $music->count()
|
||||
]);
|
||||
// Laravel's paginator JSON keeps `data` and `total`, and adds
|
||||
// current_page / last_page / per_page for the client.
|
||||
return response()->json($music);
|
||||
}
|
||||
|
||||
public function getMusicByPlaylist($playlistId)
|
||||
|
||||
@@ -50,6 +50,7 @@ public function store(Request $request)
|
||||
'detail_image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
'is_premium' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
// Ensure at least one category or subcategory is provided
|
||||
@@ -98,24 +99,33 @@ public function show($id)
|
||||
->latest()
|
||||
->paginate(15);
|
||||
|
||||
return response()->json([
|
||||
'playlist' => $playlist,
|
||||
'statistics' => [
|
||||
'total_musics' => $playlist->musics->count(),
|
||||
'total_duration' => $playlist->total_duration,
|
||||
'total_comments' => $playlist->comments_count,
|
||||
'total_likes' => $playlist->likes_count,
|
||||
'total_saves' => $playlist->saved_count,
|
||||
],
|
||||
'user_interaction' => [
|
||||
'has_commented' => $playlist->has_user_commented,
|
||||
'user_comment' => $playlist->user_comment,
|
||||
'user_comment_id' => $playlist->user_comment_id,
|
||||
'has_liked' => $playlist->is_liked,
|
||||
'has_saved' => $playlist->is_saved,
|
||||
],
|
||||
'comments' => $comments,
|
||||
]);
|
||||
$playlist->append('duration');
|
||||
|
||||
return response()->json(array_merge(
|
||||
$playlist->toArray(),
|
||||
[
|
||||
'statistics' => [
|
||||
'total_musics' => $playlist->musics->count(),
|
||||
'total_duration' => $playlist->total_duration,
|
||||
'total_comments' => $playlist->comments_count,
|
||||
'total_likes' => $playlist->likes_count,
|
||||
'total_saves' => $playlist->saved_count,
|
||||
'average_rating' => $playlist->average_rating,
|
||||
'total_ratings' => $playlist->ratings_count,
|
||||
'rating_distribution' => $playlist->rating_distribution,
|
||||
],
|
||||
'user_interaction' => [
|
||||
'has_commented' => $playlist->has_user_commented,
|
||||
'user_comment' => $playlist->user_comment,
|
||||
'user_comment_id' => $playlist->user_comment_id,
|
||||
'has_liked' => $playlist->is_liked,
|
||||
'has_saved' => $playlist->is_saved,
|
||||
'has_rated' => $playlist->has_user_rated,
|
||||
'user_rating' => $playlist->user_rating,
|
||||
],
|
||||
'comments' => $comments,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
@@ -135,6 +145,7 @@ public function update(Request $request, $id)
|
||||
'detail_image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
'is_premium' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
if (isset($data['name'])) {
|
||||
|
||||
@@ -4,9 +4,22 @@
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SavedItem;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class SaveController extends Controller
|
||||
{
|
||||
// Relations to eager-load for each saveable/likeable type so the full
|
||||
// model (with its categories, images, tags, ...) is returned.
|
||||
public static function morphRelations(): array
|
||||
{
|
||||
return [
|
||||
\App\Models\Media::class => ['image', 'detailImage', 'categories', 'subCategories', 'tags'],
|
||||
\App\Models\Music::class => ['image', 'playlists', 'tags'],
|
||||
\App\Models\MusicPlaylist::class => ['image', 'detailImage', 'categories', 'subcategories'],
|
||||
\App\Models\BreathingTemplate::class => ['image', 'breathingColor'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an item (music, media, breathing template, etc.)
|
||||
*/
|
||||
@@ -95,7 +108,7 @@ public function mySavedItems(Request $request)
|
||||
{
|
||||
$type = $request->get('type'); // Optional filter by type
|
||||
|
||||
$query = SavedItem::with('saveable')
|
||||
$query = SavedItem::with(['saveable' => fn (MorphTo $m) => $m->morphWith(self::morphRelations())])
|
||||
->where('user_id', auth()->id());
|
||||
|
||||
if ($type) {
|
||||
|
||||
@@ -12,11 +12,11 @@ class SceneController extends Controller
|
||||
// CONSOLIDATED: everything the scene-settings screen needs in one call.
|
||||
public function settings()
|
||||
{
|
||||
$settings = UserSceneSetting::with('activeScene')
|
||||
$settings = UserSceneSetting::with('activeScene.theme')
|
||||
->firstOrNew(['user_id' => auth()->id()]);
|
||||
|
||||
return response()->json([
|
||||
'scenes' => Scene::where('is_active', true)->orderBy('order')->get(),
|
||||
'scenes' => Scene::with('theme')->where('is_active', true)->orderBy('order')->get(),
|
||||
'settings' => [
|
||||
'active_scene_id' => $settings->active_scene_id,
|
||||
'active_scene' => $settings->activeScene,
|
||||
@@ -55,7 +55,7 @@ public function updateSettings(Request $request)
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Scene::query();
|
||||
$query = Scene::query()->with('theme');
|
||||
|
||||
if (!$request->boolean('include_inactive')) {
|
||||
$query->where('is_active', true);
|
||||
@@ -66,7 +66,7 @@ public function index(Request $request)
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(Scene::findOrFail($id));
|
||||
return response()->json(Scene::with('theme')->findOrFail($id));
|
||||
}
|
||||
|
||||
// CREATE a scene with its image / video / sound uploads.
|
||||
@@ -74,17 +74,21 @@ public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'theme_id' => 'nullable|exists:themes,id',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
'is_premium' => 'nullable|boolean',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
'video' => 'nullable|mimes:mp4,mov,webm|max:512000',
|
||||
'sound' => 'nullable|mimes:mp3,wav,ogg,flac|max:51200',
|
||||
'video' => 'nullable|file|extensions:mp4,mov,webm,mkv,avi,m4v,3gp|max:512000',
|
||||
'sound' => 'nullable|file|extensions:mp3,wav,ogg,flac,aac,m4a,opus,mpga,wma|max:51200',
|
||||
]);
|
||||
|
||||
$scene = Scene::create([
|
||||
'name' => $data['name'],
|
||||
'theme_id' => $data['theme_id'] ?? null,
|
||||
'order' => $data['order'] ?? 0,
|
||||
'is_active' => $data['is_active'] ?? true,
|
||||
'is_premium' => $data['is_premium'] ?? false,
|
||||
'image_path' => $request->hasFile('image') ? $request->file('image')->store('scenes/images', 'public') : null,
|
||||
'video_path' => $request->hasFile('video') ? $request->file('video')->store('scenes/videos', 'public') : null,
|
||||
'sound_path' => $request->hasFile('sound') ? $request->file('sound')->store('scenes/sounds', 'public') : null,
|
||||
@@ -92,7 +96,7 @@ public function store(Request $request)
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Scene created successfully',
|
||||
'scene' => $scene,
|
||||
'scene' => $scene->load('theme'),
|
||||
], 201);
|
||||
}
|
||||
|
||||
@@ -103,22 +107,30 @@ public function update(Request $request, $id)
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => 'sometimes|string|max:255',
|
||||
'theme_id' => 'nullable|exists:themes,id',
|
||||
'order' => 'nullable|integer',
|
||||
'is_active' => 'nullable|boolean',
|
||||
'is_premium' => 'nullable|boolean',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
'video' => 'nullable|mimes:mp4,mov,webm|max:512000',
|
||||
'sound' => 'nullable|mimes:mp3,wav,ogg,flac|max:51200',
|
||||
'video' => 'nullable|file|extensions:mp4,mov,webm,mkv,avi,m4v,3gp|max:512000',
|
||||
'sound' => 'nullable|file|extensions:mp3,wav,ogg,flac,aac,m4a,opus,mpga,wma|max:51200',
|
||||
]);
|
||||
|
||||
if (array_key_exists('name', $data)) {
|
||||
$scene->name = $data['name'];
|
||||
}
|
||||
if (array_key_exists('theme_id', $data)) {
|
||||
$scene->theme_id = $data['theme_id'];
|
||||
}
|
||||
if (array_key_exists('order', $data)) {
|
||||
$scene->order = $data['order'];
|
||||
}
|
||||
if (array_key_exists('is_active', $data)) {
|
||||
$scene->is_active = $data['is_active'];
|
||||
}
|
||||
if (array_key_exists('is_premium', $data)) {
|
||||
$scene->is_premium = $data['is_premium'];
|
||||
}
|
||||
|
||||
foreach (['image' => 'scenes/images', 'video' => 'scenes/videos', 'sound' => 'scenes/sounds'] as $field => $folder) {
|
||||
if ($request->hasFile($field)) {
|
||||
@@ -134,7 +146,7 @@ public function update(Request $request, $id)
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Scene updated successfully',
|
||||
'scene' => $scene,
|
||||
'scene' => $scene->load('theme'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,49 @@
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Slider;
|
||||
use App\Traits\HandlesImageUpload;
|
||||
|
||||
class SliderController extends Controller
|
||||
{
|
||||
use HandlesImageUpload;
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => Slider::all()
|
||||
'data' => Slider::with('image')->get()->map(fn ($s) => $this->formatSlider($s))->values(),
|
||||
]);
|
||||
}
|
||||
|
||||
// Shape a slider so the (old) app parses it safely: description is always a
|
||||
// string, and action.type is normalized to 'navigation' or 'link' (the only
|
||||
// types the client understands) — unknown/empty actions become null.
|
||||
private function formatSlider(Slider $slider): array
|
||||
{
|
||||
return array_merge($slider->toArray(), [
|
||||
'description' => $slider->description ?? '',
|
||||
'action' => $this->normalizeAction($slider->action),
|
||||
]);
|
||||
}
|
||||
|
||||
private function normalizeAction($action): ?array
|
||||
{
|
||||
if (!is_array($action) || empty($action['type'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = $action['type'];
|
||||
|
||||
if (in_array($type, ['navigation', 'screen'], true)) {
|
||||
return ['type' => 'navigation', 'path' => $action['path'] ?? ($action['url'] ?? '')];
|
||||
}
|
||||
|
||||
if (in_array($type, ['link', 'url'], true)) {
|
||||
return ['type' => 'link', 'url' => $action['url'] ?? ($action['path'] ?? '')];
|
||||
}
|
||||
|
||||
return null; // unknown type → drop so the client doesn't throw
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
@@ -21,20 +54,25 @@ public function store(Request $request)
|
||||
'description' => 'nullable|string',
|
||||
'url' => 'nullable|string|max:500',
|
||||
'action' => 'nullable|array',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
$data['image_id'] = $this->uploadedImageId($request) ?? ($data['image_id'] ?? null);
|
||||
|
||||
$slider = Slider::create($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Slider created successfully',
|
||||
'data' => $slider
|
||||
'data' => $this->formatSlider($slider->load('image')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
return response()->json($slider);
|
||||
$slider = Slider::with('image')->findOrFail($id);
|
||||
return response()->json($this->formatSlider($slider));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
@@ -46,13 +84,20 @@ public function update(Request $request, $id)
|
||||
'description' => 'sometimes|string',
|
||||
'url' => 'sometimes|string|max:500',
|
||||
'action' => 'nullable|array',
|
||||
'image_id' => 'nullable|exists:images,id',
|
||||
'image' => 'nullable|file|extensions:jpg,jpeg,png,gif,webp,bmp,svg|max:8192',
|
||||
]);
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
if (($uploadedImageId = $this->uploadedImageId($request)) !== null) {
|
||||
$data['image_id'] = $uploadedImageId;
|
||||
}
|
||||
|
||||
$slider->update($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Slider updated successfully',
|
||||
'data' => $slider
|
||||
'data' => $this->formatSlider($slider->load('image')),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
use App\Models\SurveyAnswer;
|
||||
use App\Models\SurveyQuestion;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class SurveyQuestionController extends Controller
|
||||
@@ -56,6 +58,104 @@ public function adminShow($id)
|
||||
return response()->json($question);
|
||||
}
|
||||
|
||||
// ADMIN: paginated list of users with their survey stats (age, gender, answers count).
|
||||
public function adminUsers(Request $request)
|
||||
{
|
||||
$perPage = max(1, min((int) $request->input('per_page', 20), 100));
|
||||
$answered = $request->input('answered');
|
||||
|
||||
$query = User::select('id', 'first_name', 'last_name', 'age', 'gender', 'email', 'mobile', 'created_at', 'identifier')
|
||||
->withCount(['surveyAnswers as answers_count'])
|
||||
->withCount(['surveyAnswers as questions_answered' => function ($q) {
|
||||
$q->select(DB::raw('COUNT(DISTINCT survey_question_id)'));
|
||||
}])
|
||||
->orderByDesc('created_at');
|
||||
|
||||
if ($answered === '1') {
|
||||
$query->has('surveyAnswers');
|
||||
} elseif ($answered === '0') {
|
||||
$query->doesntHave('surveyAnswers');
|
||||
}
|
||||
|
||||
$users = $query->paginate($perPage);
|
||||
|
||||
return response()->json($users);
|
||||
}
|
||||
|
||||
// ADMIN: single user profile with all their survey answers grouped by question.
|
||||
// Accepts either local user ID or approagency identifier (UUID).
|
||||
public function adminUserShow($identifier)
|
||||
{
|
||||
$query = User::query()
|
||||
->select('id', 'first_name', 'last_name', 'age', 'gender', 'birthday', 'email', 'mobile', 'created_at')
|
||||
->withCount(['surveyAnswers as answers_count'])
|
||||
->withCount(['surveyAnswers as questions_answered' => function ($q) {
|
||||
$q->select(DB::raw('COUNT(DISTINCT survey_question_id)'));
|
||||
}]);
|
||||
|
||||
if (is_numeric($identifier)) {
|
||||
$query->where('id', $identifier);
|
||||
} else {
|
||||
$query->where('identifier', $identifier);
|
||||
}
|
||||
|
||||
$user = $query->first();
|
||||
|
||||
if (!$user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$answers = SurveyAnswer::where('user_id', $user->id)
|
||||
->with(['question.options', 'option'])
|
||||
->get()
|
||||
->groupBy('survey_question_id')
|
||||
->map(function ($group) {
|
||||
$question = $group->first()->question;
|
||||
return [
|
||||
'question_id' => $question->id,
|
||||
'question' => $question->question,
|
||||
'type' => $question->type,
|
||||
'answers' => $group->map(fn ($a) => [
|
||||
'option_id' => $a->survey_option_id,
|
||||
'label' => $a->option->label,
|
||||
])->values(),
|
||||
];
|
||||
})
|
||||
->values();
|
||||
|
||||
$user->survey_answers = $answers;
|
||||
|
||||
return response()->json($user);
|
||||
}
|
||||
|
||||
// ADMIN: update a user's profile fields from approagency data.
|
||||
public function adminUserUpdate(Request $request, $identifier)
|
||||
{
|
||||
if (is_numeric($identifier)) {
|
||||
$user = User::where('id', $identifier)->first();
|
||||
} else {
|
||||
$user = User::where('identifier', $identifier)->first();
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'first_name' => 'nullable|string',
|
||||
'last_name' => 'nullable|string',
|
||||
'age' => 'nullable|integer',
|
||||
'gender' => 'nullable|integer',
|
||||
'birthday' => 'nullable|string',
|
||||
'identifier' => 'nullable|string',
|
||||
'email' => 'nullable|email',
|
||||
]);
|
||||
|
||||
$user->update(array_filter($data, fn ($v) => !is_null($v)));
|
||||
|
||||
return response()->json($user);
|
||||
}
|
||||
|
||||
// ADMIN: clean aggregated results — per option vote counts & percentages, no raw rows.
|
||||
// Pass an $id for one question, omit it for all questions.
|
||||
public function adminAnalytics($id = null)
|
||||
@@ -193,48 +293,21 @@ public function destroy($id)
|
||||
return response()->json(['message' => 'Question deleted successfully']);
|
||||
}
|
||||
|
||||
// USER submits their answer(s) for a question.
|
||||
// USER submits their answer(s) for a single question.
|
||||
// An empty option_ids array (or omitting it) means "no answer" / skip.
|
||||
public function answer(Request $request, $id)
|
||||
{
|
||||
$question = SurveyQuestion::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'option_ids' => 'required|array|min:1',
|
||||
'option_ids' => 'nullable|array',
|
||||
'option_ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
$optionIds = array_values(array_unique($data['option_ids']));
|
||||
|
||||
// Every selected option must belong to this question.
|
||||
$validOptionIds = $question->options()->pluck('id')->all();
|
||||
if (array_diff($optionIds, $validOptionIds)) {
|
||||
throw ValidationException::withMessages([
|
||||
'option_ids' => ['One or more options do not belong to this question.'],
|
||||
]);
|
||||
}
|
||||
|
||||
// Enforce single vs multiple selection.
|
||||
if ($question->type === 'single' && count($optionIds) > 1) {
|
||||
throw ValidationException::withMessages([
|
||||
'option_ids' => ['This question allows only a single option.'],
|
||||
]);
|
||||
}
|
||||
|
||||
$userId = auth()->id();
|
||||
|
||||
DB::transaction(function () use ($question, $optionIds, $userId) {
|
||||
// Replace any previous answer for this user + question.
|
||||
$question->answers()->where('user_id', $userId)->delete();
|
||||
|
||||
$rows = array_map(fn ($optionId) => [
|
||||
'user_id' => $userId,
|
||||
'survey_question_id' => $question->id,
|
||||
'survey_option_id' => $optionId,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
], $optionIds);
|
||||
|
||||
$question->answers()->getRelated()->insert($rows);
|
||||
DB::transaction(function () use ($question, $data, $userId) {
|
||||
$this->syncAnswerFor($question, $data['option_ids'] ?? [], $userId);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
@@ -243,45 +316,166 @@ public function answer(Request $request, $id)
|
||||
]);
|
||||
}
|
||||
|
||||
// USER submits answers for many questions at once. Each item may carry an
|
||||
// empty option_ids (skip), and the whole answers array may be empty too.
|
||||
public function bulkAnswer(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'answers' => 'present|array',
|
||||
'answers.*.question_id' => 'required|integer|exists:survey_questions,id',
|
||||
'answers.*.option_ids' => 'nullable|array',
|
||||
'answers.*.option_ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
$userId = auth()->id();
|
||||
$items = $data['answers'] ?? [];
|
||||
|
||||
$questions = SurveyQuestion::with('options')
|
||||
->whereIn('id', collect($items)->pluck('question_id')->unique()->all())
|
||||
->get()
|
||||
->keyBy('id');
|
||||
|
||||
DB::transaction(function () use ($items, $questions, $userId) {
|
||||
foreach ($items as $item) {
|
||||
$question = $questions->get($item['question_id']);
|
||||
if (!$question) {
|
||||
continue;
|
||||
}
|
||||
$this->syncAnswerFor($question, $item['option_ids'] ?? [], $userId);
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Answers submitted successfully',
|
||||
'questions' => SurveyQuestion::with(['options', 'userAnswers'])
|
||||
->where('is_active', true)
|
||||
->orderBy('order')
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
// Validate and replace a single user's answer set for one question.
|
||||
// Empty $optionIds clears the answer (the user chose not to answer it).
|
||||
private function syncAnswerFor(SurveyQuestion $question, array $optionIds, int $userId): void
|
||||
{
|
||||
$optionIds = array_values(array_unique(array_map('intval', $optionIds)));
|
||||
|
||||
// Every selected option must belong to this question.
|
||||
$validOptionIds = $question->options()->pluck('id')->all();
|
||||
if (array_diff($optionIds, $validOptionIds)) {
|
||||
throw ValidationException::withMessages([
|
||||
'option_ids' => ["One or more options do not belong to question #{$question->id}."],
|
||||
]);
|
||||
}
|
||||
|
||||
// Enforce single vs multiple selection.
|
||||
if ($question->type === 'single' && count($optionIds) > 1) {
|
||||
throw ValidationException::withMessages([
|
||||
'option_ids' => ["Question #{$question->id} allows only a single option."],
|
||||
]);
|
||||
}
|
||||
|
||||
// Replace any previous answer for this user + question.
|
||||
$question->answers()->where('user_id', $userId)->delete();
|
||||
|
||||
if ($optionIds) {
|
||||
$now = now();
|
||||
$rows = array_map(fn ($optionId) => [
|
||||
'user_id' => $userId,
|
||||
'survey_question_id' => $question->id,
|
||||
'survey_option_id' => $optionId,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
], $optionIds);
|
||||
|
||||
$question->answers()->getRelated()->insert($rows);
|
||||
}
|
||||
}
|
||||
|
||||
// USER: suggest media based on the tags attached to the options this user has chosen.
|
||||
public function suggestedMedia(Request $request)
|
||||
{
|
||||
$userId = auth()->id();
|
||||
|
||||
$limit = (int) $request->input('limit', 20);
|
||||
$limit = max(1, min($limit, 100));
|
||||
|
||||
$answersQuery = SurveyAnswer::where('user_id', $userId);
|
||||
if ($request->filled('question_id')) {
|
||||
$answersQuery->where('survey_question_id', $request->question_id);
|
||||
}
|
||||
$optionIds = $answersQuery->pluck('survey_option_id');
|
||||
|
||||
if ($optionIds->isEmpty()) {
|
||||
return response()->json([]);
|
||||
// Tags behind the user's chosen options.
|
||||
$tagIds = $optionIds->isEmpty()
|
||||
? collect()
|
||||
: DB::table('survey_option_tag')
|
||||
->whereIn('survey_option_id', $optionIds)
|
||||
->pluck('tag_id')
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
// Visible to this user: public or their own.
|
||||
$visible = function ($q) use ($userId) {
|
||||
$q->where('visibility', 'public')->orWhere('user_id', $userId);
|
||||
};
|
||||
|
||||
$eager = ['image', 'detailImage', 'categories', 'subCategories', 'tags'];
|
||||
|
||||
$media = collect();
|
||||
|
||||
if ($tagIds->isNotEmpty()) {
|
||||
// 1) Media directly sharing the chosen tags, ranked by overlap.
|
||||
$tagMatched = Media::query()
|
||||
->whereHas('tags', fn ($q) => $q->whereIn('tags.id', $tagIds))
|
||||
->withCount(['tags as match_count' => fn ($q) => $q->whereIn('tags.id', $tagIds)])
|
||||
->where($visible)
|
||||
->with($eager)
|
||||
->orderByDesc('match_count')
|
||||
->orderByDesc('created_at')
|
||||
->get();
|
||||
|
||||
// 2) Broaden to "similar" media: same categories / sub-categories as
|
||||
// the tag-matched media (so a thinly-tagged catalog still surfaces
|
||||
// the rest of the topic, not just the one over-tagged item).
|
||||
$categoryIds = $tagMatched->pluck('categories')->flatten(1)->pluck('id')->unique()->values();
|
||||
$subCategoryIds = $tagMatched->pluck('subCategories')->flatten(1)->pluck('id')->unique()->values();
|
||||
|
||||
$similar = collect();
|
||||
if ($categoryIds->isNotEmpty() || $subCategoryIds->isNotEmpty()) {
|
||||
$similar = Media::query()
|
||||
->where($visible)
|
||||
->whereNotIn('id', $tagMatched->pluck('id'))
|
||||
->where(function ($q) use ($categoryIds, $subCategoryIds) {
|
||||
if ($categoryIds->isNotEmpty()) {
|
||||
$q->orWhereHas('categories', fn ($c) => $c->whereIn('categories.id', $categoryIds));
|
||||
}
|
||||
if ($subCategoryIds->isNotEmpty()) {
|
||||
$q->orWhereHas('subCategories', fn ($s) => $s->whereIn('sub_categories.id', $subCategoryIds));
|
||||
}
|
||||
})
|
||||
->with($eager)
|
||||
->orderByDesc('created_at')
|
||||
->get()
|
||||
->each(fn ($m) => $m->match_count = 0);
|
||||
}
|
||||
|
||||
$media = $tagMatched->concat($similar);
|
||||
}
|
||||
|
||||
// Collect the tags behind the chosen options.
|
||||
$tagIds = DB::table('survey_option_tag')
|
||||
->whereIn('survey_option_id', $optionIds)
|
||||
->pluck('tag_id')
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($tagIds->isEmpty()) {
|
||||
return response()->json([]);
|
||||
// Fallback (no answers / no tags / nothing matched): popular public media,
|
||||
// so the suggestions row is never empty.
|
||||
if ($media->isEmpty()) {
|
||||
$media = Media::query()
|
||||
->where($visible)
|
||||
->withCount('plays as plays_count')
|
||||
->with($eager)
|
||||
->orderByDesc('plays_count')
|
||||
->orderByDesc('created_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
// Media sharing those tags, ranked by how many of them match.
|
||||
$media = Media::query()
|
||||
->whereHas('tags', fn ($q) => $q->whereIn('tags.id', $tagIds))
|
||||
->withCount(['tags as match_count' => fn ($q) => $q->whereIn('tags.id', $tagIds)])
|
||||
->where(function ($q) use ($userId) {
|
||||
$q->where('visibility', 'public')->orWhere('user_id', $userId);
|
||||
})
|
||||
->with(['image', 'categories', 'subCategories', 'tags'])
|
||||
->orderByDesc('match_count')
|
||||
->orderByDesc('created_at')
|
||||
->get();
|
||||
|
||||
return response()->json($media);
|
||||
return response()->json($media->take($limit)->values());
|
||||
}
|
||||
|
||||
private function syncOptions(SurveyQuestion $question, array $options): void
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Theme;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ThemeController extends Controller
|
||||
{
|
||||
// List themes (for the scene theme picker and the app).
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Theme::query();
|
||||
|
||||
if (!$request->boolean('include_inactive')) {
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
return response()->json($query->orderBy('order')->get());
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json(Theme::findOrFail($id));
|
||||
}
|
||||
|
||||
// Edit an existing theme — typically its color map. The `key` is the stable
|
||||
// identifier the app maps against, so it is intentionally not editable here.
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$theme = Theme::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => 'sometimes|string|max:255',
|
||||
'colors' => 'sometimes|array',
|
||||
'colors.*' => 'nullable|string|max:32',
|
||||
'order' => 'sometimes|integer',
|
||||
'is_active' => 'sometimes|boolean',
|
||||
]);
|
||||
|
||||
$theme->update($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Theme updated successfully',
|
||||
'data' => $theme,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -44,10 +44,16 @@ public function loginV2(Request $request)
|
||||
$user = User::where('identifier', $response['uuid'])->first();
|
||||
}
|
||||
|
||||
// If not found, try by email
|
||||
if (!$user) {
|
||||
// Then by email — only when an email exists. (where('email', null) would
|
||||
// match an arbitrary mobile-only user and cross-link the wrong account.)
|
||||
if (!$user && !empty($response['email'])) {
|
||||
$user = User::where('email', $response['email'])->first();
|
||||
}
|
||||
|
||||
// Finally by mobile, so mobile-only users reconnect to their account
|
||||
if (!$user && !empty($response['mobile'])) {
|
||||
$user = User::where('mobile', $response['mobile'])->first();
|
||||
}
|
||||
$mobile = $response['mobile'] ?? null;
|
||||
|
||||
// If mobile already exists, set it null to avoid duplicate error
|
||||
@@ -60,18 +66,31 @@ public function loginV2(Request $request)
|
||||
'email' => $response['email'],
|
||||
'identifier' => $response['uuid'] ?? null,
|
||||
'password' => config('app.default_password'),
|
||||
// 'name' => trim(($response['first_name'] ?? '') . ' ' . ($response['last_name'] ?? '')),
|
||||
'mobile' => $mobile,
|
||||
'first_name' => $response['first_name'] ?? null,
|
||||
'last_name' => $response['last_name'] ?? null,
|
||||
'age' => $response['age'] ?? null,
|
||||
'gender' => $response['gender'] ?? null,
|
||||
'birthday' => $response['birthday'] ?? null,
|
||||
'referral_code' => $response['referral_code'] ?? null,
|
||||
]);
|
||||
} else {
|
||||
// Only update name and mobile for existing user
|
||||
$user->first_name = $response['first_name'] ?? $user->first_name;
|
||||
$user->last_name = $response['last_name'] ?? $user->last_name;
|
||||
// $user->name = trim(($response['first_name'] ?? '') . ' ' . ($response['last_name'] ?? ''));
|
||||
// Keep the local identifier aligned with the current approagency uuid
|
||||
// (e.g. when the user was matched by mobile, not identifier).
|
||||
$user->identifier = $response['uuid'] ?? $user->identifier;
|
||||
|
||||
// Sync names — update if the response has a non-null, non-empty value
|
||||
if (!empty($response['first_name'])) {
|
||||
$user->first_name = $response['first_name'];
|
||||
}
|
||||
if (!empty($response['last_name'])) {
|
||||
$user->last_name = $response['last_name'];
|
||||
}
|
||||
|
||||
$user->mobile = $mobile ?? $user->mobile;
|
||||
$user->age = $response['age'] ?? $user->age;
|
||||
$user->gender = $response['gender'] ?? $user->gender;
|
||||
$user->birthday = $response['birthday'] ?? $user->birthday;
|
||||
$user->referral_code = $response['referral_code'] ?? $user->referral_code;
|
||||
$user->save();
|
||||
}
|
||||
@@ -92,6 +111,7 @@ public function loginV2(Request $request)
|
||||
'identifier' => $user->identifier,
|
||||
'token' => $access_token,
|
||||
'user' => $user,
|
||||
'status' => $response,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -105,6 +125,9 @@ private function syncUserFromStatus(array $response, ?User $user = null): User
|
||||
if (!$user && !empty($response['email'])) {
|
||||
$user = User::where('email', $response['email'])->first();
|
||||
}
|
||||
if (!$user && !empty($response['mobile'])) {
|
||||
$user = User::where('mobile', $response['mobile'])->first();
|
||||
}
|
||||
}
|
||||
|
||||
$mobile = $response['mobile'] ?? null;
|
||||
@@ -121,14 +144,27 @@ private function syncUserFromStatus(array $response, ?User $user = null): User
|
||||
'mobile' => $mobile,
|
||||
'first_name' => $response['first_name'] ?? null,
|
||||
'last_name' => $response['last_name'] ?? null,
|
||||
'age' => $response['age'] ?? null,
|
||||
'gender' => $response['gender'] ?? null,
|
||||
'birthday' => $response['birthday'] ?? null,
|
||||
'referral_code' => $response['referral_code'] ?? null,
|
||||
'email_verified_at' => $response['email_verified_at'] ?? null
|
||||
]);
|
||||
} else {
|
||||
// update existing
|
||||
$user->first_name = $response['first_name'] ?? $user->first_name;
|
||||
$user->last_name = $response['last_name'] ?? $user->last_name;
|
||||
$user->identifier = $response['uuid'] ?? $user->identifier;
|
||||
|
||||
if (!empty($response['first_name'])) {
|
||||
$user->first_name = $response['first_name'];
|
||||
}
|
||||
if (!empty($response['last_name'])) {
|
||||
$user->last_name = $response['last_name'];
|
||||
}
|
||||
|
||||
$user->mobile = $mobile ?? $user->mobile;
|
||||
$user->age = $response['age'] ?? $user->age;
|
||||
$user->gender = $response['gender'] ?? $user->gender;
|
||||
$user->birthday = $response['birthday'] ?? $user->birthday;
|
||||
$user->referral_code = $response['referral_code'] ?? $user->referral_code;
|
||||
$user->email_verified_at = $response['email_verified_at'] ?? $user->email_verified_at;
|
||||
$user->save();
|
||||
@@ -500,6 +536,7 @@ public function updateProfile(Request $request)
|
||||
'first_name' => 'string|nullable',
|
||||
'last_name' => 'string|nullable',
|
||||
'birthday' => 'date|nullable',
|
||||
'age' => 'integer|nullable|min:0|max:120',
|
||||
'gender' => ['integer', 'nullable', Rule::in(User::GENDERS)],
|
||||
'email' => 'email|nullable',
|
||||
'mobile' => [new MobileNumber, 'string'],
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Announcement extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'image_id', 'title', 'description', 'link', 'button_text', 'start_date', 'end_date',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'datetime',
|
||||
'end_date' => 'datetime',
|
||||
];
|
||||
|
||||
public function image(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Image::class);
|
||||
}
|
||||
|
||||
// Currently within its [start_date, end_date] window (null bounds = open-ended).
|
||||
public function scopeActive($query)
|
||||
{
|
||||
$now = now();
|
||||
|
||||
return $query
|
||||
->where(fn ($q) => $q->whereNull('start_date')->orWhere('start_date', '<=', $now))
|
||||
->where(fn ($q) => $q->whereNull('end_date')->orWhere('end_date', '>=', $now));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AppVersion extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'image_id', 'title', 'description', 'version_name', 'version_code', 'link', 'button_text',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'version_code' => 'integer',
|
||||
];
|
||||
|
||||
public function image(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Image::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BreathingColor extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'colors', 'order', 'is_active'];
|
||||
|
||||
protected $casts = [
|
||||
'colors' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
}
|
||||
@@ -8,12 +8,17 @@
|
||||
class BreathingTemplate extends Model
|
||||
{
|
||||
use HasSaves;
|
||||
protected $fillable = ['user_id', 'name', 'inhale', 'exhale', 'breath_hold' , 'duration' , 'description','image_id' , 'source'];
|
||||
protected $fillable = ['user_id', 'name', 'inhale', 'exhale', 'breath_hold' , 'duration' , 'description','image_id' , 'source', 'breathing_color_id'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function breathingColor()
|
||||
{
|
||||
return $this->belongsTo(BreathingColor::class);
|
||||
}
|
||||
protected $appends = ['image_url', 'is_saved','saved_count'];
|
||||
|
||||
public function getImageUrlAttribute()
|
||||
|
||||
+15
-1
@@ -6,7 +6,21 @@
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'description', 'icon'];
|
||||
public const TYPE_MEDIA = 'media';
|
||||
public const TYPE_PLAYLIST = 'playlist';
|
||||
public const TYPE_BREATHING_TEMPLATE = 'breathing_template';
|
||||
|
||||
public const TYPES = [
|
||||
self::TYPE_MEDIA,
|
||||
self::TYPE_PLAYLIST,
|
||||
self::TYPE_BREATHING_TEMPLATE,
|
||||
];
|
||||
|
||||
protected $fillable = ['name', 'type', 'order', 'description', 'icon'];
|
||||
|
||||
protected $casts = [
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
protected $appends = ['icon_url'];
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Faq extends Model
|
||||
{
|
||||
protected $fillable = ['faq_category_id', 'question', 'answer', 'order', 'is_active'];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(FaqCategory::class, 'faq_category_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class FaqCategory extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'order', 'is_active'];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
public function faqs(): HasMany
|
||||
{
|
||||
return $this->hasMany(Faq::class)->orderBy('order');
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -89,14 +89,6 @@ public function getUrlAttribute()
|
||||
|
||||
return $this->external_url;
|
||||
}
|
||||
|
||||
|
||||
public function getIsSavedAttribute()
|
||||
{
|
||||
if (!auth()->check()) return false;
|
||||
|
||||
return $this->savedBy()
|
||||
->where('user_id', auth()->id())
|
||||
->exists();
|
||||
}
|
||||
// is_saved / saved_count come from the HasSaves trait (saved_items table),
|
||||
// so the /saves/* endpoints and the media list/show all agree.
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany; // ← Add this
|
||||
class MusicCategory extends Model
|
||||
{
|
||||
// Static type so playlist categories are tagged like media categories.
|
||||
public const TYPE = 'playlist';
|
||||
|
||||
protected $table = 'music_categories';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -19,6 +22,13 @@ class MusicCategory extends Model
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
protected $appends = ['type'];
|
||||
|
||||
public function getTypeAttribute(): string
|
||||
{
|
||||
return self::TYPE;
|
||||
}
|
||||
|
||||
public function playlists(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(MusicPlaylist::class, 'music_category_playlist', 'category_id', 'playlist_id');
|
||||
|
||||
@@ -9,17 +9,19 @@
|
||||
use App\Traits\HasComments; // Add this
|
||||
use App\Traits\HasLikes;
|
||||
use App\Traits\HasSaves;
|
||||
use App\Traits\HasRatings;
|
||||
class MusicPlaylist extends Model
|
||||
{
|
||||
use HasComments, HasLikes, HasSaves;
|
||||
use HasComments, HasLikes, HasSaves, HasRatings;
|
||||
protected $table = 'music_playlists';
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'slug', 'description', 'image_id', 'detail_image_id', 'order', 'is_active'
|
||||
'name', 'slug', 'description', 'image_id', 'detail_image_id', 'order', 'is_active', 'is_premium'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'is_premium' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
protected $appends = [
|
||||
@@ -30,7 +32,8 @@ class MusicPlaylist extends Model
|
||||
'is_liked',
|
||||
'likes_count',
|
||||
'is_saved',
|
||||
'saved_count'
|
||||
'saved_count',
|
||||
'duration',
|
||||
];
|
||||
public function categories(): BelongsToMany
|
||||
{
|
||||
@@ -70,4 +73,10 @@ public function getTotalDurationAttribute()
|
||||
{
|
||||
return $this->musics()->where('music.is_active', true)->sum('music.duration');
|
||||
}
|
||||
|
||||
// Total play time of the playlist = sum of its active musics' durations.
|
||||
public function getDurationAttribute()
|
||||
{
|
||||
return $this->total_duration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,23 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Scene extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'image_path', 'video_path', 'sound_path', 'order', 'is_active'];
|
||||
protected $fillable = ['theme_id', 'name', 'image_path', 'video_path', 'sound_path', 'order', 'is_active', 'is_premium'];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'is_premium' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
public function theme(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Theme::class);
|
||||
}
|
||||
|
||||
protected $appends = ['image_url', 'video_url', 'sound_url', 'has_video'];
|
||||
|
||||
public function getImageUrlAttribute(): ?string
|
||||
|
||||
@@ -3,12 +3,18 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Slider extends Model
|
||||
{
|
||||
protected $fillable = ['title', 'description', 'url','action'];
|
||||
protected $fillable = ['title', 'description', 'url', 'action', 'image_id'];
|
||||
|
||||
protected $casts = [
|
||||
'action' => 'array', // auto convert JSON to array
|
||||
];
|
||||
|
||||
public function image(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Image::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Theme extends Model
|
||||
{
|
||||
protected $fillable = ['key', 'name', 'colors', 'order', 'is_active'];
|
||||
|
||||
protected $casts = [
|
||||
'colors' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
public function scenes(): HasMany
|
||||
{
|
||||
return $this->hasMany(Scene::class);
|
||||
}
|
||||
}
|
||||
@@ -143,4 +143,9 @@ public function savedMedia()
|
||||
return $this->belongsToMany(Media::class, 'saved_media')->withTimestamps();
|
||||
}
|
||||
|
||||
public function surveyAnswers()
|
||||
{
|
||||
return $this->hasMany(SurveyAnswer::class);
|
||||
}
|
||||
|
||||
}
|
||||
+22
-14
@@ -3,7 +3,6 @@
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\SavedItem;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
trait HasSaves
|
||||
{
|
||||
@@ -14,11 +13,7 @@ public function saves()
|
||||
|
||||
public function getIsSavedAttribute()
|
||||
{
|
||||
if (!auth()->check()) return false;
|
||||
|
||||
return $this->saves()
|
||||
->where('user_id', auth()->id())
|
||||
->exists();
|
||||
return $this->isSavedByAuthUser();
|
||||
}
|
||||
|
||||
public function getSavedCountAttribute()
|
||||
@@ -26,20 +21,31 @@ public function getSavedCountAttribute()
|
||||
return $this->saves()->count();
|
||||
}
|
||||
|
||||
// Check the saves() relation directly (not the is_saved attribute, which a
|
||||
// model may override to point at a different table — e.g. Media), so toggle
|
||||
// always decides against the same table it writes to.
|
||||
protected function isSavedByAuthUser(): bool
|
||||
{
|
||||
if (!auth()->check()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->saves()->where('user_id', auth()->id())->exists();
|
||||
}
|
||||
|
||||
public function toggleSaveStatus()
|
||||
{
|
||||
if ($this->getIsSavedAttribute()) {
|
||||
return $this->removeSave();
|
||||
} else {
|
||||
return $this->addSave();
|
||||
}
|
||||
return $this->isSavedByAuthUser() ? $this->removeSave() : $this->addSave();
|
||||
}
|
||||
|
||||
public function addSave()
|
||||
{
|
||||
if ($this->getIsSavedAttribute()) return false;
|
||||
if (!auth()->check()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return SavedItem::create([
|
||||
// Idempotent: never inserts a duplicate even on repeated/racing calls.
|
||||
return SavedItem::firstOrCreate([
|
||||
'user_id' => auth()->id(),
|
||||
'saveable_id' => $this->id,
|
||||
'saveable_type' => get_class($this),
|
||||
@@ -48,7 +54,9 @@ public function addSave()
|
||||
|
||||
public function removeSave()
|
||||
{
|
||||
if (!$this->getIsSavedAttribute()) return false;
|
||||
if (!auth()->check()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return SavedItem::where([
|
||||
'user_id' => auth()->id(),
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('users', 'age')) {
|
||||
$table->unsignedTinyInteger('age')->nullable()->after('birthday');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('users', 'age')) {
|
||||
$table->dropColumn('age');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
// General category type: media | playlist | breathing_template
|
||||
$table->string('type')->default('media')->after('name')->index();
|
||||
});
|
||||
|
||||
// Existing categories were used for media content.
|
||||
DB::table('categories')->update(['type' => 'media']);
|
||||
|
||||
// Name is unique per type (same name may exist for media and playlist).
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->dropUnique('categories_name_unique');
|
||||
$table->unique(['name', 'type']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->dropUnique(['name', 'type']);
|
||||
$table->unique('name');
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('themes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key')->unique(); // blue, pink, green, orange, purple
|
||||
$table->string('name'); // display label
|
||||
$table->json('colors'); // full color map (json works on MySQL & Postgres)
|
||||
$table->integer('order')->default(0);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('themes');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('scenes', function (Blueprint $table) {
|
||||
$table->foreignId('theme_id')->nullable()->after('id')
|
||||
->constrained('themes')->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('scenes', function (Blueprint $table) {
|
||||
$table->dropForeign(['theme_id']);
|
||||
$table->dropColumn('theme_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('scenes', function (Blueprint $table) {
|
||||
$table->boolean('is_premium')->default(false)->after('is_active');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('scenes', function (Blueprint $table) {
|
||||
$table->dropColumn('is_premium');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('breathing_templates', function (Blueprint $table) {
|
||||
// One or more hex colors: a single solid color or a gradient.
|
||||
$table->json('colors')->nullable()->after('image_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('breathing_templates', function (Blueprint $table) {
|
||||
$table->dropColumn('colors');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('breathing_colors', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->nullable();
|
||||
$table->json('colors'); // one hex (solid) or several (gradient)
|
||||
$table->integer('order')->default(0);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('breathing_colors');
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('breathing_templates', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('breathing_templates', 'colors')) {
|
||||
$table->dropColumn('colors');
|
||||
}
|
||||
$table->foreignId('breathing_color_id')->nullable()->after('image_id')
|
||||
->constrained('breathing_colors')->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('breathing_templates', function (Blueprint $table) {
|
||||
$table->dropForeign(['breathing_color_id']);
|
||||
$table->dropColumn('breathing_color_id');
|
||||
$table->json('colors')->nullable();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('faq_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->integer('order')->default(0);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('faq_categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('faqs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('faq_category_id')->constrained('faq_categories')->cascadeOnDelete();
|
||||
$table->string('question');
|
||||
$table->text('answer');
|
||||
$table->integer('order')->default(0);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('faqs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sliders', function (Blueprint $table) {
|
||||
$table->foreignId('image_id')->nullable()->after('id')
|
||||
->constrained('images')->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sliders', function (Blueprint $table) {
|
||||
$table->dropForeign(['image_id']);
|
||||
$table->dropColumn('image_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('music_playlists', function (Blueprint $table) {
|
||||
$table->boolean('is_premium')->default(false)->after('is_active');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('music_playlists', function (Blueprint $table) {
|
||||
$table->dropColumn('is_premium');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('announcements', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('image_id')->nullable()->constrained('images')->nullOnDelete();
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->string('link')->nullable();
|
||||
$table->dateTime('start_date')->nullable();
|
||||
$table->dateTime('end_date')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('announcements');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('app_versions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('image_id')->nullable()->constrained('images')->nullOnDelete();
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->string('version_name'); // e.g. "1.2.0"
|
||||
$table->unsignedInteger('version_code'); // monotonic build number, e.g. 42
|
||||
$table->string('link')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('app_versions');
|
||||
}
|
||||
};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('announcements', function (Blueprint $table) {
|
||||
$table->string('button_text')->nullable()->after('link');
|
||||
});
|
||||
|
||||
Schema::table('app_versions', function (Blueprint $table) {
|
||||
$table->string('button_text')->nullable()->after('link');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('announcements', function (Blueprint $table) {
|
||||
$table->dropColumn('button_text');
|
||||
});
|
||||
|
||||
Schema::table('app_versions', function (Blueprint $table) {
|
||||
$table->dropColumn('button_text');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->integer('order')->default(0)->after('type')->index();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->dropColumn('order');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\BreathingColor;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class BreathingColorSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$colors = [
|
||||
['name' => 'آبی', 'order' => 1, 'colors' => ['#3ABDEB', '#553AEB']],
|
||||
['name' => 'صورتی', 'order' => 2, 'colors' => ['#CE4299', '#8628FF']],
|
||||
['name' => 'سبز', 'order' => 3, 'colors' => ['#5CC65C', '#00A489']],
|
||||
['name' => 'نارنجی', 'order' => 4, 'colors' => ['#E2990A', '#CC4B1C']],
|
||||
['name' => 'بنفش', 'order' => 5, 'colors' => ['#6829DD', '#1A50CC']],
|
||||
['name' => 'تکرنگ', 'order' => 6, 'colors' => ['#5360FC']],
|
||||
];
|
||||
|
||||
foreach ($colors as $c) {
|
||||
BreathingColor::firstOrCreate(['name' => $c['name']], $c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Theme;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ThemeSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$common = [
|
||||
'bgPrimary' => '#26000000',
|
||||
'bgSecondary' => '#33000000',
|
||||
'bgTertiary' => '#40000000',
|
||||
'bgFourth' => '#80000000',
|
||||
'bgBlack' => '#99000000',
|
||||
'bgWhite' => '#FFF7F7F7',
|
||||
'bgError' => '#FFF04438',
|
||||
'fgPrimary' => '#FFFFFFFF',
|
||||
'fgSecondary' => '#FFD9D9D9',
|
||||
'fgDisable' => '#FFC0C0C0',
|
||||
'fgBlack' => '#FF000000',
|
||||
'fgBlack2' => '#FF2F2F2F',
|
||||
'fgError' => '#FFF04438',
|
||||
'textPrimary' => '#FFFFFFFF',
|
||||
'textSecondary' => '#FFD9D9D9',
|
||||
'textDisable' => '#FFC0C0C0',
|
||||
'textPrimaryReverse' => '#FF000000',
|
||||
'textPrimaryReverse2' => '#FF2F2F2F',
|
||||
'textError' => '#FFF04438',
|
||||
'borderPrimary' => '#26FFFFFF',
|
||||
'borderSecondary' => '#40FFFFFF',
|
||||
'borderWhite' => '#FFFFFFFF',
|
||||
'borderBlack' => '#FF000000',
|
||||
'borderError' => '#FFF04438',
|
||||
];
|
||||
|
||||
$themes = [
|
||||
[
|
||||
'key' => 'blue',
|
||||
'name' => 'آبی',
|
||||
'order' => 1,
|
||||
'colors' => array_merge($common, [
|
||||
'themeUp' => '#156395',
|
||||
'themeDown' => '#2E3381',
|
||||
'bottomNavigation' => '#292E74',
|
||||
'lightColorGradient' => '#3ABDEB',
|
||||
'darkColorGradient' => '#553AEB',
|
||||
'chatContainer' => '#252967',
|
||||
'bottomPlayerContainer' => '#252967',
|
||||
'bgBrand' => '#5360FC',
|
||||
'fgBrand' => '#5360FC',
|
||||
'textBrand' => '#5360FC',
|
||||
'borderBrand' => '#5360FC',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'key' => 'pink',
|
||||
'name' => 'صورتی',
|
||||
'order' => 2,
|
||||
'colors' => array_merge($common, [
|
||||
'themeUp' => '#843F6A',
|
||||
'themeDown' => '#4F366F',
|
||||
'bottomNavigation' => '#3F2B59',
|
||||
'lightColorGradient' => '#CE4299',
|
||||
'darkColorGradient' => '#8628FF',
|
||||
'chatContainer' => '#3F2B59',
|
||||
'bottomPlayerContainer' => '#3F2B59',
|
||||
'bgBrand' => '#843F6A',
|
||||
'fgBrand' => '#843F6A',
|
||||
'textBrand' => '#FFFF80AB',
|
||||
'borderBrand' => '#843F6A',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'key' => 'green',
|
||||
'name' => 'سبز',
|
||||
'order' => 3,
|
||||
'colors' => array_merge($common, [
|
||||
'themeUp' => '#3B6D3B',
|
||||
'themeDown' => '#064A3F',
|
||||
'bottomNavigation' => '#054339',
|
||||
'lightColorGradient' => '#5CC65C',
|
||||
'darkColorGradient' => '#00A489',
|
||||
'chatContainer' => '#053B32',
|
||||
'bottomPlayerContainer' => '#053B32',
|
||||
'bgBrand' => '#3B6D3B',
|
||||
'fgBrand' => '#3B6D3B',
|
||||
'textBrand' => '#4CAF50',
|
||||
'borderBrand' => '#3B6D3B',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'key' => 'orange',
|
||||
'name' => 'نارنجی',
|
||||
'order' => 4,
|
||||
'colors' => array_merge($common, [
|
||||
'themeUp' => '#7E5607',
|
||||
'themeDown' => '#81381D',
|
||||
'bottomNavigation' => '#74321A',
|
||||
'lightColorGradient' => '#E2990A',
|
||||
'darkColorGradient' => '#CC4B1C',
|
||||
'chatContainer' => '#672D17',
|
||||
'bottomPlayerContainer' => '#672D17',
|
||||
'bgBrand' => '#7E5607',
|
||||
'fgBrand' => '#7E5607',
|
||||
'textBrand' => '#FFE2990A',
|
||||
'borderBrand' => '#7E5607',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'key' => 'purple',
|
||||
'name' => 'بنفش',
|
||||
'order' => 5,
|
||||
'colors' => array_merge($common, [
|
||||
'themeUp' => '#371F63',
|
||||
'themeDown' => '#132F6F',
|
||||
'bottomNavigation' => '#112A64',
|
||||
'lightColorGradient' => '#6829DD',
|
||||
'darkColorGradient' => '#1A50CC',
|
||||
'chatContainer' => '#0F2659',
|
||||
'bottomPlayerContainer' => '#0F2659',
|
||||
'bgBrand' => '#371F63',
|
||||
'fgBrand' => '#371F63',
|
||||
'textBrand' => '#1A50CC',
|
||||
'borderBrand' => '#371F63',
|
||||
]),
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($themes as $theme) {
|
||||
Theme::updateOrCreate(['key' => $theme['key']], $theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
+61
-1
@@ -4,6 +4,7 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use App\Http\Controllers\BreathingExerciseController;
|
||||
use App\Http\Controllers\BreathingColorController;
|
||||
use App\Http\Controllers\PackageNameController;
|
||||
use App\Http\Controllers\ProductController;
|
||||
use App\Http\Controllers\BreathingTemplate;
|
||||
@@ -14,8 +15,13 @@
|
||||
use App\Http\Controllers\SurveyQuestionController;
|
||||
use App\Http\Controllers\ChatTopicController;
|
||||
use App\Http\Controllers\AppFeedbackController;
|
||||
use App\Http\Controllers\FaqController;
|
||||
use App\Http\Controllers\FaqCategoryController;
|
||||
use App\Http\Controllers\SliderController;
|
||||
use App\Http\Controllers\AnnouncementController;
|
||||
use App\Http\Controllers\AppVersionController;
|
||||
use App\Http\Controllers\SceneController;
|
||||
use App\Http\Controllers\ThemeController;
|
||||
use App\Http\Controllers\BellSoundController;
|
||||
use App\Http\Controllers\BackgroundSoundController;
|
||||
use App\Http\Controllers\TimerPresetController;
|
||||
@@ -31,6 +37,7 @@
|
||||
use App\Http\Controllers\MusicSubcategoryController;
|
||||
use App\Http\Controllers\SaveController;
|
||||
use App\Http\Controllers\LikeController;
|
||||
use App\Http\Controllers\InteractionController;
|
||||
|
||||
Route::get('/test-hash', function() {
|
||||
$plain = 'amnk1380';
|
||||
@@ -107,6 +114,9 @@
|
||||
Route::get('user-templates', [BreathingExerciseController::class, 'getUserTemplates']);
|
||||
Route::get('breathing-sessions', [BreathingExerciseController::class, 'getSessions']);
|
||||
|
||||
// Breathing color palette (app reads it to pick a template color; admin manages it).
|
||||
Route::apiResource('breathing-colors', BreathingColorController::class);
|
||||
|
||||
/// worry box feature
|
||||
Route::prefix('worries')->controller(WorryController::class)->group(function () {
|
||||
Route::post('/', 'store'); // Create worry + note
|
||||
@@ -130,6 +140,15 @@
|
||||
Route::apiResource('chat-topics', ChatTopicController::class);
|
||||
|
||||
|
||||
/// FAQ (سوالات متداول) — app reads grouped /faqs; admin manages categories & items
|
||||
Route::get('/faqs', [FaqController::class, 'index']); // app: categories + their questions
|
||||
Route::apiResource('faq-categories', FaqCategoryController::class);
|
||||
Route::post('/faqs', [FaqController::class, 'store']);
|
||||
Route::get('/faqs/{id}', [FaqController::class, 'show']);
|
||||
Route::put('/faqs/{id}', [FaqController::class, 'update']);
|
||||
Route::delete('/faqs/{id}', [FaqController::class, 'destroy']);
|
||||
|
||||
|
||||
/// app feedback — ideas & reviews (نظرات و ایدهها)
|
||||
Route::get('/app-feedback', [AppFeedbackController::class, 'mine']);
|
||||
Route::post('/app-feedback', [AppFeedbackController::class, 'store']);
|
||||
@@ -147,9 +166,14 @@
|
||||
Route::get('/admin/survey-questions/{id}/analytics', [SurveyQuestionController::class, 'adminAnalytics']);
|
||||
Route::get('/admin/survey-questions', [SurveyQuestionController::class, 'adminIndex']);
|
||||
Route::get('/admin/survey-questions/{id}', [SurveyQuestionController::class, 'adminShow']);
|
||||
// User list + detail for survey admin
|
||||
Route::get('/admin/survey-users', [SurveyQuestionController::class, 'adminUsers']);
|
||||
Route::get('/admin/survey-users/{id}', [SurveyQuestionController::class, 'adminUserShow']);
|
||||
Route::patch('/admin/survey-users/{id}', [SurveyQuestionController::class, 'adminUserUpdate']);
|
||||
});
|
||||
// User: answer + read questions with their own answers only.
|
||||
Route::get('/survey-questions/suggested-media', [SurveyQuestionController::class, 'suggestedMedia']);
|
||||
Route::post('/survey-questions/answers', [SurveyQuestionController::class, 'bulkAnswer']);
|
||||
Route::post('/survey-questions/{id}/answer', [SurveyQuestionController::class, 'answer']);
|
||||
Route::apiResource('survey-questions', SurveyQuestionController::class);
|
||||
|
||||
@@ -176,9 +200,34 @@
|
||||
Route::get('/slider', [SliderController::class, 'index']); // list all sliders
|
||||
Route::post('/slider', [SliderController::class, 'store']); // create slider
|
||||
Route::get('/slider/{id}', [SliderController::class, 'show']); // get single slider
|
||||
Route::put('/slider/{id}', [SliderController::class, 'update']); // update slider
|
||||
Route::put('/slider/{id}', [SliderController::class, 'update']); // update slider (json)
|
||||
Route::post('/slider/{id}', [SliderController::class, 'update']); // update slider (multipart: image upload)
|
||||
Route::delete('/slider/{id}', [SliderController::class, 'destroy']); // delete slider
|
||||
|
||||
/// announcements
|
||||
Route::get('/announcements/latest', [AnnouncementController::class, 'latest']); // single latest active (app)
|
||||
Route::get('/announcements', [AnnouncementController::class, 'index']); // list all (admin)
|
||||
Route::post('/announcements', [AnnouncementController::class, 'store']); // create
|
||||
Route::get('/announcements/{id}', [AnnouncementController::class, 'show']); // single
|
||||
Route::put('/announcements/{id}', [AnnouncementController::class, 'update']); // update (json)
|
||||
Route::post('/announcements/{id}', [AnnouncementController::class, 'update']); // update (multipart: image)
|
||||
Route::delete('/announcements/{id}', [AnnouncementController::class, 'destroy']); // delete
|
||||
|
||||
/// app versions
|
||||
Route::get('/versions/latest', [AppVersionController::class, 'latest']); // newest version (app update check)
|
||||
Route::get('/versions', [AppVersionController::class, 'index']); // list all (admin)
|
||||
Route::post('/versions', [AppVersionController::class, 'store']); // create
|
||||
Route::get('/versions/{id}', [AppVersionController::class, 'show']); // single
|
||||
Route::put('/versions/{id}', [AppVersionController::class, 'update']); // update (json)
|
||||
Route::post('/versions/{id}', [AppVersionController::class, 'update']); // update (multipart: image)
|
||||
Route::delete('/versions/{id}', [AppVersionController::class, 'destroy']); // delete
|
||||
|
||||
|
||||
/// themes (color themes a scene can use)
|
||||
Route::get('/themes', [ThemeController::class, 'index']);
|
||||
Route::get('/themes/{id}', [ThemeController::class, 'show']);
|
||||
Route::put('/themes/{id}', [ThemeController::class, 'update']); // edit name / colors / order / active
|
||||
Route::post('/themes/{id}', [ThemeController::class, 'update']); // same, for method-spoofed clients
|
||||
|
||||
/// scenes (تنظیمات صحنه) — each scene has an image, optional video, and sound
|
||||
// Consolidated settings screen (all scenes + current user's preferences) in one call.
|
||||
@@ -221,7 +270,9 @@
|
||||
|
||||
///media
|
||||
Route::get('/media/filters', [MediaController::class, 'filters']);
|
||||
Route::get('/media/search', [MediaController::class, 'search']);
|
||||
Route::get('/media/popular', [MediaController::class, 'popular']);
|
||||
Route::get('/media/newest', [MediaController::class, 'newest']);
|
||||
Route::get('/media/recently-played', [MediaController::class, 'recentlyPlayed']);
|
||||
Route::post('/media', [MediaController::class, 'store']);
|
||||
Route::get('/media', [MediaController::class, 'index']);
|
||||
@@ -240,6 +291,8 @@
|
||||
Route::post('/media/{id}/note', [MediaController::class, 'storeNote']);
|
||||
|
||||
// Media categories
|
||||
// Category with its sub-categories, each carrying its medias.
|
||||
Route::get('categories/{id}/grouped', [CategoryController::class, 'grouped']);
|
||||
// Explicit POST update so an icon image can be uploaded (multipart can't ride a PUT).
|
||||
Route::post('categories/{id}', [CategoryController::class, 'update']);
|
||||
Route::apiResource('categories', CategoryController::class);
|
||||
@@ -251,6 +304,10 @@
|
||||
|
||||
|
||||
// Music Categories
|
||||
// Category with its sub-categories, each carrying its playlists.
|
||||
Route::get('music-categories/{id}/grouped', [MusicCategoryController::class, 'grouped']);
|
||||
// Explicit POST update so an image can be uploaded (multipart can't ride a PUT).
|
||||
Route::post('music-categories/{id}', [MusicCategoryController::class, 'update']);
|
||||
Route::apiResource('music-categories', MusicCategoryController::class);
|
||||
Route::get('public/music-categories', [MusicCategoryController::class, 'index']);
|
||||
|
||||
@@ -306,6 +363,9 @@
|
||||
});
|
||||
|
||||
|
||||
// Combined comment + like in one request (music / media / playlist)
|
||||
Route::post('interactions/{type}/{id}', [InteractionController::class, 'store']);
|
||||
|
||||
// Like routes (only for music and media)
|
||||
Route::prefix('likes')->group(function () {
|
||||
Route::post('/like', [LikeController::class, 'like']);
|
||||
|
||||
Reference in New Issue
Block a user