Add: Delete course
This commit is contained in:
parent
986a5103df
commit
bcc5d7af4b
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Course\Controllers;
|
namespace App\Course\Controllers;
|
||||||
|
|
||||||
use App\Course\Models\CourseMember;
|
use App\Course\Models\CourseMember;
|
||||||
|
use App\Course\Requests\DestroyRequest;
|
||||||
use App\Course\Requests\StoreRequest;
|
use App\Course\Requests\StoreRequest;
|
||||||
use App\Course\Requests\UpdateRequest;
|
use App\Course\Requests\UpdateRequest;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
@ -25,4 +26,11 @@ class CourseController extends Controller
|
||||||
|
|
||||||
return redirect()->route('member.index');
|
return redirect()->route('member.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function destroy(Member $member, CourseMember $course, DestroyRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$request->persist($member, $course);
|
||||||
|
|
||||||
|
return redirect()->route('member.index');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Course\Requests;
|
||||||
|
|
||||||
|
use App\Course\Models\Course;
|
||||||
|
use App\Course\Models\CourseMember;
|
||||||
|
use App\Member\Member;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Zoomyboy\LaravelNami\NamiException;
|
||||||
|
|
||||||
|
class DestroyRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function persist(Member $member, CourseMember $course): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
auth()->user()->api()->deleteCourse($member->nami_id, $course->nami_id);
|
||||||
|
} catch(NamiException $e) {
|
||||||
|
throw ValidationException::withMessages(['id' => 'Unbekannter Fehler']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$course->delete();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
Subproject commit 64ce14910a9b43004ddb6561c64ea909bb119cee
|
Subproject commit d348aea5f6bba6cf3eb8e2050a738817f281b4c3
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Course;
|
||||||
|
|
||||||
|
use App\Course\Models\Course;
|
||||||
|
use App\Course\Models\CourseMember;
|
||||||
|
use App\Member\Member;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||||
|
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
||||||
|
|
||||||
|
class DeleteTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function testItDeletesACourse(): void
|
||||||
|
{
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
$this->login()->init();
|
||||||
|
app(CourseFake::class)->deleteSuccessful(123, 999);
|
||||||
|
$member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne();
|
||||||
|
|
||||||
|
$response = $this->delete("/member/{$member->id}/course/{$member->courses->first()->id}");
|
||||||
|
|
||||||
|
$response->assertRedirect("/member");
|
||||||
|
$this->assertDatabaseCount('course_members', 0);
|
||||||
|
app(CourseFake::class)->assertDeleted(123, 999);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItReceivesUnknownErrors(): void
|
||||||
|
{
|
||||||
|
$this->login()->init();
|
||||||
|
app(CourseFake::class)->deleteFailed(123, 999);
|
||||||
|
$member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne();
|
||||||
|
|
||||||
|
$response = $this->delete("/member/{$member->id}/course/{$member->courses->first()->id}");
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('course_members', 1);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['id' => 'Unbekannter Fehler']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue