Skip to content

Commit

Permalink
#10 - cr fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Oct 3, 2023
1 parent 9df27fe commit 290395b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 53 deletions.
35 changes: 0 additions & 35 deletions app/Enums/Semester.php

This file was deleted.

3 changes: 0 additions & 3 deletions app/Http/Controllers/Dashboard/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]);
Expand All @@ -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(),
]);
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Requests/CourseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)],
];
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/CourseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
Expand Down
18 changes: 17 additions & 1 deletion app/Models/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions database/factories/CourseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions resources/js/Pages/Dashboard/Course/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -73,7 +72,7 @@ function createCourse() {
<FormLabel for="semester">
Semestr
</FormLabel>
<Select id="semester" v-model="form.semester" :error="form.errors.semester" :options="semesters" label="label" item-value="value" />
<TextInput id="semester" v-model="form.semester" type="number" min="1" max="10" :error="form.errors.semester" autocomplete="off" />
<FormError :error="form.errors.semester" />
</FormGroup>
<FormGroup>
Expand Down
3 changes: 1 addition & 2 deletions resources/js/Pages/Dashboard/Course/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import TextAreaEditor from '../../../Shared/Forms/TextAreaEditor.vue'
const props = defineProps({
course: Object,
semesters: Array,
classTypes: Array,
studyForms: Array,
})
Expand Down Expand Up @@ -76,7 +75,7 @@ function updateCourse() {
<FormLabel for="semester">
Semestr
</FormLabel>
<Select id="semester" v-model="form.semester" :error="form.errors.semester" :options="semesters" label="label" item-value="value" />
<TextInput id="semester" v-model="form.semester" type="number" min="1" max="10" :error="form.errors.semester" autocomplete="off" />
<FormError :error="form.errors.semester" />
</FormGroup>
<FormGroup>
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/CourseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -40,23 +40,23 @@ public function testCourseCanBeUpdated(): void
$this->assertDatabaseMissing("courses", [
"name" => "Course",
"abbreviation" => "C",
"semester" => "II",
"semester" => 2,
"type" => "laboratory",
"form" => "stationary",
]);

$this->patch("/dashboard/courses/{$semester->id}", [
"name" => "Course",
"abbreviation" => "C",
"semester" => "II",
"semester" => 2,
"type" => "laboratory",
"form" => "stationary",
])->assertSessionHasNoErrors();

$this->assertDatabaseHas("courses", [
"name" => "Course",
"abbreviation" => "C",
"semester" => "II",
"semester" => 2,
"type" => "laboratory",
"form" => "stationary",
]);
Expand Down

0 comments on commit 290395b

Please sign in to comment.