From 290395ba027915649c55a129f03f773449ab7fdb Mon Sep 17 00:00:00 2001 From: Kamil Date: Tue, 3 Oct 2023 20:46:51 +0200 Subject: [PATCH] #10 - cr fix --- app/Enums/Semester.php | 35 ------------------- .../Dashboard/CourseController.php | 3 -- app/Http/Requests/CourseRequest.php | 3 +- app/Http/Resources/CourseResource.php | 2 +- app/Models/Course.php | 18 +++++++++- database/factories/CourseFactory.php | 3 +- ...2023_10_03_193906_create_courses_table.php | 2 +- .../js/Pages/Dashboard/Course/Create.vue | 3 +- resources/js/Pages/Dashboard/Course/Edit.vue | 3 +- tests/Feature/CourseTest.php | 8 ++--- 10 files changed, 27 insertions(+), 53 deletions(-) delete mode 100644 app/Enums/Semester.php diff --git a/app/Enums/Semester.php b/app/Enums/Semester.php deleted file mode 100644 index 60aeaba..0000000 --- a/app/Enums/Semester.php +++ /dev/null @@ -1,35 +0,0 @@ - __("I"), - "II" => __("II"), - "III" => __("III"), - "IV" => __("IV"), - "V" => __("V"), - "VI" => __("VI"), - "VII" => __("VII"), - "VIII" => __("VIII"), - "IX" => __("IX"), - "X" => __("X"), - ]; - } -} diff --git a/app/Http/Controllers/Dashboard/CourseController.php b/app/Http/Controllers/Dashboard/CourseController.php index 1d2fc52..d041769 100644 --- a/app/Http/Controllers/Dashboard/CourseController.php +++ b/app/Http/Controllers/Dashboard/CourseController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers\Dashboard; use App\Enums\ClassType; -use App\Enums\Semester; use App\Enums\StudyForm; use App\Http\Controllers\Controller; use App\Http\Requests\CourseRequest; @@ -33,7 +32,6 @@ public function index(): Response public function create(): Response { return inertia("Dashboard/Course/Create", [ - "semesters" => Options::forEnum(Semester::class)->toArray(), "classTypes" => Options::forEnum(ClassType::class)->toArray(), "studyForms" => Options::forEnum(StudyForm::class)->toArray(), ]); @@ -52,7 +50,6 @@ public function edit(Course $course): Response { return inertia("Dashboard/Course/Edit", [ "course" => $course, - "semesters" => Options::forEnum(Semester::class)->toArray(), "classTypes" => Options::forEnum(ClassType::class)->toArray(), "studyForms" => Options::forEnum(StudyForm::class)->toArray(), ]); diff --git a/app/Http/Requests/CourseRequest.php b/app/Http/Requests/CourseRequest.php index 2d3b0f1..cd18e30 100644 --- a/app/Http/Requests/CourseRequest.php +++ b/app/Http/Requests/CourseRequest.php @@ -5,7 +5,6 @@ namespace App\Http\Requests; use App\Enums\ClassType; -use App\Enums\Semester; use App\Enums\StudyForm; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rules\Enum; @@ -18,7 +17,7 @@ public function rules(): array "name" => ["required", "max:255"], "abbreviation" => ["required", "max:255"], "description" => ["nullable", "max:65000"], - "semester" => ["required", new Enum(Semester::class)], + "semester" => ["required", "numeric", "min:1", "max:10"], "type" => ["required", new Enum(ClassType::class)], "form" => ["required", new Enum(StudyForm::class)], ]; diff --git a/app/Http/Resources/CourseResource.php b/app/Http/Resources/CourseResource.php index 30c2bf1..af7b6e3 100644 --- a/app/Http/Resources/CourseResource.php +++ b/app/Http/Resources/CourseResource.php @@ -22,7 +22,7 @@ public function toArray(Request $request): array "name" => $course->name, "abbreviation" => $course->abbreviation, "description" => $course->description, - "semester" => $course->semester, + "semester" => $course->getRomanizedSemester(), "type" => ClassType::labels()[$course->type], "form" => StudyForm::labels()[$course->form], ]; diff --git a/app/Models/Course.php b/app/Models/Course.php index a04505e..3930b8a 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -16,7 +16,7 @@ * @property string $name * @property string $abbreviation * @property string $description - * @property string $semester + * @property int $semester * @property string $type * @property string $form * @property Carbon $created_at @@ -36,6 +36,22 @@ class Course extends Model "form", ]; + public function getRomanizedSemester(): string + { + return match ($this->semester) { + 1 => __("I"), + 2 => __("II"), + 3 => __("III"), + 4 => __("IV"), + 5 => __("V"), + 6 => __("VI"), + 7 => __("VII"), + 8 => __("VIII"), + 9 => __("IX"), + default => __("X"), + }; + } + protected function description(): Attribute { return Attribute::make( diff --git a/database/factories/CourseFactory.php b/database/factories/CourseFactory.php index 3cd898f..fa75d81 100644 --- a/database/factories/CourseFactory.php +++ b/database/factories/CourseFactory.php @@ -6,7 +6,6 @@ use App\Enums\ClassType; use App\Enums\StudyForm; -use App\Models\Semester; use Illuminate\Database\Eloquent\Factories\Factory; class CourseFactory extends Factory @@ -17,7 +16,7 @@ public function definition(): array "name" => fake()->asciify("******"), "abbreviation" => fake()->asciify("*"), "description" => fake()->text, - "semester" => Semester::factory()->create()->name, + "semester" => fake()->numberBetween(1, 10), "type" => ClassType::LABORATORY->value, "form" => StudyForm::STATIONARY->value, ]; diff --git a/database/migrations/2023_10_03_193906_create_courses_table.php b/database/migrations/2023_10_03_193906_create_courses_table.php index fa8628e..b89b960 100644 --- a/database/migrations/2023_10_03_193906_create_courses_table.php +++ b/database/migrations/2023_10_03_193906_create_courses_table.php @@ -14,7 +14,7 @@ public function up(): void $table->string("abbreviation"); $table->string("name"); $table->longText("description"); - $table->string("semester"); + $table->integer("semester"); $table->string("type"); $table->string("form"); $table->timestamps(); diff --git a/resources/js/Pages/Dashboard/Course/Create.vue b/resources/js/Pages/Dashboard/Course/Create.vue index e1b63ff..9fdc039 100644 --- a/resources/js/Pages/Dashboard/Course/Create.vue +++ b/resources/js/Pages/Dashboard/Course/Create.vue @@ -13,7 +13,6 @@ import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' import TextAreaEditor from '@/Shared/Forms/TextAreaEditor.vue' defineProps({ - semesters: Array, classTypes: Array, studyForms: Array, }) @@ -73,7 +72,7 @@ function createCourse() { Semestr - + diff --git a/tests/Feature/CourseTest.php b/tests/Feature/CourseTest.php index 8c30874..8780daf 100644 --- a/tests/Feature/CourseTest.php +++ b/tests/Feature/CourseTest.php @@ -27,7 +27,7 @@ public function testCourseCanBeCreated(): void $this->post("/dashboard/courses", [ "name" => "Course", "abbreviation" => "C", - "semester" => "II", + "semester" => 2, "type" => "laboratory", "form" => "stationary", ])->assertSessionHasNoErrors(); @@ -40,7 +40,7 @@ public function testCourseCanBeUpdated(): void $this->assertDatabaseMissing("courses", [ "name" => "Course", "abbreviation" => "C", - "semester" => "II", + "semester" => 2, "type" => "laboratory", "form" => "stationary", ]); @@ -48,7 +48,7 @@ public function testCourseCanBeUpdated(): void $this->patch("/dashboard/courses/{$semester->id}", [ "name" => "Course", "abbreviation" => "C", - "semester" => "II", + "semester" => 2, "type" => "laboratory", "form" => "stationary", ])->assertSessionHasNoErrors(); @@ -56,7 +56,7 @@ public function testCourseCanBeUpdated(): void $this->assertDatabaseHas("courses", [ "name" => "Course", "abbreviation" => "C", - "semester" => "II", + "semester" => 2, "type" => "laboratory", "form" => "stationary", ]);