Merge branch 'feature/76_Prepojenie_databázy_s_aplikáciou' into develop

This commit is contained in:
2025-10-21 13:00:38 +02:00
20 changed files with 696 additions and 4 deletions

View 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)
{
//
}
}

View 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)
{
//
}
}

View 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)
{
//
}
}

View 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)
{
//
}
}

View 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'
];
}

View 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',
];
}

View 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'
];
}

View 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',
];
}

View File

@@ -19,7 +19,11 @@ class User extends Authenticatable
*/
protected $fillable = [
'name',
'first_name',
'last_name',
'phone',
'email',
'role',
'password',
];

View 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(),
];
}
}

View 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,
];
}
}

View 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,
];
}
}

View 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"]),
];
}
}

View File

@@ -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'),

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->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',
]);
});
}
};

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('student_data', function (Blueprint $table) {
$table->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');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('companies', function (Blueprint $table) {
$table->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');
}
};

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('internships', function (Blueprint $table) {
$table->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');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('internship_statuses', function (Blueprint $table) {
$table->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');
}
};

View File

@@ -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,
]);
});
}
}