mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
refactor: playlist is not viewable (#847)
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\GraphQL\Definition\Fields\List\Playlist;
|
||||
|
||||
use App\GraphQL\Definition\Fields\Base\CountAggregateField;
|
||||
use App\Models\List\Playlist;
|
||||
|
||||
/**
|
||||
* Class PlaylistViewsCountField.
|
||||
*/
|
||||
class PlaylistViewsCountField extends CountAggregateField
|
||||
{
|
||||
/**
|
||||
* Create a new field instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Playlist::RELATION_VIEW_AGGREGATE, 'viewsCount');
|
||||
}
|
||||
|
||||
/**
|
||||
* The description of the field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function description(): string
|
||||
{
|
||||
return 'The number of views recorded for the resource';
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ use App\GraphQL\Definition\Fields\List\Playlist\PlaylistLikesCountField;
|
||||
use App\GraphQL\Definition\Fields\List\Playlist\PlaylistNameField;
|
||||
use App\GraphQL\Definition\Fields\List\Playlist\PlaylistTracksCountField;
|
||||
use App\GraphQL\Definition\Fields\List\Playlist\PlaylistTracksExistsField;
|
||||
use App\GraphQL\Definition\Fields\List\Playlist\PlaylistViewsCountField;
|
||||
use App\GraphQL\Definition\Fields\List\Playlist\PlaylistVisibilityField;
|
||||
use App\GraphQL\Definition\Fields\LocalizedEnumField;
|
||||
use App\GraphQL\Definition\Relations\BelongsToManyRelation;
|
||||
@@ -76,7 +75,6 @@ class PlaylistType extends EloquentType implements HasFields, HasRelations
|
||||
new PlaylistTracksCountField(),
|
||||
new PlaylistTracksExistsField(),
|
||||
new PlaylistLikesCountField(),
|
||||
new PlaylistViewsCountField(),
|
||||
new CreatedAtField(),
|
||||
new UpdatedAtField(),
|
||||
new DeletedAtField(),
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Api\Field\List\Playlist;
|
||||
|
||||
use App\Enums\Http\Api\Field\AggregateFunction;
|
||||
use App\Enums\Http\Api\QualifyColumn;
|
||||
use App\Http\Api\Field\Aggregate\AggregateField;
|
||||
use App\Http\Api\Filter\Filter;
|
||||
use App\Http\Api\Filter\IntFilter;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
use App\Http\Api\Sort\Sort;
|
||||
use App\Models\Aggregate\ViewAggregate;
|
||||
use App\Models\List\Playlist;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class PlaylistViewCountField.
|
||||
*/
|
||||
class PlaylistViewCountField extends AggregateField
|
||||
{
|
||||
/**
|
||||
* Create a new field instance.
|
||||
*
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function __construct(Schema $schema)
|
||||
{
|
||||
parent::__construct($schema, Playlist::RELATION_VIEW_AGGREGATE, AggregateFunction::SUM, ViewAggregate::ATTRIBUTE_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filters that can be applied to the field.
|
||||
*
|
||||
* @return Filter
|
||||
*/
|
||||
public function getFilter(): Filter
|
||||
{
|
||||
return new IntFilter(key: $this->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';
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
],
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user