diff --git a/app/Http/Controllers/Dashboard/SettingController.php b/app/Http/Controllers/Dashboard/SettingController.php new file mode 100644 index 0000000..b838e54 --- /dev/null +++ b/app/Http/Controllers/Dashboard/SettingController.php @@ -0,0 +1,31 @@ + Setting::query()->first(), + ]); + } + + public function update(SettingRequest $request): RedirectResponse + { + Setting::query()->first() + ->update($request->validated()); + + return redirect() + ->back() + ->with("success", "Zaktualizowano ustawienia"); + } +} diff --git a/app/Http/Controllers/Public/HomeController.php b/app/Http/Controllers/Public/HomeController.php index 8e4f3b0..b7d6384 100644 --- a/app/Http/Controllers/Public/HomeController.php +++ b/app/Http/Controllers/Public/HomeController.php @@ -5,18 +5,22 @@ namespace App\Http\Controllers\Public; use App\Http\Controllers\Controller; +use App\Models\Setting; use Inertia\Response; class HomeController extends Controller { public function __invoke(): Response { + /** @var Setting $settings */ + $settings = Setting::query()->first(); + return inertia("Public/Home", [ - "title" => "mgr inż.", - "name" => "Krzysztof Rewak", - "email" => "krzysztof.rewak@collegiumwitelona.pl", - "department" => "Zakład Informatyki, Wydział Nauk Technicznych i Ekonomicznych", - "university" => "Collegium Witelona Uczelnia Państwowa", + "title" => $settings->teacher_titles, + "name" => $settings->teacher_name, + "email" => $settings->teacher_email, + "department" => $settings->department_name, + "university" => $settings->university_name, "universityLogo" => "https://irg2023.collegiumwitelona.pl/assets/logos/cwup.png", "sections" => [ [ diff --git a/app/Http/Requests/SettingRequest.php b/app/Http/Requests/SettingRequest.php new file mode 100644 index 0000000..3a4f223 --- /dev/null +++ b/app/Http/Requests/SettingRequest.php @@ -0,0 +1,21 @@ + ["required", "max:255"], + "teacher_email" => ["required", "email", "max:255"], + "teacher_titles" => ["required", "max:255"], + "university_name" => ["required", "max:255"], + "department_name" => ["required", "max:255"], + ]; + } +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php new file mode 100644 index 0000000..ecb6a98 --- /dev/null +++ b/app/Models/Setting.php @@ -0,0 +1,34 @@ + "dr", + "teacher_name" => fake()->name, + "teacher_email" => fake()->email, + "department_name" => "Zakład Informatyki, Wydział Nauk Technicznych i Ekonomicznych", + "university_name" => "Collegium Witelona Uczelnia Państwowa", + ]; + } +} diff --git a/database/migrations/2023_10_18_193906_create_settings_table.php b/database/migrations/2023_10_18_193906_create_settings_table.php new file mode 100644 index 0000000..585b597 --- /dev/null +++ b/database/migrations/2023_10_18_193906_create_settings_table.php @@ -0,0 +1,27 @@ +ulid("id")->primary(); + $table->string("teacher_name")->nullable(); + $table->string("teacher_email")->nullable(); + $table->string("teacher_titles")->nullable(); + $table->string("university_name")->nullable(); + $table->string("department_name")->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists("settings"); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0ff7edb..c79e71d 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; +use App\Models\Setting; use App\Models\User; use Illuminate\Database\Seeder; @@ -12,5 +13,6 @@ class DatabaseSeeder extends Seeder public function run(): void { User::factory()->create(["email" => "admin@example.com"]); + Setting::factory()->create(); } } diff --git a/lang/pl/validation.php b/lang/pl/validation.php index 3b9a1c9..b066404 100644 --- a/lang/pl/validation.php +++ b/lang/pl/validation.php @@ -124,5 +124,10 @@ "abbreviation" => "skrótowiec", "form" => "tryb studiów", "type" => "typ zajęć", + "teacher_name" => "imię i nazwisko nauczyciela", + "teacher_email" => "adres e-mail nauczyciela", + "teacher_titles" => "tytuły/stopnie naukowe nauczyciela", + "university_name" => "nazwa uczelni", + "department_name" => "nazwa wydziału", ], ]; diff --git a/resources/js/Layouts/DashboardLayout.vue b/resources/js/Layouts/DashboardLayout.vue index 5c46c3c..3bc0eb4 100644 --- a/resources/js/Layouts/DashboardLayout.vue +++ b/resources/js/Layouts/DashboardLayout.vue @@ -29,7 +29,7 @@ const navigation = [ title: 'Ogólne', elements: [ { name: 'Dashboard', href: '/dashboard', icon: HomeIcon, current: true }, - { name: 'Ustawienia', href: '#', icon: Cog6ToothIcon, current: false }, + { name: 'Ustawienia', href: '/dashboard/settings', icon: Cog6ToothIcon, current: false }, { name: 'Aktualizacja hasła', href: '/dashboard/password', icon: LockOpenIcon, current: false }, { name: 'Aktualności', href: '/dashboard/news', icon: NewspaperIcon, current: false }, { name: 'FAQ', href: '/dashboard/faqs', icon: QuestionMarkCircleIcon, current: false }, diff --git a/resources/js/Pages/Dashboard/Setting/Edit.vue b/resources/js/Pages/Dashboard/Setting/Edit.vue new file mode 100644 index 0000000..bebafa1 --- /dev/null +++ b/resources/js/Pages/Dashboard/Setting/Edit.vue @@ -0,0 +1,91 @@ + + + diff --git a/routes/web.php b/routes/web.php index fb0512e..f3c9953 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,6 +15,7 @@ use App\Http\Controllers\Dashboard\NewsManagementController; use App\Http\Controllers\Dashboard\PasswordUpdateController; use App\Http\Controllers\Dashboard\SemesterController; +use App\Http\Controllers\Dashboard\SettingController; use App\Http\Controllers\Dashboard\StudentController; use App\Http\Controllers\Public\HomeController; use App\Http\Controllers\Public\LoginController; @@ -119,4 +120,8 @@ Route::patch("/semester-courses/{course}/groups/{group}/grades/{gradeColumn}/update", "updateGrade")->name("course.semester.group.grades.update"); Route::post("/semester-courses/{course}/groups/{group}/grades/{gradeColumn}/reorder/{down}", "reorder")->name("course.semester.group.grades.reorder"); }); + Route::controller(SettingController::class)->group(function (): void { + Route::get("/settings", "edit")->name("settings.edit"); + Route::patch("/settings", "update")->name("settings.update"); + }); }); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 0295a22..76894f9 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -4,15 +4,15 @@ namespace Tests\Feature; +use App\Models\Setting; use Tests\TestCase; class ExampleTest extends TestCase { - /** - * A basic test example. - */ public function testTheApplicationReturnsASuccessfulResponse(): void { + Setting::factory()->create(); + $response = $this->get("/"); $response->assertStatus(200); diff --git a/tests/Feature/SettingsTest.php b/tests/Feature/SettingsTest.php new file mode 100644 index 0000000..190ae82 --- /dev/null +++ b/tests/Feature/SettingsTest.php @@ -0,0 +1,126 @@ +user = User::factory()->create(); + $this->gradeColumn = Setting::factory()->create([ + "teacher_name" => "Ty Doe", + "teacher_email" => "ty.doe@exmple.com", + "teacher_titles" => "dr inż.", + "university_name" => "CWUP", + "department_name" => "IT department", + ]); + $this->actingAs($this->user); + } + + public function testSettingsCanBeUpdated(): void + { + $this->assertDatabaseHas("settings", [ + "teacher_name" => "Ty Doe", + "teacher_email" => "ty.doe@exmple.com", + "teacher_titles" => "dr inż.", + "university_name" => "CWUP", + "department_name" => "IT department", + ]); + + $this->patch("/dashboard/settings", [ + "teacher_name" => "John Doe", + "teacher_email" => "john.doe@exmple.com", + "teacher_titles" => "dr", + "university_name" => "SWPS", + "department_name" => "Psychology department", + ])->assertSessionHasNoErrors(); + + $this->assertDatabaseHas("settings", [ + "teacher_name" => "John Doe", + "teacher_email" => "john.doe@exmple.com", + "teacher_titles" => "dr", + "university_name" => "SWPS", + "department_name" => "Psychology department", + ]); + } + + public function testSettingsCannotBeUpdatedWithInvalidData(): void + { + $this->assertDatabaseHas("settings", [ + "teacher_name" => "Ty Doe", + "teacher_email" => "ty.doe@exmple.com", + "teacher_titles" => "dr inż.", + "university_name" => "CWUP", + "department_name" => "IT department", + ]); + + $this->patch("/dashboard/settings", [ + "teacher_name" => Str::random(256), + "teacher_email" => "john.doe", + "teacher_titles" => Str::random(256), + "university_name" => Str::random(256), + "department_name" => Str::random(256), + ])->assertSessionHasErrors() + ->assertInvalid([ + "teacher_name", + "teacher_email", + "teacher_titles", + "university_name", + "department_name", + ]); + + $this->assertDatabaseHas("settings", [ + "teacher_name" => "Ty Doe", + "teacher_email" => "ty.doe@exmple.com", + "teacher_titles" => "dr inż.", + "university_name" => "CWUP", + "department_name" => "IT department", + ]); + } + + public function testSettingsCannotBeUpdatedWithEmptyData(): void + { + $this->assertDatabaseHas("settings", [ + "teacher_name" => "Ty Doe", + "teacher_email" => "ty.doe@exmple.com", + "teacher_titles" => "dr inż.", + "university_name" => "CWUP", + "department_name" => "IT department", + ]); + + $this->patch("/dashboard/settings", [ + "teacher_name" => "", + "teacher_email" => "", + "teacher_titles" => "", + "university_name" => "", + "department_name" => "", + ])->assertSessionHasErrors() + ->assertInvalid([ + "teacher_name", + "teacher_email", + "teacher_titles", + "university_name", + "department_name", + ]); + + $this->assertDatabaseHas("settings", [ + "teacher_name" => "Ty Doe", + "teacher_email" => "ty.doe@exmple.com", + "teacher_titles" => "dr inż.", + "university_name" => "CWUP", + "department_name" => "IT department", + ]); + } +}