messages implemented
This commit is contained in:
33
app/Http/Controllers/Dashboard/DashboardAwardsController.php
Normal file
33
app/Http/Controllers/Dashboard/DashboardAwardsController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardAwardsController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$artworks = Artwork::query()
|
||||
->where('user_id', (int) $user->id)
|
||||
->whereHas('awards')
|
||||
->with(['awardStat', 'stats', 'categories.contentType'])
|
||||
->orderByDesc(
|
||||
\App\Models\ArtworkAwardStat::select('score_total')
|
||||
->whereColumn('artwork_id', 'artworks.id')
|
||||
->limit(1)
|
||||
)
|
||||
->paginate(24)
|
||||
->withQueryString();
|
||||
|
||||
return view('dashboard.awards', [
|
||||
'artworks' => $artworks,
|
||||
'page_title' => 'My Awards – SkinBase',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use App\Services\UserStatsService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -17,23 +18,10 @@ class FavoriteController extends Controller
|
||||
$user = $request->user();
|
||||
$perPage = 20;
|
||||
|
||||
$favTable = DB::getSchemaBuilder()->hasTable('user_favorites') ? 'user_favorites' : (DB::getSchemaBuilder()->hasTable('favourites') ? 'favourites' : null);
|
||||
if (! $favTable) {
|
||||
return view('dashboard.favorites', ['artworks' => new LengthAwarePaginator([], 0, $perPage)]);
|
||||
}
|
||||
|
||||
$favTable = 'artwork_favourites';
|
||||
$sort = $request->query('sort', 'newest');
|
||||
$order = $sort === 'oldest' ? 'asc' : 'desc';
|
||||
|
||||
// Determine a column to order by (legacy 'datum' or modern timestamps)
|
||||
$schema = DB::getSchemaBuilder();
|
||||
$orderColumn = null;
|
||||
foreach (['datum', 'created_at', 'created', 'date'] as $col) {
|
||||
if ($schema->hasColumn($favTable, $col)) {
|
||||
$orderColumn = $col;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$orderColumn = 'created_at';
|
||||
|
||||
$query = DB::table($favTable)->where('user_id', (int) $user->id);
|
||||
if ($orderColumn) {
|
||||
@@ -78,19 +66,18 @@ class FavoriteController extends Controller
|
||||
$artwork = (int) $last;
|
||||
}
|
||||
}
|
||||
$favTable = DB::getSchemaBuilder()->hasTable('user_favorites') ? 'user_favorites' : (DB::getSchemaBuilder()->hasTable('favourites') ? 'favourites' : null);
|
||||
if ($favTable) {
|
||||
$artworkId = is_object($artwork) ? (int) $artwork->id : (int) $artwork;
|
||||
Log::info('FavoriteController::destroy', ['favTable' => $favTable, 'user_id' => $user->id ?? null, 'artwork' => $artwork, 'artworkId' => $artworkId]);
|
||||
$deleted = DB::table($favTable)
|
||||
->where('user_id', (int) $user->id)
|
||||
->where('artwork_id', $artworkId)
|
||||
->delete();
|
||||
$artworkId = is_object($artwork) ? (int) $artwork->id : (int) $artwork;
|
||||
Log::info('FavoriteController::destroy', ['user_id' => $user->id ?? null, 'artworkId' => $artworkId]);
|
||||
// Look up creator before deleting so we can decrement their counter
|
||||
$creatorId = (int) DB::table('artworks')->where('id', $artworkId)->value('user_id');
|
||||
|
||||
// Fallback: some schemas or test setups may not match user_id; try deleting by artwork_id alone
|
||||
if (! $deleted) {
|
||||
DB::table($favTable)->where('artwork_id', $artworkId)->delete();
|
||||
}
|
||||
DB::table('artwork_favourites')
|
||||
->where('user_id', (int) $user->id)
|
||||
->where('artwork_id', $artworkId)
|
||||
->delete();
|
||||
|
||||
if ($creatorId) {
|
||||
app(UserStatsService::class)->decrementFavoritesReceived($creatorId);
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.favorites')->with('status', 'favourite-removed');
|
||||
|
||||
@@ -3,16 +3,46 @@
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AvatarUrl;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FollowerController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
// Minimal placeholder: real implementation should query followers table
|
||||
$followers = [];
|
||||
$user = $request->user();
|
||||
$perPage = 30;
|
||||
|
||||
return view('dashboard.followers', ['followers' => $followers]);
|
||||
// People who follow $user (user_id = $user being followed)
|
||||
$followers = DB::table('user_followers as uf')
|
||||
->join('users as u', 'u.id', '=', 'uf.follower_id')
|
||||
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
|
||||
->leftJoin('user_statistics as us', 'us.user_id', '=', 'u.id')
|
||||
->where('uf.user_id', $user->id)
|
||||
->whereNull('u.deleted_at')
|
||||
->orderByDesc('uf.created_at')
|
||||
->select([
|
||||
'u.id', 'u.username', 'u.name',
|
||||
'up.avatar_hash',
|
||||
'us.uploads_count',
|
||||
'uf.created_at as followed_at',
|
||||
])
|
||||
->paginate($perPage)
|
||||
->withQueryString()
|
||||
->through(fn ($row) => (object) [
|
||||
'id' => $row->id,
|
||||
'username' => $row->username,
|
||||
'uname' => $row->username ?? $row->name,
|
||||
'avatar_url' => AvatarUrl::forUser((int) $row->id, $row->avatar_hash, 50),
|
||||
'profile_url' => '/@' . strtolower((string) ($row->username ?? $row->id)),
|
||||
'uploads' => $row->uploads_count ?? 0,
|
||||
'followed_at' => $row->followed_at,
|
||||
]);
|
||||
|
||||
return view('dashboard.followers', [
|
||||
'followers' => $followers,
|
||||
'page_title' => 'My Followers',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,48 @@
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AvatarUrl;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FollowingController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
// Minimal placeholder: real implementation should query following relationships
|
||||
$following = [];
|
||||
$user = $request->user();
|
||||
$perPage = 30;
|
||||
|
||||
return view('dashboard.following', ['following' => $following]);
|
||||
// People that $user follows (follower_id = $user)
|
||||
$following = DB::table('user_followers as uf')
|
||||
->join('users as u', 'u.id', '=', 'uf.user_id')
|
||||
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
|
||||
->leftJoin('user_statistics as us', 'us.user_id', '=', 'u.id')
|
||||
->where('uf.follower_id', $user->id)
|
||||
->whereNull('u.deleted_at')
|
||||
->orderByDesc('uf.created_at')
|
||||
->select([
|
||||
'u.id', 'u.username', 'u.name',
|
||||
'up.avatar_hash',
|
||||
'us.uploads_count',
|
||||
'us.followers_count',
|
||||
'uf.created_at as followed_at',
|
||||
])
|
||||
->paginate($perPage)
|
||||
->withQueryString()
|
||||
->through(fn ($row) => (object) [
|
||||
'id' => $row->id,
|
||||
'username' => $row->username,
|
||||
'uname' => $row->username ?? $row->name,
|
||||
'avatar_url' => AvatarUrl::forUser((int) $row->id, $row->avatar_hash, 50),
|
||||
'profile_url' => '/@' . strtolower((string) ($row->username ?? $row->id)),
|
||||
'uploads' => $row->uploads_count ?? 0,
|
||||
'followers_count'=> $row->followers_count ?? 0,
|
||||
'followed_at' => $row->followed_at,
|
||||
]);
|
||||
|
||||
return view('dashboard.following', [
|
||||
'following' => $following,
|
||||
'page_title' => 'People I Follow',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user