From 6bbfa1e86af5399c6af573ab7a37f28ed9f84fac Mon Sep 17 00:00:00 2001 From: Kyrch Date: Wed, 2 Jul 2025 03:25:37 -0300 Subject: [PATCH] refactor: playlist is not viewable (#847) --- .../List/Playlist/PlaylistViewsCountField.php | 32 -------- .../Definition/Types/List/PlaylistType.php | 2 - .../List/Playlist/PlaylistViewCountField.php | 73 ------------------- app/Http/Api/Schema/List/PlaylistSchema.php | 2 - app/Models/List/Playlist.php | 8 +- tests/Unit/Models/List/PlaylistTest.php | 18 ----- 6 files changed, 1 insertion(+), 134 deletions(-) delete mode 100644 app/GraphQL/Definition/Fields/List/Playlist/PlaylistViewsCountField.php delete mode 100644 app/Http/Api/Field/List/Playlist/PlaylistViewCountField.php diff --git a/app/GraphQL/Definition/Fields/List/Playlist/PlaylistViewsCountField.php b/app/GraphQL/Definition/Fields/List/Playlist/PlaylistViewsCountField.php deleted file mode 100644 index 6c3dfa312..000000000 --- a/app/GraphQL/Definition/Fields/List/Playlist/PlaylistViewsCountField.php +++ /dev/null @@ -1,32 +0,0 @@ -alias(), column: ViewAggregate::ATTRIBUTE_VALUE, qualifyColumn: QualifyColumn::YES); - } - - /** - * Get the sort that can be applied to the field. - * - * @return Sort - */ - public function getSort(): Sort - { - return new Sort(key: $this->alias(), column: 'view_aggregate_sum_value', qualifyColumn: QualifyColumn::NO); - } - - /** - * Get the value to display to the user. - * - * @param Model $model - * @return mixed - */ - public function render(Model $model): mixed - { - return (int) $model->getAttribute('view_aggregate_sum_value'); - } - - /** - * Format the aggregate value to its sub-select alias / model attribute. - * - * @return string - */ - public function alias(): string - { - return 'views_count'; - } -} diff --git a/app/Http/Api/Schema/List/PlaylistSchema.php b/app/Http/Api/Schema/List/PlaylistSchema.php index d086857fe..b904b1e68 100644 --- a/app/Http/Api/Schema/List/PlaylistSchema.php +++ b/app/Http/Api/Schema/List/PlaylistSchema.php @@ -15,7 +15,6 @@ use App\Http\Api\Field\List\Playlist\PlaylistNameField; use App\Http\Api\Field\List\Playlist\PlaylistTrackCountField; use App\Http\Api\Field\List\Playlist\PlaylistTrackExistsField; use App\Http\Api\Field\List\Playlist\PlaylistUserIdField; -use App\Http\Api\Field\List\Playlist\PlaylistViewCountField; use App\Http\Api\Field\List\Playlist\PlaylistVisibilityField; use App\Http\Api\Include\AllowedInclude; use App\Http\Api\Schema\Auth\UserSchema; @@ -88,7 +87,6 @@ class PlaylistSchema extends EloquentSchema implements SearchableSchema new PlaylistDescriptionField($this), new PlaylistUserIdField($this), new PlaylistVisibilityField($this), - new PlaylistViewCountField($this), new PlaylistTrackExistsField($this), new PlaylistTrackCountField($this), ], diff --git a/app/Models/List/Playlist.php b/app/Models/List/Playlist.php index db538ec39..3c151faeb 100644 --- a/app/Models/List/Playlist.php +++ b/app/Models/List/Playlist.php @@ -5,10 +5,8 @@ declare(strict_types=1); namespace App\Models\List; use App\Concerns\Models\Aggregate\AggregatesLike; -use App\Concerns\Models\Aggregate\AggregatesView; use App\Concerns\Models\InteractsWithLikes; use App\Contracts\Models\HasAggregateLikes; -use App\Contracts\Models\HasAggregateViews; use App\Contracts\Models\HasHashids; use App\Contracts\Models\HasImages; use App\Contracts\Models\Likeable; @@ -23,8 +21,6 @@ use App\Models\BaseModel; use App\Models\List\Playlist\PlaylistTrack; use App\Models\Wiki\Image; use App\Pivots\List\PlaylistImage; -use CyrildeWit\EloquentViewable\Contracts\Viewable; -use CyrildeWit\EloquentViewable\InteractsWithViews; use Database\Factories\List\PlaylistFactory; use Elastic\ScoutDriverPlus\Searchable; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -50,12 +46,10 @@ use Illuminate\Support\Collection; * * @method static PlaylistFactory factory(...$parameters) */ -class Playlist extends BaseModel implements HasAggregateLikes, HasAggregateViews, HasHashids, HasImages, Likeable, Viewable +class Playlist extends BaseModel implements HasAggregateLikes, HasHashids, HasImages, Likeable { use AggregatesLike; - use AggregatesView; use InteractsWithLikes; - use InteractsWithViews; use Searchable; final public const TABLE = 'playlists'; diff --git a/tests/Unit/Models/List/PlaylistTest.php b/tests/Unit/Models/List/PlaylistTest.php index 11687f60b..d44f12895 100644 --- a/tests/Unit/Models/List/PlaylistTest.php +++ b/tests/Unit/Models/List/PlaylistTest.php @@ -10,11 +10,9 @@ use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; use App\Models\Wiki\Image; use App\Pivots\List\PlaylistImage; -use CyrildeWit\EloquentViewable\View; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Arr; use Tests\TestCase; @@ -135,22 +133,6 @@ class PlaylistTest extends TestCase static::assertEmpty(array_diff($playlist->hashids(), [$user->id, $playlist->playlist_id])); } - /** - * Playlists shall have a one-to-many polymorphic relationship to View. - * - * @return void - */ - public function testViews(): void - { - $playlist = Playlist::factory()->createOne(); - - views($playlist)->record(); - - static::assertInstanceOf(MorphMany::class, $playlist->views()); - static::assertEquals(1, $playlist->views()->count()); - static::assertInstanceOf(View::class, $playlist->views()->first()); - } - /** * Playlists shall belong to a User. *