diff --git a/backend/app/Http/Controllers/CompanyController.php b/backend/app/Http/Controllers/CompanyController.php new file mode 100644 index 0000000..171eaad --- /dev/null +++ b/backend/app/Http/Controllers/CompanyController.php @@ -0,0 +1,65 @@ + */ + use HasFactory; + + /** + * The attributes that are mass assignable. + * + * @var list + */ + protected $fillable = [ + 'name', + 'address', + 'ico', + 'contact', + 'hiring' + ]; +} diff --git a/backend/app/Models/Internship.php b/backend/app/Models/Internship.php new file mode 100644 index 0000000..a549885 --- /dev/null +++ b/backend/app/Models/Internship.php @@ -0,0 +1,28 @@ + */ + use HasFactory; + + /** + * The attributes that are mass assignable. + * + * @var list + */ + protected $fillable = [ + 'user_id', + 'company_id', + 'start', + 'end', + 'year_of_study', + 'semester', + 'position_description', + 'agreement', + ]; +} diff --git a/backend/app/Models/InternshipStatus.php b/backend/app/Models/InternshipStatus.php new file mode 100644 index 0000000..4272c86 --- /dev/null +++ b/backend/app/Models/InternshipStatus.php @@ -0,0 +1,25 @@ + */ + use HasFactory; + + /** + * The attributes that are mass assignable. + * + * @var list + */ + protected $fillable = [ + 'internship_id', + 'status', + 'changed', + 'note', + 'modified_by' + ]; +} diff --git a/backend/app/Models/StudentData.php b/backend/app/Models/StudentData.php new file mode 100644 index 0000000..8490416 --- /dev/null +++ b/backend/app/Models/StudentData.php @@ -0,0 +1,24 @@ + */ + use HasFactory; + + /** + * The attributes that are mass assignable. + * + * @var list + */ + protected $fillable = [ + 'user_id', + 'address', + 'personal_email', + 'study_field', + ]; +} diff --git a/backend/app/Models/User.php b/backend/app/Models/User.php index 749c7b7..97edce1 100644 --- a/backend/app/Models/User.php +++ b/backend/app/Models/User.php @@ -19,7 +19,11 @@ class User extends Authenticatable */ protected $fillable = [ 'name', + 'first_name', + 'last_name', + 'phone', 'email', + 'role', 'password', ]; diff --git a/backend/database/factories/CompanyFactory.php b/backend/database/factories/CompanyFactory.php new file mode 100644 index 0000000..44b328a --- /dev/null +++ b/backend/database/factories/CompanyFactory.php @@ -0,0 +1,27 @@ + + */ +class CompanyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->company(), + 'address' => fake()->address(), + 'ico' => fake()->numberBetween(111111, 999999), + 'contact' => 0, + 'hiring' => fake()->boolean(), + ]; + } +} diff --git a/backend/database/factories/InternshipFactory.php b/backend/database/factories/InternshipFactory.php new file mode 100644 index 0000000..d1d9015 --- /dev/null +++ b/backend/database/factories/InternshipFactory.php @@ -0,0 +1,30 @@ + + */ +class InternshipFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + 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, + ]; + } +} diff --git a/backend/database/factories/InternshipStatusFactory.php b/backend/database/factories/InternshipStatusFactory.php new file mode 100644 index 0000000..9826179 --- /dev/null +++ b/backend/database/factories/InternshipStatusFactory.php @@ -0,0 +1,27 @@ + + */ +class InternshipStatusFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + 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, + ]; + } +} diff --git a/backend/database/factories/StudentDataFactory.php b/backend/database/factories/StudentDataFactory.php new file mode 100644 index 0000000..31b910a --- /dev/null +++ b/backend/database/factories/StudentDataFactory.php @@ -0,0 +1,26 @@ + + */ +class StudentDataFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'user_id' => 0, + 'address' => fake()->address(), + 'personal_email' => fake()->safeEmail(), + 'study_field' => fake()->randomElement(["AI22m", "AI22b"]), + ]; + } +} diff --git a/backend/database/factories/UserFactory.php b/backend/database/factories/UserFactory.php index 584104c..39a6cef 100644 --- a/backend/database/factories/UserFactory.php +++ b/backend/database/factories/UserFactory.php @@ -23,8 +23,15 @@ class UserFactory extends Factory */ public function definition(): array { + $first_name = fake()->firstName(); + $last_name = fake()->lastName(); + return [ - 'name' => fake()->name(), + 'name' => "$first_name $last_name", + 'first_name' => $first_name, + 'last_name' => $last_name, + 'phone' => fake()->phoneNumber(), + 'role' => fake()->randomElement(['STUDENT', 'EMPLOYER', 'ADMIN']), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => static::$password ??= Hash::make('password'), diff --git a/backend/database/migrations/2025_10_20_191423_alter_users_table.php b/backend/database/migrations/2025_10_20_191423_alter_users_table.php new file mode 100644 index 0000000..9041dde --- /dev/null +++ b/backend/database/migrations/2025_10_20_191423_alter_users_table.php @@ -0,0 +1,38 @@ +string('first_name')->nullable(false)->after('name'); + $table->string('last_name')->nullable(false)->after('first_name'); + $table->string('phone')->nullable(false)->unique()->after('email'); + $table->enum("role", ["STUDENT", "EMPLOYER", "ADMIN"])->nullable(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropUnique(['phone']); + + $table->dropColumn([ + 'first_name', + 'last_name', + 'phone', + 'role', + ]); + }); + } +}; diff --git a/backend/database/migrations/2025_10_20_192305_create_student_data_table.php b/backend/database/migrations/2025_10_20_192305_create_student_data_table.php new file mode 100644 index 0000000..af27da8 --- /dev/null +++ b/backend/database/migrations/2025_10_20_192305_create_student_data_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignId("user_id")->nullable(false)->constrained("users")->onDelete("cascade"); + $table->string("address")->nullable(false); + $table->string("personal_email")->nullable(false); + $table->string("study_field")->nullable(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('student_data'); + } +}; diff --git a/backend/database/migrations/2025_10_20_192651_create_companies_table.php b/backend/database/migrations/2025_10_20_192651_create_companies_table.php new file mode 100644 index 0000000..194936a --- /dev/null +++ b/backend/database/migrations/2025_10_20_192651_create_companies_table.php @@ -0,0 +1,32 @@ +id(); + $table->string("name")->nullable(false)->unique(); + $table->string("address")->nullable(false); + $table->unsignedInteger("ico")->nullable(false)->unique(); + $table->foreignId("contact")->nullable(false)->constrained("users")->onDelete("cascade"); + $table->boolean("hiring")->nullable(false)->default(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('companies'); + } +}; diff --git a/backend/database/migrations/2025_10_20_193012_create_internships_table.php b/backend/database/migrations/2025_10_20_193012_create_internships_table.php new file mode 100644 index 0000000..1b3f750 --- /dev/null +++ b/backend/database/migrations/2025_10_20_193012_create_internships_table.php @@ -0,0 +1,35 @@ +id(); + $table->foreignId("user_id")->nullable(false)->constrained("users")->onDelete("cascade"); + $table->foreignId("company_id")->nullable(false)->constrained("companies")->onDelete("cascade"); + $table->dateTimeTz("start")->nullable(false); + $table->dateTimeTz("end")->nullable(false); + $table->unsignedSmallInteger("year_of_study")->nullable(false); + $table->enum("semester", ["WINTER", "SUMMER"])->nullable(false); + $table->string("position_description")->nullable(false); + $table->binary("agreement")->nullable(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('internships'); + } +}; diff --git a/backend/database/migrations/2025_10_20_193408_create_internship_statuses_table.php b/backend/database/migrations/2025_10_20_193408_create_internship_statuses_table.php new file mode 100644 index 0000000..a54ffa7 --- /dev/null +++ b/backend/database/migrations/2025_10_20_193408_create_internship_statuses_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId("internship_id")->nullable(false)->constrained("internships")->onDelete("cascade"); + $table->enum("status", ["SUBMITTED", "CONFIRMED", "DENIED", "DEFENDED", "NOT_DEFENDED"])->nullable(false)->default("SUBMITTED"); + $table->dateTimeTz("changed")->nullable(false); + $table->string("note")->nullable(true)->default(null); + $table->foreignId("modified_by")->nullable(false)->constrained("users")->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('internship_statuses'); + } +}; diff --git a/backend/database/seeders/DatabaseSeeder.php b/backend/database/seeders/DatabaseSeeder.php index d01a0ef..9102ebd 100644 --- a/backend/database/seeders/DatabaseSeeder.php +++ b/backend/database/seeders/DatabaseSeeder.php @@ -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; @@ -13,11 +17,48 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // User::factory(10)->create(); - - User::factory()->create([ + // create a default admin user + $admin = User::factory()->create([ 'name' => 'Test User', + 'first_name' => 'Test', + 'last_name' => 'User', 'email' => 'test@example.com', + '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, + ]); + }); } }