Skip to content

Commit

Permalink
Merge pull request #53 from kyledoesdev/feature/explore-overhaul
Browse files Browse the repository at this point in the history
Feature/explore overhaul
  • Loading branch information
kyledoesdev authored Feb 5, 2025
2 parents 29c5ebb + 47d578f commit 62e653e
Show file tree
Hide file tree
Showing 23 changed files with 575 additions and 227 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/ExploreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Artist;
use App\Models\Ranking;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
Expand All @@ -11,9 +12,10 @@ class ExploreController extends Controller
public function pages(): JsonResponse
{
return response()->json([
'top_artists' => Artist::getTopArtists(),
'rankings' => Ranking::query()
->forExplorePage(request()->search)
->paginate(6),
->paginate(5),
], 200);
}
}
12 changes: 11 additions & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ public function show(string $id): View
{
$user = User::where('spotify_id', $id)->first();

/* no profile found for user */
if (is_null($user)) {
return view('profile.show', [
'user' => null,
'name' => get_formatted_name($id),
'rankings' => null,
]);
}

return view('profile.show', [
'user' => $user,
'name' => get_formatted_name($user->name),
'rankings' => Ranking::query()
->forProfilePage($user)
->paginate(5)
->get()
]);
}
}
20 changes: 1 addition & 19 deletions app/Http/Controllers/RankingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function destroy(DestroyRankingRequest $request): JsonResponse
Song::where('ranking_id', $request->rankingId)->delete();

return response()->json([
'message' => 'Your ranking has been tossed into the void, never to return. Or will it?',
'message' => 'Your ranking has been deleted.',
'rankings' => Ranking::query()
->where('user_id', auth()->id())
->with('user', 'artist')
Expand All @@ -85,22 +85,4 @@ public function destroy(DestroyRankingRequest $request): JsonResponse
->paginate(5),
], 200);
}

public function pages(): JsonResponse
{
$user = User::where('spotify_id', request()->spotify_id)->first();

$response = [
'success' => true,
'rankings' => Ranking::query()->forProfilePage($user)->paginate(5),
'name' => $user ? get_formatted_name($user->name) : null,
];

if (is_null($user)) {
$response['success'] = false;
$response['message'] = "No ranking results for user: {$spotify_id}.";
}

return response()->json($response, 200);
}
}
20 changes: 20 additions & 0 deletions app/Models/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,24 @@ public function ranking(): BelongsTo
{
return $this->belongsTo(Ranking::class);
}

public static function getTopArtists()
{
return self::query()
->selectRaw('
count(rankings.artist_id) as artist_rankings_count,
artists.id,
artists.artist_name
')
->join('rankings', function($join) {
$join->on('rankings.artist_id', '=', 'artists.id')
->where('rankings.is_ranked', true)
->where('rankings.is_public', true);
})
->groupBy('rankings.artist_id')
->orderBy('artist_rankings_count', 'desc')
->orderBy('artists.artist_name', 'asc')
->limit(10)
->get();
}
}
6 changes: 2 additions & 4 deletions app/Models/Ranking.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ public function scopeForExplorePage(Builder $query, ?string $search = null)
->where('is_ranked', true)
->where('is_public', true)
->when($search != null, function($query) use ($search) {
$query->where(function($query2) use ($search) {
$query2->newQuery()
->whereHas('artist', fn($q) => $q->where('artist_name', 'LIKE', "%{$search}%"))
->orWhere('name', 'LIKE', "%{$search}%");
$query->whereHas('artist', function($q) use ($search) {
$q->where('artist_name', 'LIKE', "%{$search}%")->orWhere('id', $search);
});
})
->with('user', 'artist')
Expand Down
4 changes: 4 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
$middleware->redirectUsersTo(AppServiceProvider::HOME);

$middleware->throttleApi();

$middleware->validateCsrfTokens(except: [
'support-bubble',
]);
})
->withSchedule(function (Schedule $schedule) {
})
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"laravel/tinker": "^2.9",
"maatwebsite/excel": "^3.1",
"marvinlabs/laravel-discord-logger": "^1.4",
"socialiteproviders/spotify": "^4.1"
"socialiteproviders/spotify": "^4.1",
"spatie/laravel-support-bubble": "^1.8"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.10",
Expand Down
222 changes: 221 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 62e653e

Please sign in to comment.