-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
775 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
app/Events/Pivot/Wiki/SongResource/SongResourceCreated.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Events\Pivot\Wiki\SongResource; | ||
|
||
use App\Events\Base\Pivot\PivotCreatedEvent; | ||
use App\Models\Wiki\Song; | ||
use App\Models\Wiki\ExternalResource; | ||
use App\Pivots\Wiki\SongResource; | ||
|
||
/** | ||
* Class SongResourceCreated. | ||
* | ||
* @extends PivotCreatedEvent<Song, ExternalResource> | ||
*/ | ||
class SongResourceCreated extends PivotCreatedEvent | ||
{ | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @param SongResource $songResource | ||
*/ | ||
public function __construct(SongResource $songResource) | ||
{ | ||
parent::__construct($songResource->song, $songResource->resource); | ||
} | ||
|
||
/** | ||
* Get the description for the Discord message payload. | ||
* | ||
* @return string | ||
*/ | ||
protected function getDiscordMessageDescription(): string | ||
{ | ||
$foreign = $this->getForeign(); | ||
$related = $this->getRelated(); | ||
|
||
return "Resource '**{$foreign->getName()}**' has been attached to Song '**{$related->getName()}**'."; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/Events/Pivot/Wiki/SongResource/SongResourceDeleted.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Events\Pivot\Wiki\SongResource; | ||
|
||
use App\Events\Base\Pivot\PivotDeletedEvent; | ||
use App\Models\Wiki\Song; | ||
use App\Models\Wiki\ExternalResource; | ||
use App\Pivots\Wiki\SongResource; | ||
|
||
/** | ||
* Class SongResourceDeleted. | ||
* | ||
* @extends PivotDeletedEvent<Song, ExternalResource> | ||
*/ | ||
class SongResourceDeleted extends PivotDeletedEvent | ||
{ | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @param SongResource $songResource | ||
*/ | ||
public function __construct(SongResource $songResource) | ||
{ | ||
parent::__construct($songResource->song, $songResource->resource); | ||
} | ||
|
||
/** | ||
* Get the description for the Discord message payload. | ||
* | ||
* @return string | ||
*/ | ||
protected function getDiscordMessageDescription(): string | ||
{ | ||
$foreign = $this->getForeign(); | ||
$related = $this->getRelated(); | ||
|
||
return "Resource '**{$foreign->getName()}**' has been detached from Song '**{$related->getName()}**'."; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/Events/Pivot/Wiki/SongResource/SongResourceUpdated.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Events\Pivot\Wiki\SongResource; | ||
|
||
use App\Events\Base\Pivot\PivotUpdatedEvent; | ||
use App\Models\Wiki\Song; | ||
use App\Models\Wiki\ExternalResource; | ||
use App\Pivots\Wiki\SongResource; | ||
|
||
/** | ||
* Class SongResourceUpdated. | ||
* | ||
* @extends PivotUpdatedEvent<Song, ExternalResource> | ||
*/ | ||
class SongResourceUpdated extends PivotUpdatedEvent | ||
{ | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @param SongResource $songResource | ||
*/ | ||
public function __construct(SongResource $songResource) | ||
{ | ||
parent::__construct($songResource->song, $songResource->resource); | ||
$this->initializeEmbedFields($songResource); | ||
} | ||
|
||
/** | ||
* Get the description for the Discord message payload. | ||
* | ||
* @return string | ||
*/ | ||
protected function getDiscordMessageDescription(): string | ||
{ | ||
$foreign = $this->getForeign(); | ||
$related = $this->getRelated(); | ||
|
||
return "Resource '**{$foreign->getName()}**' for Song '**{$related->getName()}**' has been updated."; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/Http/Api/Field/Pivot/Wiki/SongResource/SongResourceAsField.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Api\Field\Pivot\Wiki\SongResource; | ||
|
||
use App\Contracts\Http\Api\Field\CreatableField; | ||
use App\Contracts\Http\Api\Field\UpdatableField; | ||
use App\Http\Api\Field\StringField; | ||
use App\Http\Api\Schema\Schema; | ||
use App\Pivots\Wiki\SongResource; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Class SongResourceAsField. | ||
*/ | ||
class SongResourceAsField extends StringField implements CreatableField, UpdatableField | ||
{ | ||
/** | ||
* Create a new field instance. | ||
* | ||
* @param Schema $schema | ||
*/ | ||
public function __construct(Schema $schema) | ||
{ | ||
parent::__construct($schema, SongResource::ATTRIBUTE_AS); | ||
} | ||
|
||
/** | ||
* Set the creation validation rules for the field. | ||
* | ||
* @param Request $request | ||
* @return array | ||
*/ | ||
public function getCreationRules(Request $request): array | ||
{ | ||
return [ | ||
'nullable', | ||
'string', | ||
'max:192', | ||
]; | ||
} | ||
|
||
/** | ||
* Set the update validation rules for the field. | ||
* | ||
* @param Request $request | ||
* @return array | ||
*/ | ||
public function getUpdateRules(Request $request): array | ||
{ | ||
return [ | ||
'nullable', | ||
'string', | ||
'max:192', | ||
]; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/Http/Api/Field/Pivot/Wiki/SongResource/SongResourceResourceIdField.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Api\Field\Pivot\Wiki\SongResource; | ||
|
||
use App\Contracts\Http\Api\Field\SelectableField; | ||
use App\Http\Api\Field\Field; | ||
use App\Http\Api\Query\Query; | ||
use App\Http\Api\Schema\Schema; | ||
use App\Pivots\Wiki\SongResource; | ||
|
||
/** | ||
* Class SongResourceResourceIdField. | ||
*/ | ||
class SongResourceResourceIdField extends Field implements SelectableField | ||
{ | ||
/** | ||
* Create a new field instance. | ||
* | ||
* @param Schema $schema | ||
*/ | ||
public function __construct(Schema $schema) | ||
{ | ||
parent::__construct($schema, SongResource::ATTRIBUTE_RESOURCE); | ||
} | ||
|
||
/** | ||
* Determine if the field should be included in the select clause of our query. | ||
* | ||
* @param Query $query | ||
* @param Schema $schema | ||
* @return bool | ||
*/ | ||
public function shouldSelect(Query $query, Schema $schema): bool | ||
{ | ||
// Needed to match resource relation. | ||
return true; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/Http/Api/Field/Pivot/Wiki/SongResource/SongResourceSongIdField.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Api\Field\Pivot\Wiki\SongResource; | ||
|
||
use App\Contracts\Http\Api\Field\SelectableField; | ||
use App\Http\Api\Field\Field; | ||
use App\Http\Api\Query\Query; | ||
use App\Http\Api\Schema\Schema; | ||
use App\Pivots\Wiki\SongResource; | ||
|
||
/** | ||
* Class SongResourceSongIdField. | ||
*/ | ||
class SongResourceSongIdField extends Field implements SelectableField | ||
{ | ||
/** | ||
* Create a new field instance. | ||
* | ||
* @param Schema $schema | ||
*/ | ||
public function __construct(Schema $schema) | ||
{ | ||
parent::__construct($schema, SongResource::ATTRIBUTE_SONG); | ||
} | ||
|
||
/** | ||
* Determine if the field should be included in the select clause of our query. | ||
* | ||
* @param Query $query | ||
* @param Schema $schema | ||
* @return bool | ||
*/ | ||
public function shouldSelect(Query $query, Schema $schema): bool | ||
{ | ||
// Needed to match anime relation. | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Api\Schema\Pivot\Wiki; | ||
|
||
use App\Http\Api\Field\Base\CreatedAtField; | ||
use App\Http\Api\Field\Base\UpdatedAtField; | ||
use App\Http\Api\Field\Field; | ||
use App\Http\Api\Field\Pivot\Wiki\SongResource\SongResourceSongIdField; | ||
use App\Http\Api\Field\Pivot\Wiki\SongResource\SongResourceAsField; | ||
use App\Http\Api\Field\Pivot\Wiki\SongResource\SongResourceResourceIdField; | ||
use App\Http\Api\Include\AllowedInclude; | ||
use App\Http\Api\Schema\EloquentSchema; | ||
use App\Http\Api\Schema\Wiki\ExternalResourceSchema; | ||
use App\Http\Api\Schema\Wiki\SongSchema; | ||
use App\Http\Resources\Pivot\Wiki\Resource\SongResourceResource; | ||
use App\Pivots\Wiki\SongResource; | ||
|
||
/** | ||
* Class SongResourceSchema. | ||
*/ | ||
class SongResourceSchema extends EloquentSchema | ||
{ | ||
/** | ||
* Get the type of the resource. | ||
* | ||
* @return string | ||
*/ | ||
public function type(): string | ||
{ | ||
return SongResourceResource::$wrap; | ||
} | ||
|
||
/** | ||
* Get the allowed includes. | ||
* | ||
* @return AllowedInclude[] | ||
*/ | ||
public function allowedIncludes(): array | ||
{ | ||
return [ | ||
new AllowedInclude(new SongSchema(), SongResource::RELATION_SONG), | ||
new AllowedInclude(new ExternalResourceSchema(), SongResource::RELATION_RESOURCE), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the direct fields of the resource. | ||
* | ||
* @return Field[] | ||
* | ||
* @noinspection PhpMissingParentCallCommonInspection | ||
*/ | ||
public function fields(): array | ||
{ | ||
return [ | ||
new CreatedAtField($this), | ||
new UpdatedAtField($this), | ||
new SongResourceSongIdField($this), | ||
new SongResourceResourceIdField($this), | ||
new SongResourceAsField($this), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.