Skip to content

Commit

Permalink
Merge pull request rrze-mmz#48 from rrze-mmz/44-enhance-database-perf…
Browse files Browse the repository at this point in the history
…ormance-by-adding-indexes-in-migrations

Add indexes to migrations
  • Loading branch information
stefanosgeo authored Feb 5, 2024
2 parents 0e585b7 + bdc0e21 commit fa22898
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 75 deletions.
27 changes: 27 additions & 0 deletions app/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace App\Models;

use App\Enums\Role;
use App\Models\Traits\RecordsActivity;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Expand All @@ -26,4 +29,28 @@ public function owner(): BelongsTo
{
return $this->belongsTo(User::class);
}

/*
* activates a channel for a specific moderator
*/
/**
* @throws Exception
*/
public function activate(User $user): Channel|AuthorizationException|Exception
{
if (! $user->hasRole(Role::MODERATOR)) {
throw new AuthorizationException('The user does not have a role: moderator');
}

if ($user->has('channels')) {
throw new Exception('User has already a channel');
}

return Channel::create([
'url_handle' => '@'.Str::before($user->email, '@'),
'name' => $user->getFullNameAttribute(),
'description' => '',
'banner_url' => null,
]);
}
}
119 changes: 59 additions & 60 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fa22898

Please sign in to comment.