Skip to content

Commit

Permalink
#11 - wip: some fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Oct 7, 2023
1 parent d1bdb8f commit 08e79a6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function store(CourseSemesterRequest $request): RedirectResponse
CourseSemester::query()->create($request->getData());

return redirect()
->route("course.semester..index")
->route("course.semester.index")
->with("success", "Dodano kurs");
}

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Dashboard/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ class GroupController extends Controller
{
public function store(GroupRequest $request, CourseSemester $course): RedirectResponse
{
$course->groups()->create(["name" => $request->get("name")]);
$course->groups()->create($request->validated());

return redirect()->back()
->with("success", "Dodano grupę");
}

public function update(GroupRequest $request, CourseSemester $course, Group $group): RedirectResponse
{
$group->update(["name" => $request->get("name")]);
$group->update($request->validated());

return redirect()->back()
->with("success", "Zaktualizowano grupę");
}

public function destroy(CourseSemester $course, Group $group): RedirectResponse
{
$group->students()->detach($group->students);
$group->delete();

return redirect()->back()
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/GroupStudentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function index(Request $request, CourseSemester $course, Group $group): R

public function store(Request $request, CourseSemester $course, Group $group): RedirectResponse
{
$group->students()->sync($request->get("student"), "false");
$group->students()->sync($request->get("student"), false);

return redirect()->back()
->with("success", "Dodano studenta");
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/CourseSemesterResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function toArray(Request $request): array
"id" => $course->id,
"course" => $course->course->name,
"semester" => $course->semester->name,
"form" => StudyForm::labels()[$course->form],
"form" => StudyForm::labels()[$course->form->value],
];
}
}
2 changes: 1 addition & 1 deletion app/Models/CourseSemester.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @property string $name
* @property string $course_id
* @property string $semester_id
* @property string $form
* @property StudyForm $form
* @property Course $course
* @property Semester $semester
* @property Carbon $created_at
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Dashboard/CourseSemester/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const courseToDeleteId = ref(0)
{{ course.semester }}
</TableCell>
<TableCell>
{{ course.type }}
{{ course.form }}
</TableCell>
<TableCell class="flex justify-end gap-2">
<Button :href="`/dashboard/course-semester/${course.id}`">
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,26 @@ public function testStudentCanBeRemovedFromStudentGroup(): void
$group->refresh();
$this->assertCount(0, $group->students);
}

public function testStudentsAreDetachedBeforeStudentGroupDeleting(): void
{
$group = Group::factory()->create();
$students = Student::factory(10)->create();
$this->assertCount(0, $group->students);
$this->assertDatabaseCount("groups", 1);

$this->post(
"/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}/students",
[
"student" => $students->pluck("id"),
],
)->assertSessionHasNoErrors();

$this->assertDatabaseCount("student_group", 10);

$this->delete("/dashboard/course-semester/{$group->course_semester_id}/groups/{$group->id}");

$this->assertDatabaseCount("student_group", 0);
$this->assertDatabaseCount("groups", 0);
}
}

0 comments on commit 08e79a6

Please sign in to comment.