Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/Http/Controllers/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Inertia\Inertia;

/**
Expand Down Expand Up @@ -36,6 +37,14 @@ abstract class CRUDController extends Controller
*/
protected array $search = [];

public function __construct()
{
$basename = Str::replaceEnd('CRUDController', '', class_basename($this));

$this->model ??= "App\\Models\\{$basename}";
$this->view ??= $basename;
}

/**
* The validation rules for the store method.
*
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/DepartmentCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

namespace App\Http\Controllers;

use App\Models\Department;
use App\Models\Edition;

class DepartmentCRUDController extends CRUDController
{
protected string $model = Department::class;

protected string $view = 'Department';

protected array $search = ['name'];

protected array $rules = [
Expand Down
6 changes: 0 additions & 6 deletions app/Http/Controllers/EditionCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace App\Http\Controllers;

use App\Models\Edition;

class EditionCRUDController extends CRUDController
{
protected string $model = Edition::class;

protected string $view = 'Edition';

protected array $rules = [
'name' => 'required|string',
'year' => 'required|integer',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/EventCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

namespace App\Http\Controllers;

use App\Models\Event;
use App\Models\EventDay;

class EventCRUDController extends CRUDController
{
protected string $model = Event::class;

protected string $view = 'Event';

protected array $rules = [
'name' => 'required|string',
'time_start' => 'required|date_format:"H:i"',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/EventDayCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
namespace App\Http\Controllers;

use App\Models\Edition;
use App\Models\EventDay;

class EventDayCRUDController extends CRUDController
{
protected string $model = EventDay::class;

protected string $view = 'EventDay';

protected array $rules = [
'edition_id' => 'required|integer|in:editions,id',
'date' => 'required|date',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/ProductCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
namespace App\Http\Controllers;

use App\Models\Edition;
use App\Models\Product;

class ProductCRUDController extends CRUDController
{
protected string $model = Product::class;

protected string $view = 'Product';

protected array $rules = [
'name' => 'required|string',
'price' => 'required|integer',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/QuestCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

use App\Models\Company;
use App\Models\Edition;
use App\Models\Quest;

class QuestCRUDController extends CRUDController
{
protected string $model = Quest::class;

protected string $view = 'Quest';

protected array $rules = [
'name' => 'required|string',
'category' => 'required|string|in:company,talk,workshop,milestone,teambuiling',
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Controllers/SpeakerCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

class SpeakerCRUDController extends CRUDController
{
protected string $model = Speaker::class;

protected string $view = 'Speaker';

protected array $rules = [
'name' => 'required|string',
'title' => 'nullable|string',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/SponsorCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

use App\Models\Company;
use App\Models\Edition;
use App\Models\Sponsor;

class SponsorCRUDController extends CRUDController
{
protected string $model = Sponsor::class;

protected string $view = 'Sponsor';

protected array $rules = [
'tier' => 'required|in:platinum,gold,silver',
'edition_id' => 'required|exists:editions,id',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/StaffCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
use App\Models\Department;
use App\Models\Edition;
use App\Models\Participant;
use App\Models\Staff;

class StaffCRUDController extends CRUDController
{
protected string $model = Staff::class;

protected string $view = 'Staff';

protected array $rules = [
'participant_id' => 'required|exists:participants,id',
'department_id' => 'required|exists:departments,id',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/StandCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

use App\Models\EventDay;
use App\Models\Sponsor;
use App\Models\Stand;

class StandCRUDController extends CRUDController
{
protected string $model = Stand::class;

protected string $view = 'Stand';

protected array $rules = [
'sponsor_id' => 'required|integer|in:sponsors,id',
'event_day_id' => 'required|integer|in:event_days,id',
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Controllers/UserCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

class UserCRUDController extends CRUDController
{
protected string $model = User::class;

protected string $view = 'User';

protected array $rules = [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users,email',
Expand Down
23 changes: 23 additions & 0 deletions database/factories/AdminFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@

namespace Database\Factories;

use App\Models\Admin;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Admin>
*/
class AdminFactory extends Factory
{
public function configure(): static
{
return $this->afterMaking(function (Admin $admin) {
if ($admin->user_id !== 0) {
return;
}

$admin->user()->associate(User::factory()->create([
'usertype_id' => -1,
'usertype_type' => Admin::class,
]));
})->afterCreating(function (Admin $admin) {
if ($admin->user_id !== 0) {
return;
}

$admin->user->usertype_id = $admin->id;
$admin->user->save();
});
}

/**
* Define the model's default state.
*
Expand Down
23 changes: 23 additions & 0 deletions database/factories/CompanyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@

namespace Database\Factories;

use App\Models\Company;
use App\Models\SocialMedia;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Company>
*/
class CompanyFactory extends Factory
{
public function configure(): static
{
return $this->afterMaking(function (Company $company) {
if ($company->user_id !== 0) {
return;
}

$company->user()->associate(User::factory()->create([
'usertype_id' => -1,
'usertype_type' => Company::class,
]));
})->afterCreating(function (Company $company) {
if ($company->user_id !== 0) {
return;
}

$company->user->usertype_id = $company->id;
$company->user->save();
});
}

/**
* Define the model's default state.
*
Expand Down
23 changes: 23 additions & 0 deletions database/factories/ParticipantFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@

namespace Database\Factories;

use App\Models\Participant;
use App\Models\SocialMedia;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Participant>
*/
class ParticipantFactory extends Factory
{
public function configure(): static
{
return $this->afterMaking(function (Participant $participant) {
if ($participant->user_id !== 0) {
return;
}

$participant->user()->associate(User::factory()->create([
'usertype_id' => -1,
'usertype_type' => Participant::class,
]));
})->afterCreating(function (Participant $participant) {
if ($participant->user_id !== 0) {
return;
}

$participant->user->usertype_id = $participant->id;
$participant->user->save();
});
}

/**
* Define the model's default state.
*
Expand Down
4 changes: 4 additions & 0 deletions database/factories/QuestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Database\Factories;

use App\Models\Company;
use App\Models\Edition;
use App\Models\Event;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -21,6 +23,8 @@ public function definition(): array
'name' => fake()->words(3, true),
'category' => fake()->randomElement(['COMPANY', 'TALK', 'WORKSHOP', 'MILESTONE', 'TEAMBUILDING']),
'edition_id' => Edition::factory(),
'requirement_type' => fake()->randomElement([Company::class, Event::class]),
'requirement_id' => fn (array $attributes) => $attributes['requirement_type']::factory(),
];
}
}
4 changes: 4 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class UserFactory extends Factory
public function configure(): static
{
return $this->afterCreating(function (User $user) {
if ($user->usertype_id !== 0) {
return;
}

$user->usertype()->associate($user->usertype_type::factory()->create([
'user_id' => $user->id,
]));
Expand Down
19 changes: 8 additions & 11 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ public function run(): void
{
self::cleanDatabase();

$participants = User::factory(100)->create();
$companies = User::factory(10)->company()->create();

if (! User::where('email', '=', DatabaseSeeder::DEFAULT_ADMIN_EMAIL)->exists()) {
User::factory()->admin()->create([
'email' => DatabaseSeeder::DEFAULT_ADMIN_EMAIL,
]);
}
User::factory()->admin()->create([
'email' => DatabaseSeeder::DEFAULT_ADMIN_EMAIL,
]);
$participants = Participant::factory(100)->create();
$companies = Company::factory(10)->create();

$edition = Edition::factory()->create();

Expand All @@ -75,7 +72,7 @@ public function run(): void
]), range(0, 7));

$departments = Department::factory(10)->recycle($edition)->create();
Staff::factory(20)->recycle($departments)->recycle($participants->pluck('usertype'))->create();
Staff::factory(20)->recycle($departments)->recycle($participants)->create();

foreach ($event_days as $day) {
$events = Event::factory(10)->recycle($day)->create();
Expand All @@ -84,8 +81,8 @@ public function run(): void

$sponsors = [];
foreach ($companies as $company) {
Quest::factory()->recycle($edition)->for($company->usertype, 'requirement')->create();
$sponsors[] = Sponsor::factory()->recycle($edition)->recycle($company->usertype)->create();
Quest::factory()->recycle($edition)->for($company, 'requirement')->create();
$sponsors[] = Sponsor::factory()->recycle($edition)->recycle($company)->create();
}

Stand::factory(20)->recycle($event_days)->recycle($sponsors)->create();
Expand Down
Loading