You've already forked isop-mirror
refactor: create models, factories, and seeders for Company, Internship, InternshipStatus, and StudentData
This commit is contained in:
65
backend/app/Http/Controllers/CompanyController.php
Normal file
65
backend/app/Http/Controllers/CompanyController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Company;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Company $company)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Company $company)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Company $company)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
65
backend/app/Http/Controllers/InternshipController.php
Normal file
65
backend/app/Http/Controllers/InternshipController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Internship;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InternshipController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Internship $internship)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Internship $internship)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Internship $internship)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Internship $internship)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
65
backend/app/Http/Controllers/InternshipStatusController.php
Normal file
65
backend/app/Http/Controllers/InternshipStatusController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\InternshipStatus;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InternshipStatusController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(InternshipStatus $internshipStatus)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(InternshipStatus $internshipStatus)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, InternshipStatus $internshipStatus)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(InternshipStatus $internshipStatus)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
65
backend/app/Http/Controllers/StudentDataController.php
Normal file
65
backend/app/Http/Controllers/StudentDataController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\StudentData;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StudentDataController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(StudentData $studentData)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(StudentData $studentData)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, StudentData $studentData)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(StudentData $studentData)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
25
backend/app/Models/Company.php
Normal file
25
backend/app/Models/Company.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Company extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\CompanyFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'address',
|
||||
'ico',
|
||||
'contact',
|
||||
'hiring'
|
||||
];
|
||||
}
|
||||
28
backend/app/Models/Internship.php
Normal file
28
backend/app/Models/Internship.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Internship extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\InternshipFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'company_id',
|
||||
'start',
|
||||
'end',
|
||||
'year_of_study',
|
||||
'semester',
|
||||
'position_description',
|
||||
'agreement',
|
||||
];
|
||||
}
|
||||
25
backend/app/Models/InternshipStatus.php
Normal file
25
backend/app/Models/InternshipStatus.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InternshipStatus extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\InternshipStatusFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'internship_id',
|
||||
'status',
|
||||
'changed',
|
||||
'note',
|
||||
'modified_by'
|
||||
];
|
||||
}
|
||||
24
backend/app/Models/StudentData.php
Normal file
24
backend/app/Models/StudentData.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StudentData extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\StudentDataFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'address',
|
||||
'personal_email',
|
||||
'study_field',
|
||||
];
|
||||
}
|
||||
27
backend/database/factories/CompanyFactory.php
Normal file
27
backend/database/factories/CompanyFactory.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Company>
|
||||
*/
|
||||
class CompanyFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->company(),
|
||||
'address' => fake()->address(),
|
||||
'ico' => fake()->numberBetween(111111, 999999),
|
||||
'contact' => 0,
|
||||
'hiring' => fake()->boolean(),
|
||||
];
|
||||
}
|
||||
}
|
||||
30
backend/database/factories/InternshipFactory.php
Normal file
30
backend/database/factories/InternshipFactory.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Internship>
|
||||
*/
|
||||
class InternshipFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 0,
|
||||
'company_id' => 0,
|
||||
'start' => fake()->dateTime(),
|
||||
'end' => fake()->dateTime("+30 days"),
|
||||
'year_of_study' => fake()->randomElement([1, 2, 3, 4, 5]),
|
||||
'semester' => fake()->randomElement(["WINTER", "SUMMER"]),
|
||||
'position_description' => fake()->jobTitle(),
|
||||
'agreement' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
27
backend/database/factories/InternshipStatusFactory.php
Normal file
27
backend/database/factories/InternshipStatusFactory.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\InternshipStatus>
|
||||
*/
|
||||
class InternshipStatusFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'internship_id' => 0,
|
||||
'status' => fake()->randomElement(["SUBMITTED", "CONFIRMED", "DENIED", "DEFENDED", "NOT_DEFENDED"]),
|
||||
'changed' => fake()->dateTime(),
|
||||
'note' => null,
|
||||
'modified_by' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
26
backend/database/factories/StudentDataFactory.php
Normal file
26
backend/database/factories/StudentDataFactory.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\StudentData>
|
||||
*/
|
||||
class StudentDataFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 0,
|
||||
'address' => fake()->address(),
|
||||
'personal_email' => fake()->safeEmail(),
|
||||
'study_field' => fake()->randomElement(["AI22m", "AI22b"]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ return new class extends Migration
|
||||
$table->enum("semester", ["WINTER", "SUMMER"])->nullable(false);
|
||||
$table->string("position_description")->nullable(false);
|
||||
$table->binary("agreement")->nullable(true);
|
||||
$table->foreignId("personel_id")->nullable(false)->constrained("users")->onDelete("cascade");
|
||||
$table->foreignId("status_id")->nullable(false)->constrained("internship_statuses")->onDelete("cascade");
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
17
backend/database/seeders/CompanySeeder.php
Normal file
17
backend/database/seeders/CompanySeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class CompanySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Internship;
|
||||
use App\Models\InternshipStatus;
|
||||
use App\Models\StudentData;
|
||||
use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
@@ -14,7 +18,7 @@ class DatabaseSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
// create a default admin user
|
||||
User::factory()->create([
|
||||
$admin = User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'User',
|
||||
@@ -22,5 +26,39 @@ class DatabaseSeeder extends Seeder
|
||||
'phone' => '+421907444555',
|
||||
'role' => 'ADMIN',
|
||||
]);
|
||||
|
||||
// create employers and companies
|
||||
User::factory(10)
|
||||
->create([
|
||||
'role' => 'EMPLOYER'
|
||||
])
|
||||
->each(function ($user) {
|
||||
Company::factory()->create([
|
||||
'contact' => $user->id
|
||||
]);
|
||||
});
|
||||
|
||||
// create students
|
||||
User::factory(10)
|
||||
->create([
|
||||
'role' => 'STUDENT'
|
||||
])
|
||||
->each(function ($user) use ($admin) {
|
||||
StudentData::factory()->create([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
|
||||
$internship = Internship::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => Company::inRandomOrder()->value('id'),
|
||||
]);
|
||||
|
||||
InternshipStatus::factory()->create([
|
||||
'internship_id' => $internship->id,
|
||||
'status' => "SUBMITTED",
|
||||
'note' => 'made by seeder',
|
||||
'modified_by' => $admin->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
17
backend/database/seeders/InternshipSeeder.php
Normal file
17
backend/database/seeders/InternshipSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InternshipSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
17
backend/database/seeders/InternshipStatusSeeder.php
Normal file
17
backend/database/seeders/InternshipStatusSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InternshipStatusSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
17
backend/database/seeders/StudentDataSeeder.php
Normal file
17
backend/database/seeders/StudentDataSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class StudentDataSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user