Migrate backend to Porto architecture and fix minor bugs

- Fully transitioned the backend to the Porto architectural pattern
- Improved code organization and maintainability
- Fixed minor bugs and inconsistencies
This commit is contained in:
F4ilji
2025-05-12 08:47:43 +05:00
parent 76deaf75f3
commit c01016a154
620 changed files with 16218 additions and 6073 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Database\Factories;
use App\Models\Faculty;
use App\Containers\InstituteStructure\Models\Faculty;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
@@ -0,0 +1,21 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class EducationalGroupFactory extends Factory
{
public function definition(): array
{
return [
'title' => $this->faker->words(3, true),
'faculty_id' => \App\Models\Faculty::factory(),
'education_form_id' => $this->faker->numberBetween(1, 3),
'created_at' => $this->faker->dateTimeBetween('-1 year', 'now'),
'updated_at' => $this->faker->dateTimeBetween('-1 year', 'now'),
];
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Database\Factories;
use App\Models\EventCategory;
use App\Containers\Event\Models\EventCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
+1
View File
@@ -35,6 +35,7 @@ class FacultyFactory extends Factory
'slug' => $slug,
'content' => $content,
'abbreviation' => $abbreviation,
'is_active' => $this->faker->boolean(100),
'created_at' => now(),
'updated_at' => now(),
];
+4 -6
View File
@@ -2,15 +2,12 @@
namespace Database\Factories;
use App\Enums\PostStatus;
use App\Models\Category;
use App\Models\User;
use App\Containers\Article\Enums\PostStatus;
use App\Containers\Article\Models\Category;
use App\Containers\User\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
*/
class PostFactory extends Factory
{
/**
@@ -54,6 +51,7 @@ class PostFactory extends Factory
'status' => $status,
'authors' => $authors,
'images' => $images,
'preview' => null,
'search_data' => $search_data,
'reading_time' => $reading_time,
'category_id' => $category_id,
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ScheduleFactory extends Factory
{
public function definition(): array
{
$fileName = $this->faker->unique()->word . '.pdf';
return [
'file' => [
[
'title' => $this->faker->randomElement(['Обычное', 'Основное', 'Дополнительное', 'Экзаменационное']),
'path' => 'schedules/' . $this->faker->slug . '-' . time() . '.pdf'
]
],
'educational_group_id' => \App\Models\EducationalGroup::factory(),
'created_at' => $this->faker->dateTimeBetween('-6 months', 'now'),
'updated_at' => $this->faker->dateTimeBetween('-6 months', 'now'),
];
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Database\Factories;
use App\Models\User;
use App\Containers\User\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
@@ -1,7 +1,7 @@
<?php
use App\Models\Department;
use App\Models\User;
use App\Containers\InstituteStructure\Models\Department;
use App\Containers\User\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -1,7 +1,7 @@
<?php
use App\Models\Department;
use App\Models\User;
use App\Containers\InstituteStructure\Models\Department;
use App\Containers\User\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -1,7 +1,7 @@
<?php
use App\Models\Faculty;
use App\Models\User;
use App\Containers\InstituteStructure\Models\Faculty;
use App\Containers\User\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -1,6 +1,5 @@
<?php
use App\Models\AcademicJournal;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -1,7 +1,7 @@
<?php
use App\Models\Department;
use App\Models\EducationalProgram;
use App\Containers\Education\Models\EducationalProgram;
use App\Containers\InstituteStructure\Models\Department;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
+72 -73
View File
@@ -2,21 +2,11 @@
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Category;
use App\Models\Department;
use App\Models\EducationalProgram;
use App\Models\Event;
use App\Models\EventCategory;
use App\Models\Faculty;
use App\Models\Post;
use App\Models\User;
use App\Models\UserDetail;
use Faker\Factory;
use Database\Factories\WorkerDepartmentFactory;
use App\Containers\InstituteStructure\Models\Faculty;
use App\Containers\Article\Models\Post;
use App\Containers\Schedule\Models\EducationalGroup;
use App\Containers\Schedule\Models\Schedule;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
class DatabaseSeeder extends Seeder
{
@@ -24,72 +14,81 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
$faker = Factory::create();
// $faker = Factory::create();
// User::create([
// 'name' => 'Failj',
// 'email' => 'Failj@bk.ru',
// 'slug' => 'failj',
// 'password' => "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi",
// ]);
User::factory()->count(50)->has(UserDetail::factory())->create();
EventCategory::factory()->count(10)->create();
Category::factory()->count(80)->create();
// User::factory()->count(50)->has(UserDetail::factory())->create();
// EventCategory::factory()->count(10)->create();
// Category::factory()->count(80)->create();
Post::factory()->count(1000)->create();
Event::factory()->count(200)->create();
Faculty::factory()->count(6)->create();
Department::factory()->count(12)->create();
// Event::factory()->count(200)->create();
$faculties = Faculty::factory()->count(6)->create();
for ($i = 0; $i < 20; $i++) {
DB::table('workers_departments')->insert([
'user_id' => User::inRandomOrder()->first()->id,
'department_id' => Department::inRandomOrder()->first()->id,
'position' => $faker->word,
'created_at' => now(),
'updated_at' => now(),
]);
}
for ($i = 0; $i < 20; $i++) {
DB::table('workers_faculties')->insert([
'user_id' => User::inRandomOrder()->first()->id,
'faculty_id' => Faculty::inRandomOrder()->first()->id,
'position' => $faker->word,
'created_at' => now(),
'updated_at' => now(),
]);
}
for ($i = 0; $i < 30; $i++) {
DB::table('teachers_departments')->insert([
'user_id' => User::inRandomOrder()->first()->id,
'department_id' => Department::inRandomOrder()->first()->id,
'teaching_position' => $faker->word,
'created_at' => now(),
'updated_at' => now(),
]);
}
$this->call([RolesSeeder::class]);
$users = [
[
'name' => 'Admin',
'email' => 'Admin@mail.ru',
'password' => 'R177p900',
'role' => 'admin',
],
[
'name' => 'John',
'email' => 'Test@mail.ru',
'password' => 'R177p900',
'role' => 'user',
]
];
foreach ($users as $user) {
$created_user = User::create([
'name' => $user['name'],
'email' => $user['email'],
'password' => Hash::make($user['password']),
]);
$created_user->assignRole($user['role']);
}
// Затем создаем 40 групп, распределяя их по созданным факультетам
EducationalGroup::factory()
->count(40)
->sequence(fn () => [
'faculty_id' => $faculties->random()->id
])
->has(Schedule::factory()->count(90 / 40)) // Распределяем 90 расписаний по 40 группам
->create();
// Department::factory()->count(12)->create();
//
// for ($i = 0; $i < 20; $i++) {
// DB::table('workers_departments')->insert([
// 'user_id' => User::inRandomOrder()->first()->id,
// 'department_id' => Department::inRandomOrder()->first()->id,
// 'position' => $faker->word,
// 'created_at' => now(),
// 'updated_at' => now(),
// ]);
// }
//
// for ($i = 0; $i < 20; $i++) {
// DB::table('workers_faculties')->insert([
// 'user_id' => User::inRandomOrder()->first()->id,
// 'faculty_id' => Faculty::inRandomOrder()->first()->id,
// 'position' => $faker->word,
// 'created_at' => now(),
// 'updated_at' => now(),
// ]);
// }
//
// for ($i = 0; $i < 30; $i++) {
// DB::table('teachers_departments')->insert([
// 'user_id' => User::inRandomOrder()->first()->id,
// 'department_id' => Department::inRandomOrder()->first()->id,
// 'teaching_position' => $faker->word,
// 'created_at' => now(),
// 'updated_at' => now(),
// ]);
// }
// $this->call([RolesSeeder::class]);
// $users = [
// [
// 'name' => 'Admin',
// 'email' => 'Admin@mail.ru',
// 'password' => 'R177p900',
// 'role' => 'admin',
// ],
// [
// 'name' => 'John',
// 'email' => 'Test@mail.ru',
// 'password' => 'R177p900',
// 'role' => 'user',
// ]
// ];
// foreach ($users as $user) {
// $created_user = User::create([
// 'name' => $user['name'],
// 'email' => $user['email'],
// 'password' => Hash::make($user['password']),
// ]);
// $created_user->assignRole($user['role']);
// }
}
}