-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from Kurozora/tv-rating-settings
- Loading branch information
Showing
36 changed files
with
772 additions
and
326 deletions.
There are no files selected for viewing
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,36 @@ | ||
<?php | ||
|
||
namespace App\Actions\Web\Profile; | ||
|
||
use App\Contracts\Web\Profile\UpdatesUserPreferredTvRating; | ||
use App\Models\TvRating; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\ValidationException; | ||
|
||
class UpdateUserPreferredTvRating implements UpdatesUserPreferredTvRating | ||
{ | ||
/** | ||
* Validate and update the given user's profile information. | ||
* | ||
* @param User $user | ||
* @param array $input | ||
* | ||
* @return void | ||
* @throws ValidationException | ||
*/ | ||
public function update(User $user, array $input) | ||
{ | ||
$rules = ['required', 'integer', 'not_in:0,1']; | ||
|
||
if ($input['tv_rating'] != -1) { | ||
array_push($rules, 'exists:' . TvRating::TABLE_NAME . ',id'); | ||
} | ||
|
||
Validator::make($input, [ | ||
'tv_rating' => $rules, | ||
])->validateWithBag('updatePreferredTvRating'); | ||
|
||
settings('tv_rating', (integer) $input['tv_rating']); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
app/Contracts/Web/Profile/UpdatesUserPreferredTvRating.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,17 @@ | ||
<?php | ||
|
||
namespace App\Contracts\Web\Profile; | ||
|
||
use App\Models\User; | ||
|
||
interface UpdatesUserPreferredTvRating | ||
{ | ||
/** | ||
* Validate and update the given user's preferred TV rating. | ||
* | ||
* @param User $user | ||
* @param array $input | ||
* @return void | ||
*/ | ||
public function update(User $user, array $input); | ||
} |
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Profile; | ||
|
||
use App\Contracts\Web\Profile\UpdatesUserPreferredTvRating; | ||
use Auth; | ||
use Illuminate\Contracts\Foundation\Application; | ||
use Illuminate\Contracts\View\Factory; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
|
||
class SelectPreferredTvRatingForm extends Component | ||
{ | ||
/** | ||
* The component's state. | ||
* | ||
* @var array | ||
*/ | ||
public array $state = []; | ||
|
||
/** | ||
* Prepare the component. | ||
* | ||
* @return void | ||
*/ | ||
public function mount() | ||
{ | ||
$this->state = [ | ||
'tv_rating' => settings('tv_rating') | ||
]; | ||
} | ||
|
||
/** | ||
* Update the user's preferred TV rating. | ||
* | ||
* @param UpdatesUserPreferredTvRating $updater | ||
*/ | ||
public function updatePreferredTvRating(UpdatesUserPreferredTvRating $updater) | ||
{ | ||
$this->resetErrorBag(); | ||
|
||
$updater->update(Auth::user(), $this->state); | ||
|
||
$this->emit('saved'); | ||
} | ||
|
||
/** | ||
* Render the component. | ||
* | ||
* @return Application|Factory|View | ||
*/ | ||
public function render(): Application|Factory|View | ||
{ | ||
return view('livewire.profile.select-preferred-tv-rating-form'); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class TvRating extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* The model's table name. | ||
* | ||
* @var string | ||
*/ | ||
const TABLE_NAME = 'tv_ratings'; | ||
|
||
/** | ||
* The model's table name. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = self::TABLE_NAME; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'rating', | ||
'description', | ||
]; | ||
|
||
/** | ||
* The accessors to append to the model's array form. | ||
* | ||
* @var array | ||
*/ | ||
protected $appends = [ | ||
'full_name' | ||
]; | ||
|
||
/** | ||
* The full name of the rating which combines the name and description attributes. | ||
* | ||
* @return string | ||
*/ | ||
public function getFullNameAttribute(): string | ||
{ | ||
return $this->name . ' - ' . $this->description; | ||
} | ||
|
||
/** | ||
* The anime belonging to the TV rating. | ||
* | ||
* @return HasMany | ||
*/ | ||
public function anime(): HasMany | ||
{ | ||
return $this->hasMany(Anime::class); | ||
} | ||
} |
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.