diff --git a/app/Console/Commands/CreateMainCharacteristics.php b/app/Console/Commands/CreateMainCharacteristics.php new file mode 100644 index 0000000..952c957 --- /dev/null +++ b/app/Console/Commands/CreateMainCharacteristics.php @@ -0,0 +1,73 @@ +lazy() as $name) { + + if (is_null($name->characteristics)) { + continue; + } + + $strings = explode(',', $name->characteristics); + foreach ($strings as $string) { + // lowercase + $lowercase = Str::lower($string); + + // remove the space at the beginning and the end + $string = Str::of($lowercase)->trim()->__toString(); + + // remove any comma or dot at the end + $string = Str::of($string)->rtrim(',.')->__toString(); + + // count the number of words and skip the word if there is more than 1 + $words = explode(' ', $string); + if (count($words) > 1) { + continue; + } + + $characteristic = Characteristic::firstOrCreate([ + 'name' => $string, + ]); + + $name->mainCharacteristics()->syncWithoutDetaching([$characteristic->id]); + } + } + } +} diff --git a/app/Console/Commands/FetchMetaData.php b/app/Console/Commands/FetchMetaData.php index 830ee02..13abca6 100644 --- a/app/Console/Commands/FetchMetaData.php +++ b/app/Console/Commands/FetchMetaData.php @@ -7,10 +7,12 @@ use App\Jobs\ProcessElficTraits; use App\Jobs\ProcessKlingonName; use App\Jobs\ProcessLitteratureReferences; +use App\Jobs\ProcessMainCaracteristics; use App\Jobs\ProcessMixte; use App\Jobs\ProcessOrigins; use App\Jobs\ProcessPersonality; use App\Jobs\ProcessSimilarNames; +use App\Jobs\ProcessSyllabes; use App\Models\Name; use Illuminate\Console\Command; @@ -72,9 +74,17 @@ public function handle(): void //ProcessKlingonName::dispatch($name); } - // if (is_null($name->unisex)) { - // ProcessMixte::dispatch($name); - // } + if (is_null($name->unisex)) { + ProcessMixte::dispatch($name); + } + + if ($name->syllabes === 0) { + ProcessSyllabes::dispatch($name); + } + + if (is_null($name->characteristics)) { + ProcessMainCaracteristics::dispatch($name); + } } } } diff --git a/app/Helpers/OpenAIHelper.php b/app/Helpers/OpenAIHelper.php index 5b5554f..d5b8bf8 100644 --- a/app/Helpers/OpenAIHelper.php +++ b/app/Helpers/OpenAIHelper.php @@ -167,7 +167,47 @@ public static function getUnisex(string $name): ?string [ 'role' => 'system', 'content' => <<<'PROMPT' -pour le prénom donné par l'utilisateur, indiquez si le prénom est unisexe. répondez uniquement par "oui" ou "non", sans rien d'autres, et sans les guillements bien sur. +pour le prénom donné par l'utilisateur, indiquez si le prénom est mixte/unisexe. répondez uniquement par "oui" ou "non", sans rien ajouter d'autres, et sans les guillements bien sur. +PROMPT, + ], [ + 'role' => 'user', + 'content' => $name, + ], + ], + ]); + + return $response->choices[0]->message->content; + } + + public static function getSyllabes(string $name): ?string + { + $response = OpenAI::chat()->create([ + 'model' => 'gpt-3.5-turbo', + 'messages' => [ + [ + 'role' => 'system', + 'content' => <<<'PROMPT' +pour le prénom donné par l'utilisateur, indique le nombre de syllabes. écris simplement le chiffre, sans rien d'autres. +PROMPT, + ], [ + 'role' => 'user', + 'content' => $name, + ], + ], + ]); + + return $response->choices[0]->message->content; + } + + public static function getMainCharacteristics(string $name): ?string + { + $response = OpenAI::chat()->create([ + 'model' => 'gpt-3.5-turbo', + 'messages' => [ + [ + 'role' => 'system', + 'content' => <<<'PROMPT' +pour le prénom donné par l'utilisateur, donne jusqu'à 3 termes ou qualités qui décrivent la personnalité du prénom. donne la reponse en mettant uniquement les mots, séparés par une virgule, sans rien d'autres. PROMPT, ], [ 'role' => 'user', diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index b072915..95ab112 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -31,8 +31,6 @@ public function create(): View public function store(Request $request): RedirectResponse { $request->validate([ - 'first_name' => ['required', 'string', 'max:255'], - 'last_name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class], 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); @@ -40,9 +38,6 @@ public function store(Request $request): RedirectResponse $user = (new CreateAccount( email: $request->input('email'), password: $request->input('password'), - firstName: $request->input('first_name'), - lastName: $request->input('last_name'), - organizationName: $request->input('organization_name'), ))->execute(); event(new Registered($user)); diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php new file mode 100644 index 0000000..39c5774 --- /dev/null +++ b/app/Http/Controllers/SearchController.php @@ -0,0 +1,40 @@ + $stats, + 'names' => SearchViewModel::names(), + ]); + } + + public function post(Request $request): View + { + $stats = Cache::remember('stats', 604800, function () { + return HomeViewModel::serverStats(); + }); + + $term = trim($request->input('term')); + $names = SearchViewModel::names($term); +dd($names); + return view('search.index', [ + 'stats' => $stats, + 'names' => $names, + 'term' => $term, + ]); + } +} diff --git a/app/Http/Controllers/Settings/SettingsLevelController.php b/app/Http/Controllers/Settings/SettingsLevelController.php deleted file mode 100644 index 506100f..0000000 --- a/app/Http/Controllers/Settings/SettingsLevelController.php +++ /dev/null @@ -1,96 +0,0 @@ -header('hx-request') && $request->header('hx-target') == 'levels-index') { - return view('settings.level.partials.index', [ - 'data' => SettingsLevelViewModel::index(), - ]); - } - - return view('settings.level.index', [ - 'data' => SettingsLevelViewModel::index(), - ]); - } - - public function new(): View - { - return view('settings.level.new'); - } - - public function store(Request $request): RedirectResponse - { - $validated = $request->validate([ - 'label' => 'required|string|max:255', - ]); - - (new CreateLevel( - label: $validated['label'], - ))->execute(); - - $request->session()->flash('status', __('The level has been created')); - - return redirect()->route('settings.level.index'); - } - - public function edit(Request $request, Level $level): View|RedirectResponse - { - try { - Level::where('organization_id', auth()->user()->organization_id) - ->findOrFail($level->id); - } catch (ModelNotFoundException) { - return redirect()->route('settings.level.index'); - } - - return view('settings.level.edit', [ - 'data' => SettingsLevelViewModel::level($level), - ]); - } - - public function update(Request $request, Level $level): RedirectResponse - { - $validated = $request->validate([ - 'label' => 'required|string|max:255', - ]); - - (new UpdateLevel( - level: $level, - label: $validated['label'], - ))->execute(); - - $request->session()->flash('status', __('Changes saved')); - - return redirect()->route('settings.level.index'); - } - - public function destroy(Request $request, Level $level): Response - { - try { - Level::where('organization_id', auth()->user()->organization_id) - ->findOrFail($level->id); - } catch (ModelNotFoundException) { - } - - (new DestroyLevel( - level: $level, - ))->execute(); - - return response()->make('', 200, ['HX-Trigger' => 'loadLevels']); - } -} diff --git a/app/Http/Controllers/Settings/SettingsProfileController.php b/app/Http/Controllers/Settings/SettingsProfileController.php deleted file mode 100644 index 30bc183..0000000 --- a/app/Http/Controllers/Settings/SettingsProfileController.php +++ /dev/null @@ -1,14 +0,0 @@ -header('hx-request') && $request->header('hx-target') == 'roles-index') { - return view('settings.role.partials.index', [ - 'data' => SettingsRoleViewModel::index(), - ]); - } - - return view('settings.role.index', [ - 'data' => SettingsRoleViewModel::index(), - ]); - } - - public function new(): View - { - return view('settings.role.new'); - } - - public function store(Request $request): RedirectResponse - { - $validated = $request->validate([ - 'label' => 'required|string|max:255', - ]); - - (new CreateRole( - label: $validated['label'], - ))->execute(); - - $request->session()->flash('status', __('The role has been created')); - - return redirect()->route('settings.role.index'); - } - - public function edit(Request $request, Role $role): View|RedirectResponse - { - try { - Role::where('organization_id', auth()->user()->organization_id) - ->findOrFail($role->id); - } catch (ModelNotFoundException) { - return redirect()->route('settings.role.index'); - } - - return view('settings.role.edit', [ - 'data' => SettingsRoleViewModel::role($role), - ]); - } - - public function update(Request $request, Role $role): RedirectResponse - { - $validated = $request->validate([ - 'label' => 'required|string|max:255', - ]); - - (new UpdateRole( - role: $role, - label: $validated['label'], - ))->execute(); - - $request->session()->flash('status', __('Changes saved')); - - return redirect()->route('settings.role.index'); - } - - public function destroy(Request $request, Role $role): Response - { - try { - Role::where('organization_id', auth()->user()->organization_id) - ->findOrFail($role->id); - } catch (ModelNotFoundException) { - } - - (new DestroyRole( - role: $role, - ))->execute(); - - return response()->make('', 200, ['HX-Trigger' => 'loadRoles']); - } -} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index bbcaa95..21806d5 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -65,7 +65,6 @@ class Kernel extends HttpKernel 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, - 'administrator' => \App\Http\Middleware\CheckAdministratorRole::class, 'name' => \App\Http\Middleware\CheckName::class, 'letter' => \App\Http\Middleware\CheckLetter::class, ]; diff --git a/app/Http/Middleware/CheckAdministratorRole.php b/app/Http/Middleware/CheckAdministratorRole.php deleted file mode 100644 index e96bc15..0000000 --- a/app/Http/Middleware/CheckAdministratorRole.php +++ /dev/null @@ -1,28 +0,0 @@ -user()->permissions === User::ROLE_ADMINISTRATOR || - $request->user()->permissions === User::ROLE_ACCOUNT_MANAGER - ) { - return $next($request); - } - - abort(401); - } -} diff --git a/app/Http/ViewModels/Names/NameViewModel.php b/app/Http/ViewModels/Names/NameViewModel.php index 8faaecf..6e4dc79 100644 --- a/app/Http/ViewModels/Names/NameViewModel.php +++ b/app/Http/ViewModels/Names/NameViewModel.php @@ -19,7 +19,7 @@ public static function details(Name $name): array 'avatar' => $name->avatar, 'origins' => Str::of($name->origins)->markdown(), 'personality' => Str::of($name->personality)->markdown(), - 'country_of_origin' => Str::of($name->country_of_origin)->markdown(), + 'syllabes' => $name->syllabes, 'celebrities' => Str::of($name->celebrities)->markdown(), 'elfic_traits' => Str::of($name->elfic_traits)->markdown(), 'name_day' => Str::of($name->name_day)->markdown(), @@ -55,13 +55,21 @@ public static function popularity(Name $name): array // now we need to add the percentage of popularity for each decade $total = $decadesCollection->sum('popularity'); $decadesCollection = $decadesCollection->map(function ($decade) use ($total) { - $decade['percentage'] = Number::format(round($decade['popularity'] / $total * 100), locale: 'fr'); + if ($total > 0) { + $decade['percentage'] = Number::format(round($decade['popularity'] / $total * 100), locale: 'fr'); + } else { + $decade['percentage'] = 0; + } return $decade; }); + // calculate the total popularity + $total = $name->total; + return [ 'decades' => $decadesCollection, + 'total' => Number::format($total, locale: 'fr'), ]; } diff --git a/app/Http/ViewModels/Search/SearchViewModel.php b/app/Http/ViewModels/Search/SearchViewModel.php new file mode 100644 index 0000000..291fce8 --- /dev/null +++ b/app/Http/ViewModels/Search/SearchViewModel.php @@ -0,0 +1,35 @@ +where('name', '!=', '_PRENOMS_RARES') + ->orderBy('total', 'desc') + ->take(20) + ->get() + ->map(fn (Name $name) => [ + 'id' => $name->id, + 'name' => StringHelper::formatNameFromDB($name->name), + 'avatar' => $name->avatar, + 'url' => route('name.show', [ + 'id' => $name->id, + 'name' => StringHelper::sanitizeNameForURL($name->name), + ]), + ]); + + return [ + 'names' => $names, + 'total' => $names->count(), + ]; + } +} diff --git a/app/Jobs/PopulateAccount.php b/app/Jobs/PopulateAccount.php deleted file mode 100644 index eeed22e..0000000 --- a/app/Jobs/PopulateAccount.php +++ /dev/null @@ -1,79 +0,0 @@ -addRoles(); - $this->addLevels(); - } - - private function addRoles(): void - { - $roles = [ - trans_key('Software Engineer'), - trans_key('Quality Assurance Engineer'), - trans_key('Project Manager'), - trans_key('Product Manager'), - trans_key('UI/UX Designer'), - trans_key('Data Analyst/Scientist'), - trans_key('DevOps Engineer'), - trans_key('Technical Support Engineer'), - trans_key('Scrum Master'), - trans_key('Sales/Account Manager'), - trans_key('Technical Writer'), - trans_key('System Administrator'), - trans_key('Chief Executive Officer'), - ]; - - foreach ($roles as $role) { - DB::table('roles')->insert([ - 'organization_id' => $this->organization->id, - 'label' => null, - 'label_translation_key' => $role, - 'created_at' => now(), - ]); - } - } - - private function addLevels(): void - { - $levels = [ - trans_key('Junior'), - trans_key('Intermediate'), - trans_key('Senior'), - trans_key('Staff'), - ]; - - foreach ($levels as $level) { - DB::table('levels')->insert([ - 'organization_id' => $this->organization->id, - 'label' => null, - 'label_translation_key' => $level, - 'created_at' => now(), - ]); - } - } -} diff --git a/app/Jobs/ProcessMainCaracteristics.php b/app/Jobs/ProcessMainCaracteristics.php new file mode 100644 index 0000000..ad47067 --- /dev/null +++ b/app/Jobs/ProcessMainCaracteristics.php @@ -0,0 +1,39 @@ +name->characteristics)) { + $strings = OpenAIHelper::getMainCharacteristics($this->name->name); + + $this->name->characteristics = Str::lower($strings); + $this->name->save(); + } + } +} diff --git a/app/Jobs/ProcessMixte.php b/app/Jobs/ProcessMixte.php index 8631f38..4aa26ba 100644 --- a/app/Jobs/ProcessMixte.php +++ b/app/Jobs/ProcessMixte.php @@ -30,9 +30,9 @@ public function handle(): void if ($this->name->unisex === null) { $answer = OpenAIHelper::getUnisex($this->name->name); - if ($answer == 'yes') { + if ($answer == 'oui') { $answer = true; - } elseif ($answer == 'no') { + } elseif ($answer == 'non') { $answer = false; } else { $answer = null; diff --git a/app/Jobs/ProcessSyllabes.php b/app/Jobs/ProcessSyllabes.php new file mode 100644 index 0000000..8bc3d03 --- /dev/null +++ b/app/Jobs/ProcessSyllabes.php @@ -0,0 +1,37 @@ +name->syllabes === 0) { + $number = OpenAIHelper::getSyllabes($this->name->name); + + $this->name->syllabes = $number; + $this->name->save(); + } + } +} diff --git a/app/Models/Characteristic.php b/app/Models/Characteristic.php new file mode 100644 index 0000000..1265025 --- /dev/null +++ b/app/Models/Characteristic.php @@ -0,0 +1,25 @@ +belongsToMany(Name::class); + } +} diff --git a/app/Models/Level.php b/app/Models/Level.php deleted file mode 100644 index 9d2cb29..0000000 --- a/app/Models/Level.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ - protected $fillable = [ - 'organization_id', - 'label', - 'label_translation_key', - ]; - - public function organization(): BelongsTo - { - return $this->belongsTo(Organization::class); - } -} diff --git a/app/Models/Name.php b/app/Models/Name.php index 9aa000e..acf1f1e 100644 --- a/app/Models/Name.php +++ b/app/Models/Name.php @@ -5,11 +5,13 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Laravel\Scout\Searchable; class Name extends Model { - use HasFactory; + use HasFactory, Searchable; protected $table = 'names'; @@ -26,6 +28,8 @@ class Name extends Model 'similar_names_in_other_languages', 'klingon_translation', 'unisex', + 'syllabes', + 'characteristics', 'total', 'page_views', ]; @@ -36,6 +40,19 @@ class Name extends Model 'name' => 'string', ]; + /** + * Get the indexable data array for the model. + * + * @return array + */ + public function toSearchableArray(): array + { + return [ + 'id' => (int) $this->id, + 'name' => $this->name, + ]; + } + public function nameStatistics(): HasMany { return $this->hasMany(NameStatistic::class); @@ -55,4 +72,9 @@ protected function avatar(): Attribute } ); } + + public function mainCharacteristics(): BelongsToMany + { + return $this->belongsToMany(Characteristic::class); + } } diff --git a/app/Models/Organization.php b/app/Models/Organization.php deleted file mode 100644 index 861389f..0000000 --- a/app/Models/Organization.php +++ /dev/null @@ -1,29 +0,0 @@ -hasMany(Role::class); - } - - public function levels(): HasMany - { - return $this->hasMany(Level::class); - } -} diff --git a/app/Models/Role.php b/app/Models/Role.php deleted file mode 100644 index 9414739..0000000 --- a/app/Models/Role.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ - protected $fillable = [ - 'organization_id', - 'label', - 'label_translation_key', - ]; - - public function organization(): BelongsTo - { - return $this->belongsTo(Organization::class); - } -} diff --git a/app/Models/User.php b/app/Models/User.php index b06e250..2a74eed 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,7 +4,6 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; @@ -25,15 +24,9 @@ class User extends Authenticatable implements MustVerifyEmail * @var array */ protected $fillable = [ - 'first_name', - 'last_name', - 'organization_id', - 'name_for_avatar', 'email', 'email_verified_at', 'password', - 'permissions', - 'locale', ]; /** @@ -55,9 +48,4 @@ class User extends Authenticatable implements MustVerifyEmail 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; - - public function organization(): BelongsTo - { - return $this->belongsTo(Organization::class); - } } diff --git a/app/Services/CreateAccount.php b/app/Services/CreateAccount.php index 7151a5f..4f0fa90 100644 --- a/app/Services/CreateAccount.php +++ b/app/Services/CreateAccount.php @@ -2,8 +2,6 @@ namespace App\Services; -use App\Jobs\PopulateAccount; -use App\Models\Organization; use App\Models\User; use Illuminate\Support\Facades\Hash; @@ -13,44 +11,25 @@ class CreateAccount extends BaseService { private User $user; - private Organization $organization; public function __construct( public string $email, public string $password, - public string $firstName, - public string $lastName, - public string $organizationName ) { } public function execute(): User { - $this->createOrganization(); $this->createUser(); - PopulateAccount::dispatch($this->organization); - return $this->user; } private function createUser(): void { $this->user = User::create([ - 'first_name' => $this->firstName, - 'last_name' => $this->lastName, 'email' => $this->email, - 'name_for_avatar' => $this->firstName, 'password' => Hash::make($this->password), - 'organization_id' => $this->organization->id, - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - } - - private function createOrganization(): void - { - $this->organization = Organization::create([ - 'name' => $this->organizationName, ]); } } diff --git a/app/Services/CreateLevel.php b/app/Services/CreateLevel.php deleted file mode 100644 index 1be46ea..0000000 --- a/app/Services/CreateLevel.php +++ /dev/null @@ -1,41 +0,0 @@ -checkPermissions(); - $this->create(); - - return $this->level; - } - - private function checkPermissions(): void - { - if (auth()->user()->permissions !== User::ROLE_ACCOUNT_MANAGER && - auth()->user()->permissions !== User::ROLE_ADMINISTRATOR) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function create(): void - { - $this->level = Level::create([ - 'organization_id' => auth()->user()->organization_id, - 'label' => $this->label, - ]); - } -} diff --git a/app/Services/CreateRole.php b/app/Services/CreateRole.php deleted file mode 100644 index 7aec017..0000000 --- a/app/Services/CreateRole.php +++ /dev/null @@ -1,41 +0,0 @@ -checkPermissions(); - $this->create(); - - return $this->role; - } - - private function checkPermissions(): void - { - if (auth()->user()->permissions !== User::ROLE_ACCOUNT_MANAGER && - auth()->user()->permissions !== User::ROLE_ADMINISTRATOR) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function create(): void - { - $this->role = Role::create([ - 'organization_id' => auth()->user()->organization_id, - 'label' => $this->label, - ]); - } -} diff --git a/app/Services/DestroyLevel.php b/app/Services/DestroyLevel.php deleted file mode 100644 index cb77787..0000000 --- a/app/Services/DestroyLevel.php +++ /dev/null @@ -1,44 +0,0 @@ -checkPermissions(); - $this->checkLevel(); - $this->destroy(); - } - - public function destroy(): void - { - $this->level->delete(); - } - - private function checkPermissions(): void - { - if ( - auth()->user()->permissions !== User::ROLE_ACCOUNT_MANAGER && - auth()->user()->permissions !== User::ROLE_ADMINISTRATOR - ) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function checkLevel(): void - { - if ($this->level->organization_id !== auth()->user()->organization_id) { - throw new Exception(__('You do not have permission to do this action.')); - } - } -} diff --git a/app/Services/DestroyRole.php b/app/Services/DestroyRole.php deleted file mode 100644 index 1b4a6b8..0000000 --- a/app/Services/DestroyRole.php +++ /dev/null @@ -1,44 +0,0 @@ -checkPermissions(); - $this->checkRole(); - $this->destroy(); - } - - public function destroy(): void - { - $this->role->delete(); - } - - private function checkPermissions(): void - { - if ( - auth()->user()->permissions !== User::ROLE_ACCOUNT_MANAGER && - auth()->user()->permissions !== User::ROLE_ADMINISTRATOR - ) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function checkRole(): void - { - if ($this->role->organization_id !== auth()->user()->organization_id) { - throw new Exception(__('You do not have permission to do this action.')); - } - } -} diff --git a/app/Services/UpdateLevel.php b/app/Services/UpdateLevel.php deleted file mode 100644 index e50dbd0..0000000 --- a/app/Services/UpdateLevel.php +++ /dev/null @@ -1,49 +0,0 @@ -checkPermissions(); - $this->checkLevel(); - $this->update(); - - return $this->level; - } - - private function checkPermissions(): void - { - if ( - auth()->user()->permissions !== User::ROLE_ACCOUNT_MANAGER && - auth()->user()->permissions !== User::ROLE_ADMINISTRATOR - ) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function checkLevel(): void - { - if ($this->level->organization_id !== auth()->user()->organization_id) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function update(): void - { - $this->level->update([ - 'label' => $this->label, - ]); - } -} diff --git a/app/Services/UpdateRole.php b/app/Services/UpdateRole.php deleted file mode 100644 index e5ce8c7..0000000 --- a/app/Services/UpdateRole.php +++ /dev/null @@ -1,49 +0,0 @@ -checkPermissions(); - $this->checkRole(); - $this->update(); - - return $this->role; - } - - private function checkPermissions(): void - { - if ( - auth()->user()->permissions !== User::ROLE_ACCOUNT_MANAGER && - auth()->user()->permissions !== User::ROLE_ADMINISTRATOR - ) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function checkRole(): void - { - if ($this->role->organization_id !== auth()->user()->organization_id) { - throw new Exception(__('You do not have permission to do this action.')); - } - } - - private function update(): void - { - $this->role->update([ - 'label' => $this->label, - ]); - } -} diff --git a/app/Traits/Translatable.php b/app/Traits/Translatable.php deleted file mode 100644 index 30927bf..0000000 --- a/app/Traits/Translatable.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ - protected function label(): Attribute - { - return Attribute::make( - get: function ($value, $attributes) { - if (! $value) { - return __($attributes['label_translation_key']); - } - - return $value; - } - ); - } -} diff --git a/app/View/Components/LoginLayout.php b/app/View/Components/LoginLayout.php new file mode 100644 index 0000000..e00d706 --- /dev/null +++ b/app/View/Components/LoginLayout.php @@ -0,0 +1,17 @@ +=3.0", + "doctrine/dbal": ">=4.0", "tightenco/collect": "<5.5.33" }, "provide": { @@ -1588,6 +1590,7 @@ "files": [ "src/Illuminate/Collections/helpers.php", "src/Illuminate/Events/functions.php", + "src/Illuminate/Filesystem/functions.php", "src/Illuminate/Foundation/helpers.php", "src/Illuminate/Support/helpers.php" ], @@ -1620,7 +1623,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2023-12-19T14:59:00+00:00" + "time": "2023-12-22T14:39:10+00:00" }, { "name": "laravel/prompts", @@ -1745,6 +1748,81 @@ }, "time": "2023-11-03T13:42:14+00:00" }, + { + "name": "laravel/scout", + "version": "v10.6.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/scout.git", + "reference": "fc9bc0c2061eb54b31d9dba0999755177a8f1a0e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/scout/zipball/fc9bc0c2061eb54b31d9dba0999755177a8f1a0e", + "reference": "fc9bc0c2061eb54b31d9dba0999755177a8f1a0e", + "shasum": "" + }, + "require": { + "illuminate/bus": "^9.0|^10.0", + "illuminate/contracts": "^9.0|^10.0", + "illuminate/database": "^9.0|^10.0", + "illuminate/http": "^9.0|^10.0", + "illuminate/pagination": "^9.0|^10.0", + "illuminate/queue": "^9.0|^10.0", + "illuminate/support": "^9.0|^10.0", + "php": "^8.0" + }, + "require-dev": { + "algolia/algoliasearch-client-php": "^3.2", + "meilisearch/meilisearch-php": "^1.0", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^7.31|^8.11", + "php-http/guzzle7-adapter": "^1.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "algolia/algoliasearch-client-php": "Required to use the Algolia engine (^3.2).", + "meilisearch/meilisearch-php": "Required to use the Meilisearch engine (^1.0)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "10.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Scout\\ScoutServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Scout\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Scout provides a driver based solution to searching your Eloquent models.", + "keywords": [ + "algolia", + "laravel", + "search" + ], + "support": { + "issues": "https://github.com/laravel/scout/issues", + "source": "https://github.com/laravel/scout" + }, + "time": "2023-12-05T19:44:31+00:00" + }, { "name": "laravel/serializable-closure", "version": "v1.3.3", @@ -2768,16 +2846,16 @@ }, { "name": "openai-php/client", - "version": "v0.8.0", + "version": "v0.8.1", "source": { "type": "git", "url": "https://github.com/openai-php/client.git", - "reference": "d0e4996f6446ced6ad35ec0ea6af20e3596c648f" + "reference": "ce84f541fe8a2869de7f48030d5757be1fd604c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/openai-php/client/zipball/d0e4996f6446ced6ad35ec0ea6af20e3596c648f", - "reference": "d0e4996f6446ced6ad35ec0ea6af20e3596c648f", + "url": "https://api.github.com/repos/openai-php/client/zipball/ce84f541fe8a2869de7f48030d5757be1fd604c9", + "reference": "ce84f541fe8a2869de7f48030d5757be1fd604c9", "shasum": "" }, "require": { @@ -2790,17 +2868,17 @@ "psr/http-message": "^1.1.0|^2.0.0" }, "require-dev": { - "guzzlehttp/guzzle": "^7.8.0", - "guzzlehttp/psr7": "^2.6.1", - "laravel/pint": "^1.13.6", - "mockery/mockery": "^1.6.6", + "guzzlehttp/guzzle": "^7.8.1", + "guzzlehttp/psr7": "^2.6.2", + "laravel/pint": "^1.13.7", + "mockery/mockery": "^1.6.7", "nunomaduro/collision": "^7.10.0", - "pestphp/pest": "^2.25.0", - "pestphp/pest-plugin-arch": "^2.4.1", + "pestphp/pest": "^2.28.1", + "pestphp/pest-plugin-arch": "^2.5", "pestphp/pest-plugin-type-coverage": "^2.5.0", - "phpstan/phpstan": "^1.10.44", + "phpstan/phpstan": "^1.10.50", "rector/rector": "^0.16.0", - "symfony/var-dumper": "^6.3.8" + "symfony/var-dumper": "^6.4" }, "type": "library", "autoload": { @@ -2840,7 +2918,7 @@ ], "support": { "issues": "https://github.com/openai-php/client/issues", - "source": "https://github.com/openai-php/client/tree/v0.8.0" + "source": "https://github.com/openai-php/client/tree/v0.8.1" }, "funding": [ { @@ -2856,7 +2934,7 @@ "type": "github" } ], - "time": "2023-11-23T14:04:47+00:00" + "time": "2023-12-22T15:18:26+00:00" }, { "name": "openai-php/laravel", @@ -9681,23 +9759,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "10.1.10", + "version": "10.1.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "599109c8ca6bae97b23482d557d2874c25a65e59" + "reference": "78c3b7625965c2513ee96569a4dbb62601784145" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/599109c8ca6bae97b23482d557d2874c25a65e59", - "reference": "599109c8ca6bae97b23482d557d2874c25a65e59", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/78c3b7625965c2513ee96569a4dbb62601784145", + "reference": "78c3b7625965c2513ee96569a4dbb62601784145", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=8.1", "phpunit/php-file-iterator": "^4.0", "phpunit/php-text-template": "^3.0", @@ -9747,7 +9825,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.10" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.11" }, "funding": [ { @@ -9755,7 +9833,7 @@ "type": "github" } ], - "time": "2023-12-11T06:28:43+00:00" + "time": "2023-12-21T15:38:30+00:00" }, { "name": "phpunit/php-file-iterator", @@ -10522,20 +10600,20 @@ }, { "name": "sebastian/complexity", - "version": "3.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "68cfb347a44871f01e33ab0ef8215966432f6957" + "reference": "68ff824baeae169ec9f2137158ee529584553799" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68cfb347a44871f01e33ab0ef8215966432f6957", - "reference": "68cfb347a44871f01e33ab0ef8215966432f6957", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799", + "reference": "68ff824baeae169ec9f2137158ee529584553799", "shasum": "" }, "require": { - "nikic/php-parser": "^4.10", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=8.1" }, "require-dev": { @@ -10544,7 +10622,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.1-dev" + "dev-main": "3.2-dev" } }, "autoload": { @@ -10568,7 +10646,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", "security": "https://github.com/sebastianbergmann/complexity/security/policy", - "source": "https://github.com/sebastianbergmann/complexity/tree/3.1.0" + "source": "https://github.com/sebastianbergmann/complexity/tree/3.2.0" }, "funding": [ { @@ -10576,20 +10654,20 @@ "type": "github" } ], - "time": "2023-09-28T11:50:59+00:00" + "time": "2023-12-21T08:37:17+00:00" }, { "name": "sebastian/diff", - "version": "5.0.3", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" + "reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/fbf413a49e54f6b9b17e12d900ac7f6101591b7f", + "reference": "fbf413a49e54f6b9b17e12d900ac7f6101591b7f", "shasum": "" }, "require": { @@ -10602,7 +10680,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "5.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -10635,7 +10713,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", "security": "https://github.com/sebastianbergmann/diff/security/policy", - "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/diff/tree/5.1.0" }, "funding": [ { @@ -10643,7 +10721,7 @@ "type": "github" } ], - "time": "2023-05-01T07:48:21+00:00" + "time": "2023-12-22T10:55:06+00:00" }, { "name": "sebastian/environment", @@ -10851,20 +10929,20 @@ }, { "name": "sebastian/lines-of-code", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d" + "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/649e40d279e243d985aa8fb6e74dd5bb28dc185d", - "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0", + "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0", "shasum": "" }, "require": { - "nikic/php-parser": "^4.10", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=8.1" }, "require-dev": { @@ -10897,7 +10975,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.1" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.2" }, "funding": [ { @@ -10905,7 +10983,7 @@ "type": "github" } ], - "time": "2023-08-31T09:25:50+00:00" + "time": "2023-12-21T08:38:20+00:00" }, { "name": "sebastian/object-enumerator", @@ -11471,16 +11549,16 @@ }, { "name": "spatie/laravel-ignition", - "version": "2.3.2", + "version": "2.3.3", "source": { "type": "git", "url": "https://github.com/spatie/laravel-ignition.git", - "reference": "4800661a195e15783477d99f7f8f669a49793996" + "reference": "66499cd3c858642ded56dafb8fa0352057ca20dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/4800661a195e15783477d99f7f8f669a49793996", - "reference": "4800661a195e15783477d99f7f8f669a49793996", + "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/66499cd3c858642ded56dafb8fa0352057ca20dd", + "reference": "66499cd3c858642ded56dafb8fa0352057ca20dd", "shasum": "" }, "require": { @@ -11559,7 +11637,7 @@ "type": "github" } ], - "time": "2023-12-15T13:44:49+00:00" + "time": "2023-12-21T09:43:05+00:00" }, { "name": "spatie/laravel-ray", diff --git a/config/scout.php b/config/scout.php new file mode 100644 index 0000000..481d9c3 --- /dev/null +++ b/config/scout.php @@ -0,0 +1,142 @@ + env('SCOUT_DRIVER', 'algolia'), + + /* + |-------------------------------------------------------------------------- + | Index Prefix + |-------------------------------------------------------------------------- + | + | Here you may specify a prefix that will be applied to all search index + | names used by Scout. This prefix may be useful if you have multiple + | "tenants" or applications sharing the same search infrastructure. + | + */ + + 'prefix' => env('SCOUT_PREFIX', ''), + + /* + |-------------------------------------------------------------------------- + | Queue Data Syncing + |-------------------------------------------------------------------------- + | + | This option allows you to control if the operations that sync your data + | with your search engines are queued. When this is set to "true" then + | all automatic data syncing will get queued for better performance. + | + */ + + 'queue' => env('SCOUT_QUEUE', false), + + /* + |-------------------------------------------------------------------------- + | Database Transactions + |-------------------------------------------------------------------------- + | + | This configuration option determines if your data will only be synced + | with your search indexes after every open database transaction has + | been committed, thus preventing any discarded data from syncing. + | + */ + + 'after_commit' => false, + + /* + |-------------------------------------------------------------------------- + | Chunk Sizes + |-------------------------------------------------------------------------- + | + | These options allow you to control the maximum chunk size when you are + | mass importing data into the search engine. This allows you to fine + | tune each of these chunk sizes based on the power of the servers. + | + */ + + 'chunk' => [ + 'searchable' => 500, + 'unsearchable' => 500, + ], + + /* + |-------------------------------------------------------------------------- + | Soft Deletes + |-------------------------------------------------------------------------- + | + | This option allows to control whether to keep soft deleted records in + | the search indexes. Maintaining soft deleted records can be useful + | if your application still needs to search for the records later. + | + */ + + 'soft_delete' => false, + + /* + |-------------------------------------------------------------------------- + | Identify User + |-------------------------------------------------------------------------- + | + | This option allows you to control whether to notify the search engine + | of the user performing the search. This is sometimes useful if the + | engine supports any analytics based on this application's users. + | + | Supported engines: "algolia" + | + */ + + 'identify' => env('SCOUT_IDENTIFY', false), + + /* + |-------------------------------------------------------------------------- + | Algolia Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure your Algolia settings. Algolia is a cloud hosted + | search engine which works great with Scout out of the box. Just plug + | in your application ID and admin API key to get started searching. + | + */ + + 'algolia' => [ + 'id' => env('ALGOLIA_APP_ID', ''), + 'secret' => env('ALGOLIA_SECRET', ''), + ], + + /* + |-------------------------------------------------------------------------- + | Meilisearch Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure your Meilisearch settings. Meilisearch is an open + | source search engine with minimal configuration. Below, you can state + | the host and key information for your own Meilisearch installation. + | + | See: https://www.meilisearch.com/docs/learn/configuration/instance_options#all-instance-options + | + */ + + 'meilisearch' => [ + 'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'), + 'key' => env('MEILISEARCH_KEY'), + 'index-settings' => [ + // 'users' => [ + // 'filterableAttributes'=> ['id', 'name', 'email'], + // ], + ], + ], + +]; diff --git a/database/factories/LevelFactory.php b/database/factories/LevelFactory.php deleted file mode 100644 index 66f6070..0000000 --- a/database/factories/LevelFactory.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -class LevelFactory extends Factory -{ - /** - * Define the model's default state. - * - * @return array - */ - public function definition(): array - { - return [ - 'organization_id' => Organization::factory(), - 'label' => fake()->name, - 'label_translation_key' => fake()->name, - ]; - } -} diff --git a/database/factories/OrganizationFactory.php b/database/factories/OrganizationFactory.php deleted file mode 100644 index ec6dcd5..0000000 --- a/database/factories/OrganizationFactory.php +++ /dev/null @@ -1,23 +0,0 @@ - - */ -class OrganizationFactory extends Factory -{ - /** - * Define the model's default state. - * - * @return array - */ - public function definition(): array - { - return [ - 'name' => 'Dunder Mifflin', - ]; - } -} diff --git a/database/factories/RoleFactory.php b/database/factories/RoleFactory.php deleted file mode 100644 index 5ba8e43..0000000 --- a/database/factories/RoleFactory.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -class RoleFactory extends Factory -{ - /** - * Define the model's default state. - * - * @return array - */ - public function definition(): array - { - return [ - 'organization_id' => Organization::factory(), - 'label' => fake()->name, - 'label_translation_key' => fake()->name, - ]; - } -} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index f85bc22..4ae6dec 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,8 +2,6 @@ namespace Database\Factories; -use App\Models\Organization; -use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; @@ -23,15 +21,10 @@ class UserFactory extends Factory public function definition(): array { return [ - 'organization_id' => Organization::factory(), - 'first_name' => fake()->name(), - 'last_name' => fake()->name(), - 'name_for_avatar' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => static::$password ??= Hash::make('password'), 'remember_token' => Str::random(10), - 'permissions' => User::ROLE_ADMINISTRATOR, ]; } diff --git a/database/migrations/2014_04_13_002417_create_organizations_table.php b/database/migrations/2014_04_13_002417_create_organizations_table.php deleted file mode 100644 index f832e1b..0000000 --- a/database/migrations/2014_04_13_002417_create_organizations_table.php +++ /dev/null @@ -1,18 +0,0 @@ -id(); - $table->string('name'); - $table->string('licence_key')->nullable(); - $table->timestamps(); - }); - } -}; diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 0004cd6..4cf6545 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -13,18 +13,11 @@ public function up(): void { Schema::create('users', function (Blueprint $table): void { $table->id(); - $table->unsignedBigInteger('organization_id'); - $table->string('first_name')->nullable(); - $table->string('last_name')->nullable(); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); - $table->string('permissions'); - $table->string('name_for_avatar'); - $table->string('locale')->default('en'); $table->rememberToken(); $table->timestamps(); - $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('cascade'); }); } }; diff --git a/database/migrations/2023_11_13_200951_create_roles_table.php b/database/migrations/2023_11_13_200951_create_roles_table.php deleted file mode 100644 index 1046155..0000000 --- a/database/migrations/2023_11_13_200951_create_roles_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->unsignedBigInteger('organization_id'); - $table->string('label')->nullable(); - $table->string('label_translation_key')->nullable(); - $table->timestamps(); - $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('cascade'); - }); - - Schema::create('levels', function (Blueprint $table): void { - $table->id(); - $table->unsignedBigInteger('organization_id'); - $table->string('label')->nullable(); - $table->string('label_translation_key')->nullable(); - $table->timestamps(); - $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('cascade'); - }); - } -}; diff --git a/database/migrations/2023_12_08_013120_create_name_table.php b/database/migrations/2023_12_08_013120_create_name_table.php index 999515a..98104b9 100644 --- a/database/migrations/2023_12_08_013120_create_name_table.php +++ b/database/migrations/2023_12_08_013120_create_name_table.php @@ -24,7 +24,9 @@ public function up(): void $table->text('litterature_artistics_references')->nullable(); $table->text('similar_names_in_other_languages')->nullable(); $table->text('klingon_translation')->nullable(); + $table->integer('syllabes')->default(0); $table->boolean('unisex')->nullable(); + $table->string('characteristics')->nullable(); $table->integer('total')->default(0); $table->integer('page_views')->default(0); $table->timestamps(); diff --git a/database/migrations/2023_12_21_004721_create_characteristics_table.php b/database/migrations/2023_12_21_004721_create_characteristics_table.php new file mode 100644 index 0000000..1212f0c --- /dev/null +++ b/database/migrations/2023_12_21_004721_create_characteristics_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + + Schema::create('characteristic_name', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('characteristic_id'); + $table->unsignedBigInteger('name_id'); + $table->timestamps(); + $table->foreign('characteristic_id')->references('id')->on('characteristics')->onDelete('cascade'); + $table->foreign('name_id')->references('id')->on('names')->onDelete('cascade'); + }); + } +}; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 64b16f7..7f16287 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,4 +1,4 @@ - + - + diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index b99b545..90193d8 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1,49 +1,21 @@ - +
-

{{ __('Welcome to Shelter') }}

-

{{ __('Be part of something unique.') }}

+

Bienvenue

+

Créez un compte pour sauvegarder vos noms préférés et les faire voter par ceux qui vous aiment.

@csrf
- -
-
- - - -
- -
- - - -
-
-
- + - {{ __('We will send you a verification email, and won\'t spam you.') }} + Nous vous enverrons un email de vérification, et ne vous spammerons jamais. @@ -61,7 +33,7 @@
- +
- +
-
- - - - - -
-
- {{ __('Register') }} + {{ __('Créez le compte') }} - {{ __('Already registered?') }} + {{ __('Déjà inscrit ?') }}
- + diff --git a/resources/views/layouts/footer.blade.php b/resources/views/layouts/footer.blade.php new file mode 100644 index 0000000..8af85e0 --- /dev/null +++ b/resources/views/layouts/footer.blade.php @@ -0,0 +1,5 @@ +
+
+ © 2023-{{ now()->year }} +
+
diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php index fbe392d..664d57b 100644 --- a/resources/views/layouts/guest.blade.php +++ b/resources/views/layouts/guest.blade.php @@ -21,16 +21,8 @@ {{ $slot }}
- -
-
    -
  • - {{ __('English') }} -
  • -
  • - {{ __('French') }} -
  • -
+
+ @include('layouts.footer')
diff --git a/resources/views/layouts/login.blade.php b/resources/views/layouts/login.blade.php new file mode 100644 index 0000000..b1593f9 --- /dev/null +++ b/resources/views/layouts/login.blade.php @@ -0,0 +1,39 @@ + + + + + + + + + {{ config('app.name', 'Laravel') }} + + + @vite(['resources/css/app.css', 'resources/js/app.js']) + + {{ $jsonLdSchema ?? '' }} + + + + + +
+
+ {{ $slot }} +
+ + +
+
    +
  • + {{ __('English') }} +
  • +
  • + {{ __('French') }} +
  • +
+
+
+ + + diff --git a/resources/views/layouts/unlogged-navigation.blade.php b/resources/views/layouts/unlogged-navigation.blade.php index 353eab2..cd0081a 100644 --- a/resources/views/layouts/unlogged-navigation.blade.php +++ b/resources/views/layouts/unlogged-navigation.blade.php @@ -21,6 +21,9 @@ {{ __('Tous les prénoms') }} + + {{ __('Recherche') }} +
diff --git a/resources/views/names/show.blade.php b/resources/views/names/show.blade.php index ab88b2c..1ce61c6 100644 --- a/resources/views/names/show.blade.php +++ b/resources/views/names/show.blade.php @@ -62,8 +62,8 @@ -
-
    +
    +
    - +
    -

    Pays d'origine

    -
    {!! $name['country_of_origin'] !!}
    +

    Nombre de syllabes

    +
    {!! $name['syllabes'] !!}
    @@ -99,7 +99,7 @@

    -
    {!! $name['country_of_origin'] !!}
    +
    {!! $name['syllabes'] !!}
    @@ -177,7 +177,6 @@

    Popularités par décennies

    - @foreach ($popularity['decades'] as $popularityItem) @@ -191,6 +190,7 @@ @endforeach
    Front End Developer Salary
    +

    Utilisé {{ $popularity['total'] }} fois depuis 1900.

    diff --git a/resources/views/search/index.blade.php b/resources/views/search/index.blade.php new file mode 100644 index 0000000..619697b --- /dev/null +++ b/resources/views/search/index.blade.php @@ -0,0 +1,43 @@ + +
    +
    + @include('layouts.unlogged-navigation') +
    + +
    +
    +
      +
    • + Accueil +
    • +
    • Recherche de prénoms
    • +
    +
    +
    +
    + +
    +
    +

    Recherche instantanée

    +
    +
    + + +
    +
    + +

    {{ $stats['total_names'] }} noms | 371 listes de prénoms

    +
    + +
    +
    +

    Les résultats

    + @include('search.partials.results') +
    +
    +
    +
    diff --git a/resources/views/search/partials/results.blade.php b/resources/views/search/partials/results.blade.php new file mode 100644 index 0000000..8ea6deb --- /dev/null +++ b/resources/views/search/partials/results.blade.php @@ -0,0 +1,8 @@ +@forelse ($names['names'] as $name) +
  • +
    {!! $name['avatar'] !!}
    + {{ $name['name'] }} +
  • +@empty +fuck +@endforelse diff --git a/routes/web.php b/routes/web.php index f7b4c19..d50a74d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,15 +6,15 @@ use App\Http\Controllers\MaleNameController; use App\Http\Controllers\NameController; use App\Http\Controllers\ProfileController; +use App\Http\Controllers\SearchController; use App\Http\Controllers\Settings\SettingsController; -use App\Http\Controllers\Settings\SettingsLevelController; -use App\Http\Controllers\Settings\SettingsProfileController; -use App\Http\Controllers\Settings\SettingsRoleController; use Illuminate\Support\Facades\Route; Route::get('locale/{locale}', [LocaleController::class, 'update'])->name('locale.update'); Route::get('', [HomeController::class, 'index'])->name('home.index'); +Route::get('recherche', [SearchController::class, 'index'])->name('search.index'); +Route::post('recherche', [SearchController::class, 'post'])->name('search.post'); Route::get('prenoms', [NameController::class, 'index'])->name('name.index'); Route::get('prenoms/garcons', [MaleNameController::class, 'index'])->name('name.garcon.index'); @@ -43,27 +43,6 @@ // settings Route::get('settings', [SettingsController::class, 'index'])->name('settings.index'); - - Route::middleware(['administrator'])->group(function (): void { - // profile - Route::get('settings/profile', [SettingsProfileController::class, 'index'])->name('settings.profile.index'); - - // roles - Route::get('settings/roles', [SettingsRoleController::class, 'index'])->name('settings.role.index'); - Route::get('settings/roles/new', [SettingsRoleController::class, 'new'])->name('settings.role.new'); - Route::post('settings/roles', [SettingsRoleController::class, 'store'])->name('settings.role.store'); - Route::get('settings/roles/{role}/edit', [SettingsRoleController::class, 'edit'])->name('settings.role.edit'); - Route::put('settings/roles/{role}', [SettingsRoleController::class, 'update'])->name('settings.role.update'); - Route::delete('settings/roles/{role}', [SettingsRoleController::class, 'destroy'])->name('settings.role.destroy'); - - // levels - Route::get('settings/levels', [SettingsLevelController::class, 'index'])->name('settings.level.index'); - Route::get('settings/levels/new', [SettingsLevelController::class, 'new'])->name('settings.level.new'); - Route::post('settings/levels', [SettingsLevelController::class, 'store'])->name('settings.level.store'); - Route::get('settings/levels/{level}/edit', [SettingsLevelController::class, 'edit'])->name('settings.level.edit'); - Route::put('settings/levels/{level}', [SettingsLevelController::class, 'update'])->name('settings.level.update'); - Route::delete('settings/levels/{level}', [SettingsLevelController::class, 'destroy'])->name('settings.level.destroy'); - }); }); require __DIR__ . '/auth.php'; diff --git a/tests/Browser/SettingsRolesAndLevelsTest.php b/tests/Browser/SettingsRolesAndLevelsTest.php deleted file mode 100644 index 4d2e94e..0000000 --- a/tests/Browser/SettingsRolesAndLevelsTest.php +++ /dev/null @@ -1,105 +0,0 @@ -create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - - $this->browse(function (Browser $browser) use ($administrator): void { - // create a new role - $browser->loginAs($administrator) - ->visit('/dashboard') - ->click('@nav-settings-link') - ->click('@manage-role-link') - ->waitFor('@add-role-cta') - ->click('@add-role-cta') - ->assertPathIs('/settings/roles/new') - ->type('label', 'Software developer') - ->waitFor('@submit-form-button') - ->click('@submit-form-button') - ->assertPathIs('/settings/roles') - ->assertSee('Software developer'); - - // edit a role - $role = Role::orderBy('updated_at', 'desc') - ->where('organization_id', $administrator->organization_id) - ->first(); - - $browser->visit('/settings/roles') - ->waitFor('@edit-role-' . $role->id) - ->click('@edit-role-' . $role->id) - ->type('label', 'Awesome developer') - ->waitFor('@submit-form-button') - ->click('@submit-form-button') - ->assertPathIs('/settings/roles') - ->assertSee('Awesome developer'); - - // delete a role - $browser->visit('/settings/roles') - ->waitFor('@delete-role-' . $role->id) - ->click('@delete-role-' . $role->id) - ->acceptDialog() - ->pause(150) - ->assertDontSee('Awesome developer'); - }); - } - - /** @test */ - public function it_lets_you_crud_a_level(): void - { - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - - $this->browse(function (Browser $browser) use ($administrator): void { - // create a level - $browser->loginAs($administrator) - ->visit('/dashboard') - ->click('@nav-settings-link') - ->waitFor('@manage-level-link') - ->click('@manage-level-link') - ->waitFor('@add-level-cta') - ->click('@add-level-cta') - ->type('label', 'Intermediate') - ->waitFor('@submit-form-button') - ->click('@submit-form-button') - ->assertPathIs('/settings/levels') - ->pause(150) - ->assertSee('Intermediate'); - - // edit a level - $level = Level::orderBy('updated_at', 'desc') - ->where('organization_id', $administrator->organization_id) - ->first(); - - $browser->visit('/settings/levels') - ->waitFor('@edit-level-' . $level->id) - ->click('@edit-level-' . $level->id) - ->type('label', 'Intermediate Senior') - ->waitFor('@submit-form-button') - ->click('@submit-form-button') - ->assertPathIs('/settings/levels') - ->assertSee('Intermediate Senior'); - - // delete a level - $browser->visit('/settings/levels') - ->waitFor('@delete-level-' . $level->id) - ->click('@delete-level-' . $level->id) - ->acceptDialog() - ->pause(150) - ->assertDontSee('Intermediate Senior'); - }); - } -} diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 58634e5..9b79da3 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -26,12 +26,9 @@ public function registration_screen_can_be_rendered(): void public function new_users_can_register(): void { $response = $this->post('/register', [ - 'first_name' => 'Test', - 'last_name' => 'User', 'email' => 'test@example.com', 'password' => 'password', 'password_confirmation' => 'password', - 'organization_name' => 'Test Organization', ]); $this->assertAuthenticated(); diff --git a/tests/Feature/Settings/ManageLevelTest.php b/tests/Feature/Settings/ManageLevelTest.php deleted file mode 100644 index 2ebcf31..0000000 --- a/tests/Feature/Settings/ManageLevelTest.php +++ /dev/null @@ -1,104 +0,0 @@ -create([ - 'label' => 'Intermediate', - ]); - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - 'organization_id' => $level->organization_id, - ]); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - 'organization_id' => $level->organization_id, - ]); - - $this->actingAs($user) - ->get('/settings/levels') - ->assertStatus(401); - - $this->actingAs($administrator) - ->get('/settings/levels') - ->assertStatus(200); - - $this->actingAs($administrator) - ->get('/settings/levels') - ->assertSee('Intermediate'); - } - - /** @test */ - public function an_administrator_can_create_a_new_level(): void - { - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - - $this->actingAs($user) - ->post('/settings/levels', [ - 'label' => fake()->name, - ]) - ->assertStatus(401); - - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - - $this->actingAs($administrator) - ->post('/settings/levels', [ - 'label' => 'Advanced', - ]) - ->assertRedirectToRoute('settings.level.index'); - - $this->actingAs($administrator) - ->get('/settings/levels') - ->assertSee('Advanced'); - } - - /** @test */ - public function a_level_can_be_edited(): void - { - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - $level = Level::factory()->create([ - 'organization_id' => $administrator->organization_id, - ]); - - $this->actingAs($administrator) - ->put('/settings/levels/' . $level->id, [ - 'label' => 'Intermediate', - ]) - ->assertStatus(302) - ->assertRedirectToRoute('settings.level.index'); - } - - // /** @test */ - public function a_level_cant_be_edited_with_the_wrong_permission(): void - { - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $level = Level::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - - $this->actingAs($user) - ->put('/settings/levels/' . $level->id, [ - 'label' => 'Intermediate', - ]) - ->assertStatus(401); - } -} diff --git a/tests/Feature/Settings/ManageRoleTest.php b/tests/Feature/Settings/ManageRoleTest.php deleted file mode 100644 index a62e30e..0000000 --- a/tests/Feature/Settings/ManageRoleTest.php +++ /dev/null @@ -1,104 +0,0 @@ -create([ - 'label' => 'Developer', - ]); - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - 'organization_id' => $role->organization_id, - ]); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - 'organization_id' => $role->organization_id, - ]); - - $this->actingAs($user) - ->get('/settings/roles') - ->assertStatus(401); - - $this->actingAs($administrator) - ->get('/settings/roles') - ->assertStatus(200); - - $this->actingAs($administrator) - ->get('/settings/roles') - ->assertSee('Developer'); - } - - /** @test */ - public function an_administrator_can_create_a_new_role(): void - { - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - - $this->actingAs($user) - ->post('/settings/roles', [ - 'label' => fake()->name, - ]) - ->assertStatus(401); - - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - - $this->actingAs($administrator) - ->post('/settings/roles', [ - 'label' => 'Software engineer', - ]) - ->assertRedirectToRoute('settings.role.index'); - - $this->actingAs($administrator) - ->get('/settings/roles') - ->assertSee('Software engineer'); - } - - /** @test */ - public function a_role_can_be_edited(): void - { - $administrator = User::factory()->create([ - 'permissions' => User::ROLE_ADMINISTRATOR, - ]); - $role = Role::factory()->create([ - 'organization_id' => $administrator->organization_id, - ]); - - $this->actingAs($administrator) - ->put('/settings/roles/' . $role->id, [ - 'label' => 'Software engineer', - ]) - ->assertStatus(302) - ->assertRedirectToRoute('settings.role.index'); - } - - // /** @test */ - public function a_role_cant_be_edited_with_the_wrong_permission(): void - { - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $role = Role::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - - $this->actingAs($user) - ->put('/settings/roles/' . $role->id, [ - 'label' => 'Software engineer', - ]) - ->assertStatus(401); - } -} diff --git a/tests/Unit/Jobs/PopulateAccountTest.php b/tests/Unit/Jobs/PopulateAccountTest.php deleted file mode 100644 index 6fccfc7..0000000 --- a/tests/Unit/Jobs/PopulateAccountTest.php +++ /dev/null @@ -1,31 +0,0 @@ -create(); - PopulateAccount::dispatch($organization); - - $this->assertEquals( - 13, - DB::table('roles')->count() - ); - - $this->assertEquals( - 4, - DB::table('levels')->count() - ); - } -} diff --git a/tests/Unit/Models/LevelTest.php b/tests/Unit/Models/LevelTest.php deleted file mode 100644 index c788cea..0000000 --- a/tests/Unit/Models/LevelTest.php +++ /dev/null @@ -1,19 +0,0 @@ -create(); - $this->assertTrue($level->organization()->exists()); - } -} diff --git a/tests/Unit/Models/OrganizationTest.php b/tests/Unit/Models/OrganizationTest.php deleted file mode 100644 index 060c340..0000000 --- a/tests/Unit/Models/OrganizationTest.php +++ /dev/null @@ -1,32 +0,0 @@ -create(); - Role::factory()->create(['organization_id' => $organization->id]); - - $this->assertTrue($organization->roles()->exists()); - } - - /** @test */ - public function it_has_many_levels(): void - { - $organization = Organization::factory()->create(); - Level::factory()->create(['organization_id' => $organization->id]); - - $this->assertTrue($organization->levels()->exists()); - } -} diff --git a/tests/Unit/Models/RoleTest.php b/tests/Unit/Models/RoleTest.php deleted file mode 100644 index 13cbb33..0000000 --- a/tests/Unit/Models/RoleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -create(); - $this->assertTrue($role->organization()->exists()); - } -} diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php deleted file mode 100644 index 5fa2fe7..0000000 --- a/tests/Unit/Models/UserTest.php +++ /dev/null @@ -1,24 +0,0 @@ -create(); - $user = User::factory()->create([ - 'organization_id' => $organization->id, - ]); - - $this->assertTrue($user->organization()->exists()); - } -} diff --git a/tests/Unit/Services/CreateAccountTest.php b/tests/Unit/Services/CreateAccountTest.php index 9a6a75b..cb1c6fc 100644 --- a/tests/Unit/Services/CreateAccountTest.php +++ b/tests/Unit/Services/CreateAccountTest.php @@ -2,11 +2,9 @@ namespace Tests\Unit\Services; -use App\Jobs\PopulateAccount; use App\Models\User; use App\Services\CreateAccount; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Support\Facades\Queue; use Tests\TestCase; class CreateAccountTest extends TestCase @@ -21,14 +19,9 @@ public function it_creates_an_account(): void private function executeService(): void { - Queue::fake(); - $user = (new CreateAccount( email: 'john@email.com', password: 'johnny', - firstName: 'johnny', - lastName: 'depp', - organizationName: 'johnny inc', ))->execute(); $this->assertInstanceOf( @@ -38,19 +31,7 @@ private function executeService(): void $this->assertDatabaseHas('users', [ 'id' => $user->id, - 'first_name' => 'johnny', - 'last_name' => 'depp', - 'name_for_avatar' => 'johnny', 'email' => 'john@email.com', - 'organization_id' => $user->organization_id, - 'permissions' => 'administrator', - ]); - - $this->assertDatabaseHas('organizations', [ - 'id' => $user->organization_id, - 'name' => 'johnny inc', ]); - - Queue::assertPushed(PopulateAccount::class); } } diff --git a/tests/Unit/Services/CreateLevelTest.php b/tests/Unit/Services/CreateLevelTest.php deleted file mode 100644 index e7f7bf1..0000000 --- a/tests/Unit/Services/CreateLevelTest.php +++ /dev/null @@ -1,51 +0,0 @@ -create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $this->executeService($user); - } - - /** @test */ - public function it_fails_if_the_user_doesnt_have_the_right_permissions(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $this->executeService($user); - } - - private function executeService(User $user): void - { - $this->actingAs($user); - $level = (new CreateLevel('intermediate'))->execute(); - - $this->assertInstanceOf( - Level::class, - $level - ); - - $this->assertDatabaseHas('levels', [ - 'id' => $level->id, - 'organization_id' => $user->organization_id, - 'label' => 'intermediate', - ]); - } -} diff --git a/tests/Unit/Services/CreateRoleTest.php b/tests/Unit/Services/CreateRoleTest.php deleted file mode 100644 index bc8c778..0000000 --- a/tests/Unit/Services/CreateRoleTest.php +++ /dev/null @@ -1,51 +0,0 @@ -create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $this->executeService($user); - } - - /** @test */ - public function it_fails_if_the_user_doesnt_have_the_right_permissions(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $this->executeService($user); - } - - private function executeService(User $user): void - { - $this->actingAs($user); - $role = (new CreateRole('developer'))->execute(); - - $this->assertInstanceOf( - Role::class, - $role - ); - - $this->assertDatabaseHas('roles', [ - 'id' => $role->id, - 'organization_id' => $user->organization_id, - 'label' => 'developer', - ]); - } -} diff --git a/tests/Unit/Services/DestroyLevelTest.php b/tests/Unit/Services/DestroyLevelTest.php deleted file mode 100644 index ca4548d..0000000 --- a/tests/Unit/Services/DestroyLevelTest.php +++ /dev/null @@ -1,63 +0,0 @@ -create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $level = Level::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($level, $user); - } - - /** @test */ - public function it_fails_if_the_user_doesnt_have_the_right_permissions(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $level = Level::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($level, $user); - } - - /** @test */ - public function it_fails_if_the_level_doesnt_belong_to_organization(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $level = Level::factory()->create(); - $this->executeService($level, $user); - } - - private function executeService(Level $level, User $user): void - { - $this->actingAs($user); - (new DestroyLevel( - level: $level, - ))->execute(); - - $this->assertDatabaseMissing('levels', [ - 'id' => $level->id, - ]); - } -} diff --git a/tests/Unit/Services/DestroyRoleTest.php b/tests/Unit/Services/DestroyRoleTest.php deleted file mode 100644 index 437d400..0000000 --- a/tests/Unit/Services/DestroyRoleTest.php +++ /dev/null @@ -1,63 +0,0 @@ -create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $role = Role::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($role, $user); - } - - /** @test */ - public function it_fails_if_the_user_doesnt_have_the_right_permissions(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $role = Role::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($role, $user); - } - - /** @test */ - public function it_fails_if_the_role_doesnt_belong_to_organization(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $role = Role::factory()->create(); - $this->executeService($role, $user); - } - - private function executeService(Role $role, User $user): void - { - $this->actingAs($user); - (new DestroyRole( - role: $role, - ))->execute(); - - $this->assertDatabaseMissing('roles', [ - 'id' => $role->id, - ]); - } -} diff --git a/tests/Unit/Services/UpdateLevelTest.php b/tests/Unit/Services/UpdateLevelTest.php deleted file mode 100644 index 91521c7..0000000 --- a/tests/Unit/Services/UpdateLevelTest.php +++ /dev/null @@ -1,71 +0,0 @@ -create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $level = Level::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($level, $user); - } - - /** @test */ - public function it_fails_if_the_user_doesnt_have_the_right_permissions(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $level = Level::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($level, $user); - } - - /** @test */ - public function it_fails_if_the_level_doesnt_belong_to_organization(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $level = Level::factory()->create(); - $this->executeService($level, $user); - } - - private function executeService(Level $level, User $user): void - { - $this->actingAs($user); - $level = (new UpdateLevel( - level: $level, - label: 'developer' - ))->execute(); - - $this->assertInstanceOf( - Level::class, - $level - ); - - $this->assertDatabaseHas('levels', [ - 'id' => $level->id, - 'organization_id' => $user->organization_id, - 'label' => 'developer', - ]); - } -} diff --git a/tests/Unit/Services/UpdateRoleTest.php b/tests/Unit/Services/UpdateRoleTest.php deleted file mode 100644 index 2e52d8d..0000000 --- a/tests/Unit/Services/UpdateRoleTest.php +++ /dev/null @@ -1,71 +0,0 @@ -create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $role = Role::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($role, $user); - } - - /** @test */ - public function it_fails_if_the_user_doesnt_have_the_right_permissions(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_USER, - ]); - $role = Role::factory()->create([ - 'organization_id' => $user->organization_id, - ]); - $this->executeService($role, $user); - } - - /** @test */ - public function it_fails_if_the_role_doesnt_belong_to_organization(): void - { - $this->expectException(Exception::class); - $user = User::factory()->create([ - 'permissions' => User::ROLE_ACCOUNT_MANAGER, - ]); - $role = Role::factory()->create(); - $this->executeService($role, $user); - } - - private function executeService(Role $role, User $user): void - { - $this->actingAs($user); - $role = (new UpdateRole( - role: $role, - label: 'developer' - ))->execute(); - - $this->assertInstanceOf( - Role::class, - $role - ); - - $this->assertDatabaseHas('roles', [ - 'id' => $role->id, - 'organization_id' => $user->organization_id, - 'label' => 'developer', - ]); - } -} diff --git a/tests/Unit/Traits/TranslatableTest.php b/tests/Unit/Traits/TranslatableTest.php deleted file mode 100644 index dad9f84..0000000 --- a/tests/Unit/Traits/TranslatableTest.php +++ /dev/null @@ -1,36 +0,0 @@ -create([ - 'label' => 'this is the real name', - 'label_translation_key' => 'role.label', - ]); - - $this->assertEquals( - 'this is the real name', - $role->label - ); - - $role = Role::factory()->create([ - 'label' => null, - 'label_translation_key' => 'role.label', - ]); - - $this->assertEquals( - 'role.label', - $role->label - ); - } -} diff --git a/tests/Unit/ViewModels/Names/AllNamesViewModelTest.php b/tests/Unit/ViewModels/Names/AllNamesViewModelTest.php index f9802e3..98926fb 100644 --- a/tests/Unit/ViewModels/Names/AllNamesViewModelTest.php +++ b/tests/Unit/ViewModels/Names/AllNamesViewModelTest.php @@ -1,6 +1,6 @@ 'HÉLOÏSE', 'origins' => 'Origine du prénom Héloïse', 'personality' => 'Personnalité du prénom Héloïse', - 'country_of_origin' => 'Pays d\'origine du prénom Héloïse', + 'syllabes' => 2, 'celebrities' => 'Célébrités du prénom Héloïse', 'elfic_traits' => 'Traits elfiques du prénom Héloïse', 'name_day' => 'Fête du prénom Héloïse', @@ -37,7 +37,7 @@ public function it_gets_the_details_of_a_name(): void $this->assertArrayHasKey('avatar', $array); $this->assertArrayHasKey('origins', $array); $this->assertArrayHasKey('personality', $array); - $this->assertArrayHasKey('country_of_origin', $array); + $this->assertArrayHasKey('syllabes', $array); $this->assertArrayHasKey('celebrities', $array); $this->assertArrayHasKey('elfic_traits', $array); $this->assertArrayHasKey('name_day', $array); @@ -80,8 +80,9 @@ public function it_gets_the_stats_per_decade(): void $array = NameViewModel::popularity($name); - $this->assertCount(1, $array); + $this->assertCount(2, $array); $this->assertArrayHasKey('decades', $array); + $this->assertArrayHasKey('total', $array); $this->assertEquals( [ 0 => [ diff --git a/tests/Unit/ViewModels/Settings/SettingsLevelViewModelTest.php b/tests/Unit/ViewModels/Settings/SettingsLevelViewModelTest.php deleted file mode 100644 index 65f3410..0000000 --- a/tests/Unit/ViewModels/Settings/SettingsLevelViewModelTest.php +++ /dev/null @@ -1,44 +0,0 @@ -create(); - $this->actingAs($user); - - $array = SettingsLevelViewModel::index(); - - $this->assertCount(1, $array); - $this->assertArrayHasKey('levels', $array); - } - - /** @test */ - public function it_gets_the_level_object(): void - { - $level = Level::factory()->create([ - 'label' => 'Dunder', - ]); - $array = SettingsLevelViewModel::level($level); - - $this->assertCount(2, $array); - $this->assertEquals( - [ - 'id' => $level->id, - 'label' => 'Dunder', - ], - $array - ); - } -} diff --git a/tests/Unit/ViewModels/Settings/SettingsRoleViewModelTest.php b/tests/Unit/ViewModels/Settings/SettingsRoleViewModelTest.php deleted file mode 100644 index a42b4a2..0000000 --- a/tests/Unit/ViewModels/Settings/SettingsRoleViewModelTest.php +++ /dev/null @@ -1,44 +0,0 @@ -create(); - $this->actingAs($user); - - $array = SettingsRoleViewModel::index(); - - $this->assertCount(1, $array); - $this->assertArrayHasKey('roles', $array); - } - - /** @test */ - public function it_gets_the_role_object(): void - { - $role = Role::factory()->create([ - 'label' => 'Dunder', - ]); - $array = SettingsRoleViewModel::role($role); - - $this->assertCount(2, $array); - $this->assertEquals( - [ - 'id' => $role->id, - 'label' => 'Dunder', - ], - $array - ); - } -}