Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Actions/Api/Spotify/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class RefreshToken
public function handle(User $user): bool
{
try {
$spotifyConnection = $user->connections->firstWhere('type_id', ConnectionType::SPOTIFY->value);
$spotifyConnection = $user->connections->firstWhere('type', ConnectionType::SPOTIFY->value);

$response = Http::asForm()->post('https://accounts.spotify.com/api/token', [
'grant_type' => 'refresh_token',
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Api/Spotify/SearchArtist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function handle(User $user, string $phrase)
(new RefreshToken)->handle($user);

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$user->connections->firstWhere('type_id', ConnectionType::SPOTIFY->value)->token,
'Authorization' => 'Bearer '.$user->connections->firstWhere('type', ConnectionType::SPOTIFY->value)->token,
'Content-Type' => 'application/json',
'Client-Id' => config('services.spotify.client_id'),
])->get('https://api.spotify.com/v1/search', [
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Api/Spotify/SearchTrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function handle(User $user, string $phrase): Collection
(new RefreshToken)->handle($user);

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$user->connections->firstWhere('type_id', ConnectionType::SPOTIFY->value)->token,
'Authorization' => 'Bearer '.$user->connections->firstWhere('type', ConnectionType::SPOTIFY->value)->token,
'Content-Type' => 'application/json',
'Client-Id' => config('services.spotify.client_id'),
])->get('https://api.spotify.com/v1/search', [
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Api/Twitch/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class RefreshToken
public function handle(User $user): bool
{
try {
$twitchConnection = $user->connections->firstWhere('type_id', ConnectionType::TWITCH->value);
$twitchConnection = $user->connections->firstWhere('type', ConnectionType::TWITCH->value);

$response = Http::asForm()->post('https://id.twitch.tv/oauth2/token', [
'client_id' => config('services.twitch.client_id'),
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Api/Twitch/SearchCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function search(User $user, string $phrase, MediaType $mediaType)
(new RefreshToken)->handle($user);

$response = Http::withHeaders([
'Authorization' => 'Bearer '.$user->connections->firstWhere('type_id', ConnectionType::TWITCH->value)->token,
'Authorization' => 'Bearer '.$user->connections->firstWhere('type', ConnectionType::TWITCH->value)->token,
'Content-Type' => 'application/json',
'Client-Id' => config('services.twitch.client_id'),
])->get('https://api.twitch.tv/helix/search/categories', [
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/CheckTwitchLiveStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle(): int

(new RefreshToken)->handle($user);

$token = $user->connections->firstWhere('type_id', ConnectionType::TWITCH->value)->token ?? null;
$token = $user->connections->firstWhere('type', ConnectionType::TWITCH->value)->token ?? null;

if (! $token) {
return self::FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/UpdateArtistImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle()
'GET',
"https://api.spotify.com/v1/artists?ids={$ids}", [
'headers' => [
'Authorization' => 'Bearer '.$user->connections->firstWhere('type_id', ConnectionType::SPOTIFY->value)->token,
'Authorization' => 'Bearer '.$user->connections->firstWhere('type', ConnectionType::SPOTIFY->value)->token,
],
]
);
Expand Down
8 changes: 4 additions & 4 deletions app/Enums/AssetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Enums;

enum AssetType: int
enum AssetType: string
{
case PHOTO = 1;
case RESUME = 2;
case THREE_D_PRINTS = 3;
case PHOTO = 'photo';
case RESUME = 'resume';
case THREE_D_PRINTS = 'three_d_prints';

public function label(): string
{
Expand Down
18 changes: 5 additions & 13 deletions app/Enums/ConnectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@

namespace App\Enums;

enum ConnectionType: int
enum ConnectionType: string
{
case SPOTIFY = 1;
case TWITCH = 2;
case SPOTIFY = 'spotify';
case TWITCH = 'twitch';

public function label()
public function label(): string
{
return match($this) {
return match ($this) {
self::SPOTIFY => 'Spotify',
self::TWITCH => 'Twitch',
};
}

public function slug()
{
return match($this) {
self::SPOTIFY => 'spotify',
self::TWITCH => 'twitch',
};
}
}
24 changes: 9 additions & 15 deletions app/Http/Controllers/ConnectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,28 @@ class ConnectionController extends Controller
{
public function connect(Request $request, string $type)
{
session()->put('current_connection_type_id', $this->getConnectionTypeId($type));
session()->put('current_connection_type', $type);
$connectionType = ConnectionType::from($type);

return Socialite::driver($type)->redirect();
session()->put('current_connection_type', $connectionType->value);

return Socialite::driver($connectionType->value)->redirect();
}

public function processConnection(Request $request)
{
$user = Socialite::driver(session()->get('current_connection_type'))->stateless()->user();
$type = session()->get('current_connection_type');

$user = Socialite::driver($type)->stateless()->user();

auth()->user()->connections()->updateOrCreate(['type_id' => session()->get('current_connection_type_id')], [
'type_id' => session()->get('current_connection_type_id'),
auth()->user()->connections()->updateOrCreate(['type' => $type], [
'type' => $type,
'external_id' => $user->id,
'token' => $user->token,
'refresh_token' => $user->refreshToken,
]);

session()->forget('current_connection_type_id');
session()->forget('current_connection_type');

return redirect(route('dashboard'));
}

private function getConnectionTypeId(string $type)
{
return match ($type) {
'twitch' => ConnectionType::TWITCH->slug(),
'spotify' => ConnectionType::SPOTIFY->slug()
};
}
}
6 changes: 3 additions & 3 deletions app/Livewire/Forms/PhotoForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PhotoForm extends Form

public string $description = '';

public int $type = AssetType::PHOTO->value;
public string $type = AssetType::PHOTO->value;

public $photo;

Expand All @@ -37,7 +37,7 @@ public function store()
);

Asset::create([
'type_id' => $this->type,
'type' => $this->type,
'name' => $this->name,
'slug' => Str::uuid(),
'path' => $path,
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function rules(): array
'description' => 'nullable|string|max:255',
'type' => [
'required',
'integer',
'string',
Rule::in([AssetType::PHOTO->value, AssetType::THREE_D_PRINTS->value]),
],
'photo' => 'image:mimes:png,jpg,jpeg,gif,jfif',
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function render()
{
return view('navigation', [
'resume' => Asset::query()
->where('type_id', AssetType::RESUME->value)
->where('type', AssetType::RESUME->value)
->latest()
->first()?->slug,
]);
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/Photos/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Gallery extends Component

public string $emptyMessage = 'No Photos';

public array|int $type = AssetType::PHOTO->value;
public array|string $type = AssetType::PHOTO->value;

public PhotoForm $form;

Expand All @@ -32,7 +32,7 @@ public function render()
public function photos()
{
return Asset::query()
->whereIn('type_id', is_array($this->type) ? $this->type : [$this->type])
->whereIn('type', is_array($this->type) ? $this->type : [$this->type])
->paginate(9);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Photos/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Uploader extends Component

public bool $showGallery = true;

public array|int $galleryType = AssetType::PHOTO->value;
public array|string $galleryType = AssetType::PHOTO->value;

public function render()
{
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/Resume.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function store()
$path = $this->resume->storePubliclyAs('resumes', $name, 's3');

Asset::create([
'type_id' => AssetType::RESUME->value,
'type' => AssetType::RESUME->value,
'slug' => Str::uuid(),
'name' => $name,
'path' => $path,
Expand Down Expand Up @@ -62,6 +62,6 @@ public function destroy($id)
#[Computed]
public function resumes()
{
return Asset::where('type_id', AssetType::RESUME->value)->get();
return Asset::where('type', AssetType::RESUME->value)->get();
}
}
4 changes: 2 additions & 2 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Asset extends Model
{
protected $fillable = [
'type_id',
'type',
'name',
'slug',
'path',
Expand All @@ -27,7 +27,7 @@ public static function boot()
public function casts(): array
{
return [
'type_id' => AssetType::class,
'type' => AssetType::class,
'data' => 'array',
];
}
Expand Down
3 changes: 1 addition & 2 deletions app/Models/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Connection extends Model
{
protected $fillable = [
'external_id',
'type_id',
'type',
'name',
'token',
'refresh_token',
Expand Down
6 changes: 3 additions & 3 deletions database/factories/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function definition(): array
$name = $this->faker->words(3, true);

return [
'type_id' => $this->faker->randomElement([AssetType::PHOTO->value, AssetType::RESUME->value]),
'type' => $this->faker->randomElement([AssetType::PHOTO->value, AssetType::RESUME->value]),
'name' => $name,
'slug' => Str::slug($name),
'path' => $this->faker->filePath(),
Expand All @@ -41,7 +41,7 @@ public function definition(): array
public function photo(): static
{
return $this->state(fn (array $attributes) => [
'type_id' => AssetType::PHOTO->value,
'type' => AssetType::PHOTO->value,
'mime_type' => $this->faker->randomElement([
'image/jpeg',
'image/png',
Expand All @@ -59,7 +59,7 @@ public function photo(): static
public function resume(): static
{
return $this->state(fn (array $attributes) => [
'type_id' => AssetType::RESUME->value,
'type' => AssetType::RESUME->value,
'mime_type' => $this->faker->randomElement([
'application/pdf',
]),
Expand Down
Original file line number Diff line number Diff line change
@@ -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('connections', function (Blueprint $table) {
$table->renameColumn('type_id', 'type');
});
}

public function down(): void
{
Schema::table('connections', function (Blueprint $table) {
$table->renameColumn('type', 'type_id');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

use App\Enums\AssetType;
use App\Models\Asset;
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
{
public function up(): void
{
Schema::table('assets', function (Blueprint $table) {
$table->renameColumn('type_id', 'type');
});

Schema::table('assets', function (Blueprint $table) {
$table->string('type')->change();
});

$map = [
1 => AssetType::PHOTO->value,
2 => AssetType::RESUME->value,
3 => AssetType::THREE_D_PRINTS->value,
];

DB::transaction(function () use ($map): void {
foreach ($map as $old => $new) {
Asset::withoutGlobalScopes()->where('type', (string) $old)->update(['type' => $new]);
}
});
}

public function down(): void
{
$map = [
AssetType::PHOTO->value => 1,
AssetType::RESUME->value => 2,
AssetType::THREE_D_PRINTS->value => 3,
];

DB::transaction(function () use ($map): void {
foreach ($map as $old => $new) {
Asset::withoutGlobalScopes()->where('type', $old)->update(['type' => $new]);
}
});

Schema::table('assets', function (Blueprint $table) {
$table->integer('type')->change();
});

Schema::table('assets', function (Blueprint $table) {
$table->renameColumn('type', 'type_id');
});
}
};
4 changes: 2 additions & 2 deletions resources/views/livewire/connection.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
@php
$connections = [
'spotify' => [
'connection' => auth()->user()->connections->firstWhere('type_id', App\Enums\ConnectionType::SPOTIFY->value),
'connection' => auth()->user()->connections->firstWhere('type', App\Enums\ConnectionType::SPOTIFY->value),
'icon' => 'musical-note',
'color' => 'lime',
'name' => 'Spotify'
],
'twitch' => [
'connection' => auth()->user()->connections->firstWhere('type_id', App\Enums\ConnectionType::TWITCH->value),
'connection' => auth()->user()->connections->firstWhere('type', App\Enums\ConnectionType::TWITCH->value),
'icon' => 'tv',
'color' => 'purple',
'name' => 'Twitch'
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/pages/media/games/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/>
<x-media-accordian-item
:collection="$playedBefore"
:title="'Played Before'"
:title="'Catalog'"
/>
<x-media-accordian-item
:collection="$completed"
Expand Down
Loading
Loading